akhauriyash/Code-Regression huggingface dataset:
import java.io.{BufferedOutputStream, BufferedReader, InputStreamReader, PrintWriter}

import scala.collection.mutable
import scala.collection.mutable.ArrayBuffer

object Main {
  def main(args: Array[String]): Unit = {
    val in = new BufferedReader(new InputStreamReader(System.in))
    val out = new PrintWriter(new BufferedOutputStream(System.out))
    val Array(n, x, y) = in.readLine().split("\\s+").map(_.toInt) match {
      case Array(n, x, y) => Array(n, x - 1, y - 1)
    }

    val memo = Array.fill[Int](n, n)(n - 1)
    val count = Array.ofDim[Int](n)
    count(n - 1) = (n + 1) * n / 2

    val queue = mutable.PriorityQueue.empty[(Int, Int, Int)](Ordering.by((_: (Int, Int, Int))._3).reverse)

    @inline
    def lookup(i: Int, j: Int): Int = {
      if (i < j) {
        memo(j)(i)
      } else {
        memo(i)(j)
      }
    }

    @inline
    def update(i: Int, j: Int, value: Int): Unit = {
      if (0 <= i && 0 <= j && i < n && j < n) {
        val current = lookup(i, j)
        if (current > value) {
          count(current) -= 1
          if (i < j) {
            memo(j)(i) = value
            queue.enqueue((j, i, value))
          } else {
            memo(i)(j) = value
            queue.enqueue((i, j, value))
          }
          count(value) += 1
        }
      }
    }

    for (i <- 0 until n) {
      update(i, i, 0)
    }

    while (queue.nonEmpty) {
      val (i, j, step) = queue.dequeue()
      update(i + 1, j, step + 1)
      update(i - 1, j, step + 1)
      update(i, j + 1, step + 1)
      update(i, j - 1, step + 1)
      if (i == x) {
        update(y, j, step + 1)
      }
      if (i == y) {
        update(x, j, step + 1)
      }
      if (j == x) {
        update(i, y, step + 1)
      }
      if (j == y) {
        update(i, x, step + 1)
      }
    }

    for (i <- 1 until count.length) {
      out.println(count(i))
    }

    out.flush()
  }
}


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

int main() {
    int a, b, c;
    cin >> a >> b >> c;
    int su = a+b+c;
    if (su>=22) {
        cout << "bust" << endl;
    }
    else {
        cout << "win" << endl;
    }
}

Measured memory_bytes: 256
#![allow(unused_imports)]
#![allow(non_snake_case)]
use std::cmp::*;
use std::collections::*;
use std::io::Write;

#[allow(unused_macros)]
macro_rules! debug {
    ($($e:expr),*) => {
        #[cfg(debug_assertions)]
        $({
            let (e, mut err) = (stringify!($e), std::io::stderr());
            writeln!(err, "{} = {:?}", e, $e).unwrap()
        })*
    };
}

fn main() {
    let v = read_vec::<i64>();
    let (n, m) = (v[0] as usize, v[1]);
    let a = read_vec::<i64>();
    let a = a.into_iter().map(|x| x >> 1).collect::<Vec<_>>();

    let mut lcmnum = a[0];
    for i in 1..n {
        let gcdnum1 = gcd(lcmnum, a[i]);
        lcmnum = lcmnum / gcdnum1 * a[i];
        if lcmnum > m * 2 {
            println!("0");
            return;
        }
    }
    for i in 0..n {
        if (lcmnum / a[i]) % 2 == 0 {
            println!("0");
            return;
        }
    }
    let all = m / lcmnum;
    let ans = (all + 1) / 2;
    println!("{}", ans);
}

fn gcd(a: i64, b: i64) -> i64 {
    if b == 0 {
        return a;
    }
    gcd(b, a % b)
}

fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}


Measured memory_bytes: 8444
#include<stdio.h>
int main(void)
{
	int i,flg;
	char c1[10],c2[10];
	for(i=0;i<3;i++) scanf(" %c",&c1[i]);
	for(i=0;i<3;i++) scanf(" %c",&c2[i]);
	flg=0;
	for(i=0;i<3;i++){
		if(c1[i]!=c2[2-i]) flg=1;
	}
	if(flg==0) printf("YES\n");
	else printf("NO\n");
	return 0;
}

Measured memory_bytes: 128
#include "bits/stdc++.h"
using namespace std;
int main() {
	vector<int>A = { 1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51 };
	int K; cin >> K;
	cout << A.at(K - 1) << endl;
}

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

#define fastio 			ios::sync_with_stdio(0);	cin.tie(0); cout.tie(0);  cout<<fixed;  cout<<setprecision(12);
#define randomINT 		mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());
#define	newl 			cout<<"\n"
#define DISP(as)		for(auto it : as) cout<<it<<" ";newl;
#define all(x)         	(x).begin(),(x).end()
#define mset(x,val)    	memset(x,val,sizeof(x))
#define newl           	cout<<"\n"
#define pb             	push_back
#define mp             	make_pair
#define f 				first
#define s 				second
#define dline          cerr<<"///REACHED///\n";
#define deb1(x)        cerr<<#x<<" = "<<x<<'\n';
#define deb2(x,y)      cerr<<'['<<#x<<','<<#y<<"] = "<<'['<<x<<','<<y<<']'<<'\n';
#define deb3(x,y,z)    cerr<<'['<<#x<<','<<#y<<','<<#z<<"] = "<<'['<<x<<','<<y<<','<<z<<']'<<'\n';

typedef long long 				ll;
typedef long double 			ld;
typedef vector<ll> 				vll;
typedef pair<ll , ll> 			pll;
typedef pair<ld, ld> 			pld;
typedef unordered_map<ll, ll> 	um;
typedef vector<pll> 			vpll;

const ll 	MAX5 	= 	1e+5 + 7;
const ll 	MAX7 	= 	1e+7 + 7;
const ll 	MAXN 	= 	MAX7;
const ll   	INF   	=  	0x7f7f7f7f7f7f7f7f;
const int  	INFi 	=  	0x7f7f7f7f;
const ll 	MOD		=  	1e+9 + 7;

vll adj[MAXN]; ll visit[MAXN] = {};
int dx8[] = {0, 1, 1, 1, 0, -1, -1, -1}, dy8[] = {1, 1, 0, -1, -1, -1, 0, 1};
int dx4[] = {0, 1, 0, -1}, dy4[] = {1, 0, -1, 0};

// <------------- Declare Variables Here ------------> //

ll T = 1;
ll n, x;
string s[10], t;
ll cou = 0;
ll h, w, k;
ll black;

// <------------- Implement Functions Here ----------> //

ll chk(ll selI,ll selJ) {
	vll H(h),W(w);
	ll cnt = 0;
	ll temp = black;
	while(selI ) {
		H[cnt] = selI%2;
		selI/=2;
		cnt++;
	}
	cnt = 0;
	while(selJ ) {
		W[cnt] = selJ%2;
		selJ/=2;
		cnt++;
	}

	for(ll i=0;i<h;i++) {
		for(ll j=0;j<w;j++) {
			if((H[i] || W[j] ) && s[i][j]=='#') temp--;
		}
	}

	return temp == k;
}

// <------------- Start of main() -------------------> //

void MAIN() {
	cin >> h >> w >> k;
	for (ll i = 0; i < h; i++)
	{	cin >> s[i];
		for(ll j=0;j<w;j++) {
			if(s[i][j] == '#') black++;
		}
	}

	for(ll i=0;i<pow(2,h);i++) {
		for(ll j=0;j<pow(2,w);j++) {
			cou += chk(i,j);
		}
	}

	cout<<cou;
}

int main() {
	fastio; randomINT;
	//cin>>T;
	while (T--) {
		MAIN();
	}
	return 0;
}


Measured memory_bytes: 238440
#include <stdio.h>

int main(void)
{
	int x,y,z,a,b,d;
	char c[3][4];
	for(x=0;x<3;x++) scanf("%s",c[x]);
	for(x=0;x<3;x++) printf("%c",c[x][x]);
	return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for (long long int i=0;i<(n);i++)
//#define int long long  
int main(){
    string s,t;
    cin >> s >> t;
    if(s[0]==t[2]&&s[1]==t[1]&&s[2]==t[0]){
        cout << "YES" << endl;
    }else{
        cout << "NO" << endl;
    }
	return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
    	Scanner sc = new Scanner(System.in);
    	
    	double x[] = new double[101];
    	double y[] = new double[101];
    	double p1=0,p2=0,p3=0,pm=0;
    	
    	double n = sc.nextDouble();
    	for(int i=0;i<n;i++) {
    		x[i]=sc.nextDouble();
    	}
    	for(int i=0;i<n;i++) {
    		y[i]=sc.nextDouble();
    	}
	    
    	for(int i=0;i<n;i++) {
    		p1 += Math.abs(x[i]-y[i]);
    		p2 += (x[i]-y[i])*(x[i]-y[i]);
    		p3 += Math.abs(x[i]-y[i])*(x[i]-y[i])*(x[i]-y[i]);
    		pm = Math.max(pm, Math.abs(x[i]-y[i]));
    	}
    	
    	System.out.printf("%.10f\n",p1);
    	System.out.printf("%.10f\n",Math.sqrt(p2));
    	System.out.printf("%.10f\n",Math.cbrt(p3));
    	System.out.printf("%.10f\n",pm);
    	
    }
}


Measured memory_bytes: 29104
/*
 * 16-9-4_AGC004_B.cpp
 *
 *  Created on: 2016/09/04
 *      Author: ryoma
 */

#include<iostream>
#include<limits.h>


using namespace std;

typedef long long ll;

int N;
ll x,a[2001],mina[2001][2001],ans[2001],anss;

int main(){
	cin >> N >> x;
	anss = LLONG_MAX;
	for (int i=0;i<N;i++){
		cin >> a[i];
		mina[0][i] = a[i];
	}
	for(int i=0;i<N;i++){
		ans[i] = x*i;
		for(int j=0;j<N;j++){
			mina[i+1][j] = (a[j]<mina[i][(j+1)%N])? a[j]:mina[i][(j+1)%N];
			ans[i] += mina[i][j];
		}
		anss = (anss < ans[i])? anss:ans[i];
	}
	cout << anss << endl;
	return 0;
}




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

int main() {
 int n; cin >> n;
  vector<int> p(n);
  int cnt=0;
  rep(i,n){
    cin >>p[i];
    if((p[i]-1)!=i)cnt++;
  }

  cout << ((cnt==0 || cnt==2) ? "YES" : "NO") << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstring>
//#include <bits/stdc++.h>
using namespace std;
int main(){
    //char a[200000];
    string a;
    cin>>a;
    int b=a.length();
    //b=strlen(a);
    //cout<<b<<endl;
    for(int i=0;i<b;i++){
        if(a[i]=='?'){
            /*if(a[i-1]=='P'){
                a[i]='D';
            }
            if(a[i-1]=='D'){
                /*if(a[i+1]=='D'||a[i+1]=='?'){
                    a[i]='P';
                }else{
                    a[i]='D';
                }
                a[i]='D';
            }*/
            a[i]='D';
        }
    }
    cout<<a<<endl;
}


Measured memory_bytes: 3448
//21171_somesh || asomesh999

#include<bits/stdc++.h>
using namespace std;
#define fr(i,a,b) for(long long i=a;i<b;i++)
#define io ios::sync_with_stdio(false);cin.tie(NULL);
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
long int mod=1000000007;

int main()
{
	io
	#ifdef CODE
		clock_t startTime = clock();
		freopen("input.txt","r",stdin);
	#endif

	ll a, b, k;
	cin >> a >> b >> k;
	if (a >= k) {
		cout << a - k << ' ' << b;
	} else {
		cout << 0 << ' ' << max(0LL, (b - (k - a)));
	}

	#ifdef CODE
		cerr << endl <<setprecision(20)<< double( clock() - startTime ) / (double)CLOCKS_PER_SEC<< " seconds." << endl;
	#endif
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#pragma GCC optimize("O999")
//示例：#define ll long long
//unsigned long long ;
const int INF=0x3f3f3f3f;
const int maxn=50000005;
using namespace std;

int main(){
	//freopen(".in", "r",stdin );
	//freopen(".out","w",stdout);
	ios::sync_with_stdio(0);
	int n;
	cin >> n;
	int a[n+1], b[n+1], ans=0;
	for(int i=1; i<=n; i++){
		cin >> a[i] >> b[i];
		if(a[i]==b[i]) ans++;
		else{
			if(ans>=3){
				cout<<"Yes"<<endl;
				return 0;
			}
			ans=0;
		}
	}
	if(ans>=3)
		cout<<"Yes"<<endl;
	else
		cout<<"No" <<endl;
	return 0;
}

Measured memory_bytes: 3640
#include<bits/stdc++.h>
#define ll long long
using namespace std;
int main()
{
    vector<ll>vec;
    int n;
    cin>>n;
    while(n--)
    {
        int len = vec.size();
        int order;
        cin>>order;
        if(order==0)
        {
            ll x;
            cin>>x;
            vec.push_back(x);
        }else if(order==1)
        {
            int l;
            cin>>l;
            cout<<vec[l]<<"\n";
        }else if(order==2)
        {
            vec.pop_back();
        }
    }
    return 0;
}



Measured memory_bytes: 4940
#include <iostream>
#include <cstdio>
#include <cmath>
using namespace std;
#define rep2(x,from,to) for(int x=(from);(x)<(to);(x)++)
#define rep(x,to) rep2(x,0,to)
int main() {
	int n, x[110], y[110];
	cin >> n;
	rep(i,n) {
		cin >> x[i];
	}
	rep(i,n) {
		cin >> y[i];
	}
	double ret = 0.0;
	rep(i,n) {
		ret += abs(x[i] - y[i]);
	}
	printf("%.10lf\n", ret);
	ret = 0.0;
	rep(i,n) {
		ret += pow(x[i] - y[i], 2.0);
	}
	printf("%.10lf\n", sqrt(ret));
	ret = 0.0;
	rep(i,n) {
		ret += abs(pow(x[i] - y[i], 3.0));
	}
	printf("%.10lf\n", pow(ret, 1.0 / 3.0));
	ret = 0.0;
	rep(i,n) {
		if(ret < abs(x[i] - y[i])) ret = abs(x[i] - y[i]);
	}
	printf("%.10lf\n", ret);
	return 0;
}
	

Measured memory_bytes: 1256
#include<bits/stdc++.h>
using namespace         std;
#define                 int long long
#define                 pb push_back
#define                 mp make_pair
#define st(arr,a)       memset(arr,a,sizeof arr)
#define                 nl cout<<endl
#define                 real signed
#define                 endl '\n'              
#define bitcount(x)     __builtin_popcountll(x)
const int MOD = 1000000007ll;
#define forn(i,a,b)     for(int i=a;i<=b;i++)
#define rfor(i,a,b)     for(int i=a;i>=b;i--)
#define all(x)          x.begin() , x.end()
#define pi pair<int,int>
#define X first
#define Y second
#define N 314159
#define  vi vector<int>
#define  v  vector

signed main() 
{
    ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); 
    string s;
    cin>>s;
    int i = 0;
    int a = 0;
    int ans = 0;
    while(i<=s.size())
    {
        if(s[i] == 'A'){a++;i++;}
        else if(s[i] == 'B' and s[i+1] == 'C'){i+=2;ans+=a;}
        else {a=0;i++;}
    }
    cout<<ans;



    return 0;

}

//       g++ -g c.cpp ; ./a.exe

Measured memory_bytes: 720
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG //これつけるとA[N]でもいいらしい
//for文のマクロ
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define big 1000000007
#define all(a) sort((a).begin(),(a).end()) //ソートのマクロ
#define Re(a) reverse((a).begin(),(a).end())
#define YN(a) if(a){cout<<"Yes"<<endl;}else cout<<"No"<<endl;//条件によってYes、Noを出力する
int main(){
    int64_t a,b,c;
    cin>>a>>b>>c;
    //cout << fixed << setprecision(10);
    int64_t d = c-a-b;
    if(d<=0){
        cout<<"No"<<endl;
        return 0;
    }
    int64_t l,r;
    l = 4*a*b;
    r = d*d;
    YN(l<r);
}

Measured memory_bytes: 256
L=int(input())
N,D,p=L.bit_length(),[],print
P=1<<(N-1)
for i in range(2,N+1):
    s=N-i
    D+=[(i-1,i,0),(i-1,i,1<<s)]
    if (L>>s)&1:D+=[(1,i,P)];P+=1<<s
p(N,len(D))
for x,y,c in D:p(x,y,c)

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

int main(){
    int h1, h2, m1, m2, k;
    int k_min, k_hour;
    int hour;
    int min;
    int output;

    cin >> h1 >> m1 >> h2 >> m2 >> k;

    k_min = k % 60;
    k_hour = (k - k_min) / 60;

    hour = (h2 - k_hour) - h1;
    
    if(m2 - k_min < 0){
        m2 = m2 + 60;
        min = m2 - k_min;
        hour = hour - 1;
    } else {
        min = m2 - k_min;
    }

    if(min - m1 < 0){
        min = min + 60 - m1;
        hour = hour - 1;
    } else {
        min = min - m1;
    }

    output = hour * 60 + min;

    cout << output << endl;

    return 0;
}

Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define SORT(v) sort((v).begin(), (v).end())
#define RSORT(v) sort((v).rbegin(), (v).rend())
const ll MOD = 1000000007;
const int nmax = 8;
bool graph[nmax][nmax];

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

ll lcm(ll a, ll b)
{
    ll g = gcd(a, b);
    return a / g * b;
}

ll mulMod(ll a, ll b)
{
    return (((a % MOD) * (b % MOD)) % MOD);
}
int dfs(int v, ll N, bool visited[nmax])
{
    bool all_visited = true;

    for (int i = 0; i < N; i++)
    {
        if (!visited[i])
        {
            all_visited = false;
        }
    }

    if (all_visited)
    {
        return 1;
    }
    int ret = 0;
    for (size_t i = 0; i < N; i++)
    {
        if (!graph[v][i])
        {
            continue;
        }
        if (visited[i])
        {
            continue;
        }

        visited[i] = true;
        ret += dfs(i, N, visited);
        visited[i] = false;
    }

    return ret;
}

void solve(long long x)
{
    ll ans = (x / 11) * 2;

    if (6 < x % 11)
    {
        ans += 2;
    }
    else if (x % 11 != 0)
    {
        ans++;
    }

    cout << ans << endl;
}

int main()
{
    long long x;
    scanf("%lld", &x);
    solve(x);
    return 0;
}


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

using namespace std;

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) FOR(i,0,n)
#define EPS (1e-8)

struct Vec {
	double x, y, z;
	
	Vec() {}
	Vec(double x, double y, double z) : x(x), y(y), z(z) {}
	Vec(const Vec &r) { *this = r; }
	
	Vec operator +(const Vec &r) const { return Vec(x + r.x, y + r.y, z + r.z); }
	Vec operator -(const Vec &r) const { return Vec(x - r.x, y - r.y, z - r.z); }
	Vec operator *(double r) const { return Vec(x * r, y * r, z * r); }
	Vec& operator =(const Vec &r) {
		x = r.x;
		y = r.y;
		z = r.z;
		return *this;
	}
};

double dot(const Vec &a, const Vec &b) { return a.x * b.x + a.y * b.y + a.z * b.z; }
Vec cross(const Vec &a, const Vec &b)  { return Vec(a.y * b.z - a.z  * b.y, a.z * b.x - a.x * b.z, a.x * b.y - a.y * b.x); }
double length(const Vec &a) { return sqrt(a.x * a.x + a.y * a.y + a.z * a.z); }


typedef Vec P;

double area(const P &a, const P &b, const P &c)  { return length(cross(b - a, c - a)) / 2.0; }

struct Line {
	P p;
	Vec v;
	Line(const P &p, const Vec &v) : p(p), v(v) {}
	
	P getPoint(double t) const { return p + v * t; }
};

struct Plane {
	P a, b, c;
	
	Plane(const P &a, const P &b, const P &c) : a(a), b(b), c(c) {}
};

vector<P> intersectionSPL(const Line &s, const Plane &pl) {
	vector<P> res;
	
	Vec no = cross(pl.b - pl.a, pl.c - pl.b);
	
	P a = s.p, b = s.getPoint(1.0);
	
	double da = dot(a - pl.a, no), db = dot(b - pl.a, no);

	if (abs(da) < EPS) da = 0.0;
	if (abs(db) < EPS) db = 0.0;
	if (da == 0.0 && db == 0.0) return res;
	else if (!(da * db <= 0.0)) return res;
	
	double t = abs(da) / (abs(da) + abs(db));
	res.push_back(s.getPoint(t));

	return res;
}


int main() {
	double x[5], y[5], z[5];
	REP(i, 5) cin >> x[i] >> y[i] >> z[i];
	
	P my(x[0], y[0], z[0]), en(x[1], y[1], z[1]);
	Plane ba(P(x[2], y[2], z[2]), P(x[3], y[3], z[3]), P(x[4], y[4], z[4]));
	
	Line beam(my, en - my);
	vector<P> v = intersectionSPL(beam, ba);
	
	if (v.empty()) puts("HIT");
	else {
		if (area(ba.a, ba.b, ba.c) - (area(ba.a, ba.b, v[0]) + area(ba.b, ba.c, v[0]) + area(ba.c, ba.a, v[0])) < -EPS)
			puts("HIT");
		else
			puts("MISS");
	}
	
	return 0;
}

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

const int MOD = 1000000007;
const int INF = 1e9;

//long long
using ll = long long;

//出力系
#define print(x) cout << x << endl
#define yes cout << "Yes" << endl
#define YES cout << "YES" << endl
#define no cout << "No" << endl
#define NO cout << "NO" << endl
 
// begin() end()
#define all(x) (x).begin(),(x).end()

//for
#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define REPR(i,n) for(int i=n, i##_len=(n); i>=0; i--)
#define FOR(i,a,b) for(int i=(a), i##_len=(b); i<i##_len; ++i)

//最大公約数 
unsigned gcd(unsigned a, unsigned b) {
  if(a < b) return gcd(b, a);
  unsigned r;
  while ((r=a%b)) {
    a = b;
    b = r;
  }
  return b;
} 

int main(){

int N, M;
cin >> N >> M;
const int nmmax=50;
char A[nmmax][nmmax],B[nmmax][nmmax];

REP(i, N) REP(j, N) cin >> A[i][j];
REP(i, M) REP(j, M) cin >> B[i][j];


bool ans = false;
for(int ly = 0; ly < N; ly++){
  for(int lx = 0; lx < N; lx++){
    if(lx + M - 1 >= N || ly + M - 1 >= N) continue;

    bool flag = true;
    for(int y = 0; y < M; y++){ 
       for(int x = 0; x < M; x++){ 
          if(A[ly + y][lx + x] != B[y][x]) flag = false;
       }
    }
      if(flag) ans = true;
  }
}

if(ans) yes;
else no;

}

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

int main(){
  long long int n;
  cin >> n;
  long long int a[n+10];
  for (int i =0;i<n;i++) cin >> a[i];
  long long int ans=0,nummi=0,mina;
  if (a[0]<0){
    mina = -a[0];
  }else{
    mina = a[0];
  }
  for (int i =0;i<n;i++){
    if (a[i] < 0){
      mina = min(mina,-a[i]);
      ans = ans - a[i];
      nummi += 1;
    }else{
      mina = min(a[i],mina);
      ans += a[i];
    }
  }
  
  if ((nummi % 2) == 0){
    cout << ans;
  }else{
    cout << ans-2*mina;
  }
}


Measured memory_bytes: 1024
N, M = map(int, input().split())
keyList = list(range(1,N+1))
values = [True] * N
dic = dict(zip(keyList, values))
HList = list(map(int, input().split()))
ans = []

for i in range(M):
  a, b = map(int, input().split())
  H_a = HList[a-1]
  H_b = HList[b-1]
  if(H_a == H_b):
    dic[a] = False
    dic[b] = False
  elif(H_b > H_a):
    dic[a] = False
  elif(H_a > H_b):
    dic[b] = False


for i in range(1, len(dic.values())+1):
  if(dic[i] == True):
    ans.append(dic[i])
print(len(ans))


Measured memory_bytes: 30112
#include<bits/stdc++.h>
using namespace std;
#define pi acos(-1.0)
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
typedef long long ll;
typedef unsigned long long ull;

int main()
{
    fastio;
    ll t, i, n, p, q, r, d, f=0;
    char *ye="YES", *no="NO";
    cin>>n;
    ll a[n];
    for(i=0;i<n;i++) a[i]=0;
    for(i=0;i<n-1;i++){
        cin>>p;
        a[p-1]++;
    }
    for(i=0;i<n;i++) cout<<a[i]<<endl;
}


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

typedef long long ll;

#define rep(i,n) for(int i = 0;i < n;i++);
#define reps(i,l,n) for(int i = l;i <= n;i++);

using namespace std;

int c = 0;
vector<vector<int>> ver(100,vector<int>(100));

void dfs(int target,int *endo,int *d,int *f){
    if(endo[target]) return ;
    endo[target] = 1;
    d[target] = ++c;
    if(ver[target].empty()) {
        f[target] = ++c;
        return ;
    }
    for(auto num : ver[target]){
        dfs(num,endo,d,f);
    }
    f[target] = ++c;
}

int main(){
    int n;
    cin >> n;
    int d[n],v[n],endo[n];
    for(int i=0;i<n;i++){
        d[i] = v[i] = endo[i] = 0;
        int num,hand;
        cin >> num >> hand;
        num--;
        for(int j=0;j<hand;j++){
            int child;
            cin >> child;
            child--;
            ver[num].emplace_back(child);
        }
    }
    for(int i=0;i<n;i++) dfs(i,endo,d,v);
    for(int i=1;i<=n;i++){
        cout << i <<  " " << d[i-1] << " " << v[i-1] << endl;
    }
}


Measured memory_bytes: 3232
import java.io.IOException;
import java.io.InputStream;
import java.util.NoSuchElementException;
 
public class Main {
	private static FastScanner sc = new FastScanner();
	
	public static void main(String[] args) {
		int N = sc.nextInt();
		int M = sc.nextInt();
		
		int[] a = new int[M];
		int[] b = new int[M];
		for(int i=0; i<M; i++) {
			a[i] = sc.nextInt();
			b[i] = sc.nextInt();
		}
		
		boolean[] x = new boolean[N];
		for(int i=0; i<M; i++) {
			if(a[i] == 1) {
				x[b[i]] = true;
			}
		}
			
		for(int i=0; i<M; i++) {
			if(b[i] == N && x[a[i]]) {
				System.out.println("POSSIBLE");
				return;
			}
		}
		
		System.out.println("IMPOSSIBLE");
	}
	
	static class FastScanner {
        private final InputStream in = System.in;
        private final byte[] buffer = new byte[1024];
        private int ptr = 0;
        private int buflen = 0;
        private boolean hasNextByte() {
            if(ptr < buflen) {
                return true;
            } else {
                ptr = 0;
                try {
                    buflen = in.read(buffer);
                } catch(IOException e) {
                    e.printStackTrace();
                }
                if(buflen <= 0) {
                    return false;
                }
            }
            return true;
        }
        private int readByte() { if (hasNextByte()) return buffer[ptr++]; else return -1;}
        private static boolean isPrintableChar(int c) { return 33 <= c && c <= 126;}
        private void skipUnprintable() { while(hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++;}
        public boolean hasNext() { skipUnprintable(); return hasNextByte();}
        public String next() {
            if (!hasNext()) throw new NoSuchElementException();
            StringBuilder sb = new StringBuilder();
            int b = readByte();
            while(isPrintableChar(b)) {
                sb.appendCodePoint(b);
                b = readByte();
            }
            return sb.toString();
        }
        public long nextLong() {
            return Long.parseLong(next());
        }
        public int nextInt(){
            return Integer.parseInt(next());
        }
        public double nextDouble(){
            return Double.parseDouble(next());
        }
    }
}


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

using namespace std;

int main() {
  int N, M;
  cin >> N >> M;
  for(int i = 0; i < M; i++) {
    int x;
    cin >> x;
    N = __gcd(N, x);
  }
  if(N == 1) cout << "Yes" << endl;
  else cout << "No" << endl;
}



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


int main()
{
	int a, b, c, x, y; cin >> a >> b >> c >> x >> y;
	int m = 2*c*max(x,y);
	m = min(m, a*x + b*y);
	m = min(m, a*x + 2*c*y);
	m = min(m, b*y + 2*c*x);
	if (x > y)
		m = min(m, 2*c*y + (x-y)*a);
	else 
		m = min(m, 2*c*x + (y-x)*b);
	cout << m << endl;
}



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

#if MYDEBUG
#include "lib/cp_debug.hpp"
#else
#define DBG(...) ;
#endif
#if __cplusplus <= 201402L
template <typename T>
T gcd(T a, T b) { return ((a % b == 0) ? b : gcd(b, a % b)); }
template <typename T>
T lcm(T a, T b) { return a / gcd(a, b) * b; }
#endif
using LL = long long;
constexpr LL LINF = 334ll << 53;
constexpr int INF = 15 << 26;
constexpr LL MOD = 1E9 + 7;

namespace Problem {
using namespace std;

class Solver {
 public:
  int n;
  string s;
  vector<int> w, b;
  Solver(LL n) : n(n), w(n + 1), b(n + 1){};

  void solve() {
    cin >> s;
    for (int i = 0; i < n; ++i) {
      if (s[i] == '.') {
        //white
        w[i + 1]++;
      } else {
        b[i + 1]++;
      }
    }
    for (int i = 1; i <= n; ++i) {
      w[i] += w[i - 1];
      b[i] += b[i - 1];
    }
    int ans = INF;
    for (int i = 0; i <= n; ++i) {
      //w:1 - i
      //b:i+1 - n
      ans = min(ans, b[i] - b[0] + w[n] - w[i]);
    }
    cout << ans << endl;
  }
};

}  // namespace Problem

int main() {
  std::cin.tie(0);
  std::ios_base::sync_with_stdio(false);
  // std::cout << std::fixed << std::setprecision(12);
  long long n = 0;
  std::cin >> n;

  Problem::Solver sol(n);
  sol.solve();
  return 0;
}


Measured memory_bytes: 2384
#include<deque>
#include<queue>
#include<vector>
#include<algorithm>
#include<iostream>
#include<set>
#include<cmath>
#include<tuple>
#include<string>
#include<chrono>
#include<functional>
#include<iterator>
#include<random>
#include<unordered_set>
#include<array>
#include<map>
#include<iomanip>
#include<assert.h>
#include<bitset>
#include<stack>
#include<memory>
using namespace std;
using namespace std::chrono;
typedef long long int llint;
typedef double lldo;
#define mp make_pair
#define mt make_tuple
#define pub push_back
#define puf push_front
#define pob pop_back
#define pof pop_front
#define fir first
#define sec second
#define res resize
#define ins insert
#define era erase

/*
cout<<fixed<<setprecision(20);
cin.tie(0);
ios::sync_with_stdio(false);
*/
const llint mod=1000000007;
const llint big=2.19e15+1;
const long double pai=3.141592653589793238462643383279502884197;
const long double eps=1e-15;
template <class T,class U>bool mineq(T& a,U b){if(a>b){a=b;return true;}return false;}
template <class T,class U>bool maxeq(T& a,U b){if(a<b){a=b;return true;}return false;}
llint gcd(llint a,llint b){if(a%b==0){return b;}else return gcd(b,a%b);}
llint lcm(llint a,llint b){if(a==0){return b;}return a/gcd(a,b)*b;}
template<class T> void SO(T& ve){sort(ve.begin(),ve.end());}
template<class T> void REV(T& ve){reverse(ve.begin(),ve.end());}
template<class T>llint LBI(vector<T>&ar,T in){return lower_bound(ar.begin(),ar.end(),in)-ar.begin();}
template<class T>llint UBI(vector<T>&ar,T in){return upper_bound(ar.begin(),ar.end(),in)-ar.begin();}

int main(void){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int i,j,n,K;cin>>n>>K;
	vector<int>h(n,mod);
	vector<int>c(n,mod);
	for(i=0;i<n;i++){
		cin>>h[i];
		if(i==0){c[i]=0;continue;}
		for(j=max(0,i-K);j<i;j++){mineq(c[i],c[j]+abs(h[i]-h[j]));}
	}
	cout<<c.back()<<endl;
	return 0;
}


Measured memory_bytes: 1024
//入力マクロここから
//https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
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 ) * } } ; }
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" ) } ; }
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 ) * } } ; }
//入力マクロここまで

//collections
//use std::collections::BTreeMap;
//use std::collections::BTreeSet;
//use std::collections::HashMap;
//use std::collections::HashSet;
//use std::collections::VecDeque;
//use std::collections::BinaryHeap;

use std::cmp::*;

fn main() {
    input! {
        n: usize,
        k: usize,
        x: [i64;n],
    }

    //0を１個入れる
    let mut x = x;
    let mut z = 0usize;
    while x[z] < 0 {
        z += 1;
        if z == n {
            break;
        }
    }
    x.insert(z, 0);
    let n = n + 1;
    let k = k + 1;

    let mut ans = 1_000_000_000_000i64;
    for i in 0..n + 1 - k {
        ans = min(
            ans,
            x[i].abs() + x[i + k - 1].abs() + min(x[i].abs(), x[i + k - 1].abs()),
        );
    }

    println!("{}", ans);
}


Measured memory_bytes: 6396
#include<bits/stdc++.h>
using namespace std;
#define fi first
#define sc second
typedef pair<int,int> P;
int num[26];
int main()
{
	int T;
	scanf("%d",&T);
	for(int cas=0;cas<T;cas++){
		int N,D;
		scanf("%d%d",&N,&D);
		int ans=0;
		for(int i=0;i<7;i++){
			if(N&1){
				if((D>>i)&1){
					ans+=(1<<i)*N;
				}
				else{
					ans+=(1<<i)*(N-1);
				}
			}
			else{
				if((D>>i)&1){
					ans+=(1<<i)*(N-1);
				}
				else{
					ans+=(1<<i)*N;
				}
			}
		}
		printf("%d\n",ans);
	}
	return 0;
	
}


Measured memory_bytes: 256
#include<cstdio>
#include<iostream>
#include<algorithm>
using namespace std;
int main()
{
	int a,b;
	cin>>a>>b;
	int x,y;
	a=a%500;
		if(a>b)
			puts("No");
		else
			puts("Yes");
	return 0;
}

Measured memory_bytes: 256
S = list(input())
T = list(input())
N = len(S)

a = ord('a')
alf = []
for i in range(26):
     alf.append(chr(a))
     a += 1

SN = [[] for i in range(26)]
TN = [[] for i in range(26)]
for i in range(N):
    for j in range(26):
        if alf[j] == S[i]:
            SN[j].append(i)
        if alf[j] == T[i]:
            TN[j].append(i)
SN.sort()
TN.sort()
print('Yes' if SN == TN else 'No')


Measured memory_bytes: 23152
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
#define INF 1000000000
#define LLINF 10000000000000000ll
#define MOD 1000000007LL

bool dbgflag = false;

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

  int n;
  cin >> n;
  vector<pll> each(n);
  vector<pll> dish;
  for (int i = 0; i < n; i++) {
    ll a, b;
    cin >> a >> b;
    each[i] = pll(a, b);
    dish.emplace_back(pll(a+b, i));
  }

  sort(dish.begin(), dish.end());
  reverse(dish.begin(), dish.end());
  
  ll d = 0;
  bool flag = true;
  for (pll ds: dish) {
    if (flag) d += each[ds.second].first;
    else d -= each[ds.second].second;
    flag = !flag;
  }
  
  cout << d << endl;
}


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

using namespace std;

using i64 = long long;

const i64 INF = 1e18 + 7;
const i64 MOD = 1e9 + 7;


signed main(){
    string s;
    cin >> s;
    vector<string> t{"Sunny", "Cloudy", "Rainy", "Sunny"};
    cout << *next(find(t.begin(), t.end(), s)) << endl;
}


Measured memory_bytes: 256
n = int(input())
l1 = list(map(int, input().split()))
l2 = list(map(int, input().split()))
c = 0

for i in range(n):
    if i != n-1:
        if l2[i] >= l1[i]:
            c += l1[i]
            diff = l2[i] - l1[i]
            l2[i+1] += min(diff, l1[i+1])
        else:
            c += l2[i]
    else:
        if l2[i] >= l1[i] + l1[i+1]:
            c += l1[i] + l1[i+1]
        else:
            c += l2[i]

print(c)

Measured memory_bytes: 18376
from collections import deque
    
N,K=map(int,input().strip().split())
x=list(map(int,input().strip().split()))
inf=10**9
    
l=inf
dp=deque(x[N-K:N])
i=0
while True:
    if dp[0]>=0:
        tmp=dp[K-1]
    elif dp[K-1]<=0:
        tmp=-dp[0]
    else:
        if abs(dp[K-1])>=abs(dp[0]):
            tmp=abs(dp[0])*2+abs(dp[K-1])
        else:
            tmp=abs(dp[K-1])*2+abs(dp[0])
    l=min(l,tmp)
    i+=1
    if N-K-i<0:
        break
    else:
        dp.appendleft(x[N-K-i])
        dp.pop()
print(l)

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

using namespace std;
#define all(a)a.begin(),a.end()
#define rep(i,n) for (int i = 0; i < (n); ++i)
using ll=long long;
const int INF = 1<<30;
const ll INFll =1LL<<62;
const int mod = int(1e9)+7;
using V = vector<ll>;
using P = pair<ll,ll>;

int main()
{
   string s;cin >>s;
   string ans="";
   int w;cin >>w;
   for(int i=0;i<(int)s.size();i+=w){
     ans+=s[i];
   }
   cout <<ans << endl;
    return 0;
}


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

signed main(){
	int n,k,a[100000],ma = 0,x = 0,y = 0;
	cin >> n >> k;
	for(int i = 0;i < n;i++) cin >> a[i];
	for(int i = 0;i < n - k;i++) x += max(0ll,a[i]);
	for(int i = n - k;i < n;i++) y += a[i];
	ma = max(ma,x + max(0ll,y));
	for(int i = 0;i < n - k;i++){
		x += max(0ll,a[n - i - 1]) - max(0ll,a[n - k - 1 - i]);
		y += a[n - k - 1 - i] - a[n - i - 1];
		ma = max(ma,x + max(0ll,y));
	}
	cout << ma << endl;
	return 0;
}

Measured memory_bytes: 1024
#include "bits/stdc++.h"

// Begin {{{
using namespace std;

#define all(x) x.begin(), x.end()
#define rep(i, n) for (i64 i = 0; i < (n); ++i)
#define reps(i, s, n) for (i64 i = (s); i <= (n); ++i)
#define VAR(Type, ...) Type __VA_ARGS__; IN(__VA_ARGS__)
#define Float(x) OUTN(fixed, setprecision(x));

using i64 = int_fast64_t;
using pii = pair<i64, i64>;

template <class A, class B>
inline bool chmax(A &a, const B &b) { return b > a && (a = b, true); }

template <class A, class B>
inline bool chmin(A &a, const B &b) { return b < a && (a = b, true); }

constexpr int INF = 0x3f3f3f3f;
constexpr i64 LINF = 0x3f3f3f3f3f3f3f3fLL;
constexpr int MOD = int(1e9) + 7;

// IN
void IN() {}
template <class Head, class... Tail>
void IN(Head&& head, Tail&&... tail) {
  cin >> head;
  IN(forward<Tail>(tail)...);
}

// OUTS
void OUTS() {}
template <class Head, class... Tail>
void OUTS(Head&& head, Tail&&... tail) {
  cout << head << " \n"[sizeof...(tail)==0];
  OUTS(forward<Tail>(tail)...);
}

template <class T>
void OUTS(vector<T> &vec) { for (auto &e : vec) cout << e << " \n"[&e==&vec.back()]; }

template <class T>
void OUTS(vector<vector<T>> &df) { for (auto &vec : df) OUTS(vec); }

// OUTL
void OUTL() {}
template <class Head, class... Tail>
void OUTL(Head&& head, Tail&&... tail) {
  cout << head << "\n";
  OUTL(forward<Tail>(tail)...);
}

template <class T>
void OUTL(vector<T> &vec) { for (auto &e : vec) cout << e << "\n"; }

// OUTN
void OUTN() {}
template <class Head, class... Tail>
void OUTN(Head&& head, Tail&&... tail) {
  cout << head;
  OUTN(forward<Tail>(tail)...);
}

template <class T>
void OUTN(vector<T> &vec) { for (auto &e : vec) cout << e; }
// }}} End

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

  VAR(int, n);

  vector<i64> a(3 * n);
  rep(i, 3 * n) {
    IN(a[i]);
  }

  sort(all(a), greater<>());

  i64 cnt = 0;
  i64 i = 1;
  i64 res = 0;
  while (cnt < n) {
    res += a[i];
    ++cnt;
    i += 2;
  }

  OUTL(res);

  return 0;
}


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

#define ll long long
#define ld long double
#define pb push_back
#define eb emplace_back
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()

//#define int long long
using namespace std;
const int INF = 2e9;
const int MOD = 1e9 + 7;
const int MB = 60;

void solve() {
	int n;
	cin >> n;
	vector<double> a(n + 1);
	for (int i = 1; i <= n; i++) {
		cin >> a[i];
	}

	vector<vector<double>> dp(n + 1, vector<double>(n + 1));
	dp[0][0] = 1;
	for (int i = 1; i <= n; i++) {
		for (int j = 0; j <= n; j++) {
			dp[i][j] = (j ? dp[i - 1][j - 1] * a[i] : 0) + dp[i - 1][j] * (1 - a[i]);
		}
	}
	
	double ans = 0;
	for (int i = n / 2 + 1; i <= n; i++) {
		ans += dp[n][i];
	}
	cout << ans;
}

signed main() {
	/*
	freopen("search.in", "r", stdin);
	freopen("search.out", "w", stdout);
	*/
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.tie(nullptr);
	cout << fixed;
	cout.precision(12);
	solve();
}


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

int N;
void DFS(string s, char mx){
	/*
		ありえないくらい解説行数すくなくて泣いた。
		標準形の条件言いかえのシンプルさもスゴイし、文字列でDFSするなんて考えに至れなかったなぁ……。
		レートどかっと落ちたけど、とてもタメになって楽しかったです（笑）
		

		[復習]
		文字列 s1, s2, ... sNが標準形である、ということは、

		・s1 = "a"
		・sK = max{s1, ... , sK-1}+1 ( 2<=k<=N )
		(!) ここで、『 "+1"というのは、辞書順でひとつ次の文字を表す』
			-> (例) "aaa"+1 = "aab"


		// mx: a -> 「ケツに足せる文字」
			
	*/
	if(s.length()==N)cout<<s<<endl;
	else{
		for(char c='a'; c<=mx; c++){
			DFS(s+c, ((c==mx)? (char)(mx+1):(mx)));
		}
	}
}

int main(){
	cin>>N;
	DFS("",'a');
	

	return 0;
}


Measured memory_bytes: 1536
n,k=map(int,input().split())
ab=abs
k=min(n,k)
hr=list(map(int,input().split()))
dp=[-1]*(n+1)
dp[0]=0
dp[1]=ab(hr[1]-hr[0])
for i in range(1,k):
	x=ab(hr[i]-hr[i-1])+dp[i-1]
	for j in range(1,i+1):
		y=ab(hr[i]-hr[i-j])+dp[i-j]
		x=min(x,y)
	dp[i]=x




for i in range(k,n):
	x=ab(hr[i]-hr[i-1])+dp[i-1]
	h=hr[i]
	for j in range(1,k+1):
		y=ab(h-hr[i-j])+dp[i-j]
		x=min(x,y)
	
	dp[i]=x
print(dp[n-1])

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

inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

template<class T> inline T sqr(T x) {return x*x;}

typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;
typedef unsigned long long ULL;

#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

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

const double EPS = 1e-10;
const double PI  = acos(-1.0);

#define CLR(a) memset((a), 0 ,sizeof(a))

#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

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

int main() {
  int t;

  cin >> t;  
  REP(i, t) {
    int n, k;
    cin >> n >> k;
  
    VI x(n), d(n-1);
    REP(j, n) cin >> x[j];
    int s = 0;
    REP(j, n-1) {
      d[j] = x[j+1] - x[j];
      s += d[j];
    }

    sort(ALL(d), greater<int>());

    int end = min(n-1, k-1);
    REP(j, end) {
      s -= d[j];
    }

    cout << s << endl;
  }
}

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

using namespace std;

int main()
{
	int n, m;
	cin >> n >> m;
	vector<pair<int, int>> st(n), ck(m);
	for (auto&& sti : st) cin >> sti.first >> sti.second;
	for (auto&& cki : ck) cin >> cki.first >> cki.second;
	for (auto&& sti : st)
	{
		int mind = INT_MAX;
		int mini = 0;
		for (int i = 0; i < m; i++)
		{
			auto d = abs(sti.first - ck[i].first) + abs(sti.second - ck[i].second);
			if (d < mind)
			{
				mind = d;
				mini = i+1;
			}
		}
		cout << mini << endl;
	}
	return 0;
}


Measured memory_bytes: 256
MOD=10**9+7
cnt=0; sum=0; prev=nil; can=true; h=Hash.new(0)
def gs() gets.chomp end
def gi() gets.to_i end
def gsmi() gets.chomp.split.map(&:to_i) end

def desc(ar) ar.sort!{|x,y|y<=>x} end
def min(a,b) a<=b ? a : b end
def max(a,b) a>=b ? a : b end
def sum(ar) ar.inject(:+) end

def bs(ar,eq,n) en=(eq==1 ? :>= : :>); ar.bsearch_index{|x|x.send(en,n)} end
def C(a,b) b==0||a==b ? 1 : (b=a-b if a/2<b;(a-b+1..a).inject(:*)/(1..b).inject(:*)) end

def puts_yesno(can) puts(can ? 'Yes' : 'No') end
def putsend(s) puts s; exit end
def debug(k,v) puts "#{k}:#{v}" end
########### ( ˘ω˘ )ｽﾔｧ… ###########
n,cc=gsmi
d=cc.times.map{gsmi}
c=n.times.map{gsmi}

min=10**9+7

a1=Hash.new(0)
a2=Hash.new(0)
a3=Hash.new(0)
n.times do |i|
  n.times do |j|
    case (i+j)%3
    when 1
      a1[c[i][j]]+=1
    when 2
      a2[c[i][j]]+=1
    when 0
      a3[c[i][j]]+=1
    end
  end
end

1.upto(cc) do |i|
  fix=[i]
  c1=0
  a1.each do |key,val|
    next if i==key
    c1+=d[key-1][i-1]*val
  end

  1.upto(cc) do |j|
    next if fix.include?(j)
    fix=[i,j]
    
    c2=0
    a2.each do |key,val|
      next if j==key
      c2+=d[key-1][j-1]*val
    end

    1.upto(cc) do |k|
      next if fix.include?(k)
      #fix<<k

      c3=0
      a3.each do |key,val|
        next if k==key
        c3+=d[key-1][k-1]*val
      end
      cnt=c1+c2+c3
      #puts "#{i},#{j},#{k} #{cnt}"
      min=cnt if cnt<min
    end
  end
end

puts min

Measured memory_bytes: 4476
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define INF 1e8;
typedef long long ll;
ll mod = 1e9+7;
long long fast_exp(long long a, long long b)
{
    if(b == 0)
	   return 1;
    else
    {
	   long long res = 1;
	   res = fast_exp(a,b/2);
	   res = (res*res)%mod;
	   if(b%2 == 1)
		  res = (res*a)%mod;
	   return res;
 
    }
}
const ll N = 1e5;

 

 
int main()
{
	// ios_base::sync_with_stdio(false);
	// cin.tie(NULL);
	ll a,b;
	cin>>a>>b;
	cout<< (a*b)/__gcd(a,b);
	return 0;
	
}

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

int main()
{
	int X, A, B, C,ans = 0;

	cin >> A >> B >> C >> X;

	for (int i = 0,sum = 0; i <= A; i++) {
		sum = 0;
		sum += i * 500;
		for (int k = 0; k <= B; k++) {
			sum += k * 100;
			for (int v = 0; v <= C; v++) {
				if (sum + v * 50== X) {
					ans++;
				}
			}
			sum -= k * 100;
		}
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (n); i++)
using ll = long long;
using ull = unsigned long long;
using P = pair<int,int>;
using PP = pair<int,pair<int,int>>;
using T = tuple<string,int,int>;
const string EMP = " ";
const ll INF = 1LL<<60;
const ll MOD = 1000000007;

int main(){
  int n,m; cin >> n >> m;
  vector<int> x(m);
  rep(i,m) cin >> x[i];
  sort(x.begin(), x.end());
  vector<int> dist;
  for(int i = 1; i < m; i++){
    int d = x[i] - x[i-1];
    dist.push_back(d);
  }
  sort(dist.begin(), dist.end());
  int ans = 0;
  for(int i = 0; i < m-n; i++){
    ans += dist[i];
  }
  cout << ans << endl;
  return 0;
}


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

using namespace std;
using llong = long long int;

#define rep(i, n) for (int i = 0; i < ((int)n); ++i)
#define stl_rep(itr, x) for (auto itr = x.begin(); itr != x.end(); ++itr)
#define all(x) x.begin(), x.end()
#define allr(x) x.rbegin(), x.rend()

// const static int MOD = 1000000007;
const static int INF = 1000000000;
const static int dx[4] = {1, 0, -1, 0};
const static int dy[4] = {0, 1, 0, -1};

int main (int argc, char *argv[]) {
    cin.tie(0);
    ios::sync_with_stdio(false);

    string n;
    cin >> n;
    int k = n.size();
    if (n[k - 1] == '3') cout << "bon" << endl;
    else if (n[k - 1] == '0' || n[k - 1] == '1' || n[k - 1] == '6' || n[k - 1] == '8') cout << "pon" << endl;
    else cout << "hon" << endl;

    return 0;
}

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

#define ll long long
using namespace std;

int main() {
    ll n, m;
    cin >> n >> m;
    vector<vector<ll>> v(n, vector<ll>(2));
    for (int i = 0; i < n; i++)cin >> v[i][0] >> v[i][1];
    sort(v.begin(), v.end());
    ll ret = 0;
    for (int i = 0; m > 0; i++) {
        ret += min(m, v[i][1]) * v[i][0];
        m -= min(m, v[i][1]);
    }
    cout << ret << endl;
    return 0;
}

Measured memory_bytes: 5760
#include<bits/stdc++.h>
using namespace std;
#define ull unsigned long long int
const ull MOD =1000000007;



ull POWER(ull x,ull y)
{
    if(y==0)return 1;
    if(y%2==0)
    {
        x = POWER((x*x)%MOD,y/2)%MOD;

    }
    else{
        x = x*POWER(x,y-1)%MOD;
    }
    return x;
}


int main()
{
    ull n,k;cin>>n>>k;

    ull tryall[k+1];
    for(int x=1;x<=k;x++){
        tryall[x] = POWER(k/x,n);
    }

    ull ans = 0;
    for(int x=k;x>=1;x--){
        for(int j=2;j*x<=k;j++){
            tryall[x] = (tryall[x]-tryall[j*x]+MOD)%MOD;
        }
        ans= ans + (tryall[x]*x)%MOD;
        ans%=MOD;
    }

    cout<<ans;

}


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

using namespace std;

typedef long long ll;
typedef vector<ll> vll;
typedef vector<bool> vb;
typedef pair<ll,ll> pll;
typedef vector<pll> vpll;

const ll mod=1000000007;
const ll inf=1e+16; 

#define rep(i,m,n) for(ll i=m;i<n;i++)

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

 ll n;
  cin >> n;
  vll x(n),y(n);
  vll perm(n);
  rep(i,0,n) {
    cin >> x[i] >> y[i];
    perm[i]=i;
  }
 
  double res=0;
  do{
    rep(i,0,n-1) res+=sqrt((x[perm[i]]-x[perm[i+1]])*(x[perm[i]]-x[perm[i+1]])+(y[perm[i]]-y[perm[i+1]])*(y[perm[i]]-y[perm[i+1]]));
  }while(next_permutation(perm.begin(), perm.end()));
  ll div=1;
  rep(i,0,n) div*=(i+1);
  res/=div;
  cout << setprecision(12) << res << endl;
  
}

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

namespace ABC093_B_Small_and_Large_Integers
{
	internal class Program
	{
		public static void Main(string[] args)
		{
			string[] input = Console.ReadLine().Split(' ');
			int a = int.Parse(input[0]);
			int b = int.Parse(input[1]);
			int k = int.Parse(input[2]);
			
			List<int> numbers = new List<int>();

			for (int i = a; i < a + k; i++) {
				numbers.Add(i);
				if (i <= b)
				{
					Console.WriteLine(i);
				}
			}
			
			for (int i = b - k + 1; i <= b; i++) {
				if (i >= a && !numbers.Any(x => x == i))
				{
					Console.WriteLine(i);
				}
			}
		}
	}
}

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

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

    int hasu = x % 100;
    int nokori = x - hasu;

    for (auto f = 0; f < 20; f++)
    {
        for (auto e = 0; e < 25; e++)
        {
            for (auto d = 0; d < 34; d++)
            {
                for (auto c = 0; c < 50; c++)
                {
                    int b = hasu - 5 * f - 4 * e - 3 * d - 2 * c;
                    if (b < 0)
                    {
                        continue;
                    }
                    else
                    {
                        if ((b + c + d + e + f) * 100 <= nokori)
                        {

                            cout << 1 << endl;
                            return 0;
                        }
                    }
                }
            }
        }
    }
    cout << 0 << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define int long long int
#define inf 1e9 
int solve(vector<int> a,int n,int k)
{
    vector<int> dp(n+1);
    dp[1]=0;
    for(int i=2;i<=n;i++)
    {
        dp[i]=inf;
        for(int j=i-1;j>=1 && (i-j)<=k;j--)
        {
            dp[i]=min(dp[i],abs(a[i]-a[j])+dp[j]);
        }
    }
    return dp[n];
}
signed main()
{
    int n,k;
    cin>>n>>k;
    vector<int> v(n+1);
    for(int i=1;i<=n;i++)
        cin>>v[i];
    cout<<solve(v,n,k)<<endl;
}

Measured memory_bytes: 5640