akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define PI 3.14159265359
#define NIL (-1)
#define LL long long
using namespace std;
const int64_t MOD = 1e9 + 7;

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

	vector<int> v(n);
	for (int i = 0; i < n; i++) cin >> v.at(i);
	sort(v.begin(), v.end());

	int a, b;
	a = v.back();
	b = a;

	for (int i = 0; i < n - 1; i++) {
		int x, y;
		x = abs(a / 2 - b);
		y = abs(a / 2 - v.at(i));
		if (x >= y) b = v.at(i);
	}

	cout << a << ' ' << b << endl;
}

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

#define M 1000000007
#define MM 998244353 
#define ll long long 
#define pb push_back
#define mem0(a) memset(a,0,sizeof(a))
#define mem1(a) memset(a,-1,sizeof(a))
#define memf(a) memset(a,false,sizeof(a))
#define all(v) v.begin(),v.end()
#define sz(a) (ll)a.size()
#define F first
#define S second
#define PI 3.1415926536
#define INF 2000000000000000000
#define endl "\n"
#define _time_ 1.0 * clock() / CLOCKS_PER_SEC
//RNG based on mersenne_twister 
mt19937 rng(chrono::high_resolution_clock::now().time_since_epoch().count());
ll power(ll b,ll e,ll m)
{
	if(e==0) return 1;
	if(e&1) return b*power(b*b%m,e/2,m)%m;
	return power(b*b%m,e/2,m);
}
ll power( ll b, ll e)
{
	if(e==0) return 1;
	if(e&1) return b*power(b*b,e/2);
	return power(b*b,e/2);
}
template<typename T, typename U> static inline void amin(T &x, U y){ if(y<x) x=y; }
template<typename T, typename U> static inline void amax(T &x, U y){ if(x<y) x=y; }


int _runtimeTerror_()
{
	ll n,k,i;
	cin>>n>>k;
	ll ans=0;
	for(i=k;i<=n+1;++i)
	{
		ans+=n*(n+1)/2%M-(n-i)*(n-i+1)/2%M-i*(i-1)/2%M+1;
		ans%=M;
		ans+=M;
		ans%=M;
	}
	cout<<ans<<endl;
	return 0;
}

int main()
{
	ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	#ifdef runSieve
		sieve();
	#endif
	#ifdef NCR
		initialize();
	#endif
	int TESTS=1;
	//cin>>TESTS;
	while(TESTS--)
		_runtimeTerror_();
	cerr<<"\n"<<_time_;
	return 0;
}


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

const double PI = acos(-1);
const double EPS = 1e-15;
using ll = long long;
using ull = unsigned long long;
const int inf = 2e9;
const ll INF = 2e18;
const ll MOD = 1e9+7;
const ll MOD1 = 998244353;
typedef pair<ll,ll> P;

#define rep(i,a,b) for (int i = (a); i < (b); i++)
#define rrep(i,a,b) for (int i = (a); i >= (b); i--)
#define REP(i,n) rep(i,0,n)
#define RREP(i,n) rrep(i,n,0)
#define sz(s) (s).size()
#define pb push_back
#define fi first
#define se second
//#define mp make_pair

int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  ll n;
  cin >> n;
  for (ll i = 100000; i >= 0; i--) {
    if (i * i <= n) {
      cout << i * i << endl;
      return 0;
    }
  }

  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<vector>
#include<map>
#include<string>
#include<algorithm>
#include<math.h>

using namespace std;

typedef vector<int> vi;
typedef pair<int, int> pii;
typedef long long ll;
typedef pair<long long, long long> pll;

const int INF = 1e9;
const int MOD = 1e9 + 7;

int main(){
	int N;
	cin >> N;
	cout << N * 800 - int(N / 15) * 200 << endl;
}



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

int main() {
  int N;
  ll r;
  ll L[2];
  cin >> N;
  
  if(N == 0)
  {
    cout << 2;
    return 0;
  }
  if(N == 1)
  {
    cout << 1;
    return 0;
  }
  L[0] = 2;
  L[1] = 1;
  for(int i = 2; i < N+1; i++)
  {
    r = L[1] + L[0];
    L[0] = L[1];
    L[1] = r;
  }
  cout << r;

}


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

using ll = long long;

const long long INF = 1e18L + 10;
const int N = 410;
ll prefix_sum[N];
vector<vector<long long>> dp(N, vector<long long> (N, INF));
// dp[i][j] will be the minumum cost to combine slimes [i, j] together
 

long long get_prefix_sum(int i, int j)
{
  if(i == 0)
    return prefix_sum[j];
  else
    return prefix_sum[j] - prefix_sum[i - 1];
}

int main()
{
  int n;
  scanf("%d", &n);
  vector<long long> a(n);
  for(int i = 0; i < n; i++)
  {
    scanf("%lld", &a[i]);
  }
 
  prefix_sum[0] = a[0];
  for(int i = 1; i < n; i++)
  {
    prefix_sum[i] = prefix_sum[i - 1] + a[i];
  }
  
  for(int L = n - 1; L >= 0; L--)
  {
    for(int R = L; R < n; R++)
    {
      if(L == R)
        dp[L][R] = 0;
      else
      {
        for(int i = L; i <= R; i++)
        {
          dp[L][R] = min(dp[L][R], dp[L][i] + dp[i + 1][R] + get_prefix_sum(L, R));
        }
      }
    }
  }
  printf("%lld", dp[0][n - 1]);
  
  return 0;
}


Measured memory_bytes: 1536
package main

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

var sc = bufio.NewScanner(os.Stdin)
var out = bufio.NewWriter(os.Stdout)

func main() {
	buf := make([]byte, 1024*1024)
	sc.Buffer(buf, bufio.MaxScanTokenSize)
	sc.Split(bufio.ScanWords)
	defer out.Flush()
	var house [4][3][10]int

	n := nextInt()
	for i := 0; i < n; i++ {
		b, f, r, v := nextInt(), nextInt(), nextInt(), nextInt()
		house[b-1][f-1][r-1] += v
	}

	for i := 0; i < len(house); i++ {
		for j := 0; j < len(house[i]); j++ {
			for k := 0; k < len(house[i][j]); k++ {
				fmt.Fprintf(out, " %d", house[i][j][k])
			}
			fmt.Fprintf(out, "\n")
		}
		if i != 3 {
			fmt.Fprintf(out, "####################\n")
		}
	}
}

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

func nextInt() int {
	a, _ := strconv.Atoi(next())
	return a
}



Measured memory_bytes: 1152
#include <bits/stdc++.h>
using namespace std;
 
int main() {
    int N; cin >> N;
    priority_queue<double> values;
    for (int i = 0; i < N; i++) {
        double value; cin >> value;
        values.push(- value);
    }

    for (int i = 0; i < N - 1; i++) {
        double v1; v1 = values.top();
        values.pop();
        double v2; v2 = values.top();
        values.pop();
        double mean; mean = (v1 + v2) / 2.0;
        values.push(mean);
    }

    double ans; ans = - values.top();
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
import java.io.*;
import java.util.*;

public class Main {
    PrintWriter out = new PrintWriter(System.out);
    // no self-loop or multiple edges
    public static void main(String[] args) throws Exception {
        Main main = new Main();
//        main.solve();
        System.out.println(main.solve());
    }
    long solve(){
        Scanner sc = new Scanner(System.in);
        int H = sc.nextInt(), n = sc.nextInt();
        int[] cur = new int[H+1], next = new int[H+1];
        Arrays.fill(cur,Integer.MAX_VALUE/2);
        cur[H] = 0;
        for(int i=0;i<n;i++){
            Arrays.fill(next,Integer.MAX_VALUE/2);
            int a = sc.nextInt(), b = sc.nextInt();
            if(a>H){
                System.arraycopy(cur, 0, next, 0, H+1);
                next[0] = Math.min(next[0], b);
            } else{
                for(int j=H; j>H-a; j--) next[j] = cur[j];
                for(int j=H-a;j>0;j--){
                    next[j] = Math.min(next[j+a]+b,Math.min(cur[j],cur[j+a]+b));
                }
                next[0] = cur[0];
                for(int j=a;j>=0;j--){
                    next[0] = Math.min(next[0],Math.min(cur[j]+b,next[j]+b));
                }
            }
            System.arraycopy(next, 0, cur, 0, H+1);
        }
        long ans = cur[0];
        sc.close();
        return ans;
    }
}



Measured memory_bytes: 26128
#include<iostream>
#include<algorithm>
#include<string>
#include<cstring>
#include<sstream>
#include<iomanip>
#include<limits>
#include<deque>
#include<map>
#include<list>
#include<set>
#include <unordered_set>
#include<vector>
#include<cmath>
#include<cstdio>
#include<memory>
#include<bitset>
#include<stack>
#include<functional>
#include<queue>
#include<regex>
#include<time.h>
#include<type_traits>

using namespace std;
using ll = long long;

constexpr ll MOD = 1000000007;
constexpr ll INF = 1050000000;
constexpr ll LONGINF = 1050000000000000000;


int main() {
	int n; cin >> n;
	vector<ll> a(n), b(n);
	priority_queue<pair<ll, int>> q;

	for (int i = 0; i < n; i++) {
		cin >> a[i];
	}
	for (int i = 0; i < n; i++) {
		cin >> b[i];
		q.push({ b[i],i });
	}

	ll ans = 0;
	bool flag = true;

	while (!q.empty()) {
		ll key = q.top().first;
		int i = q.top().second;
		q.pop();

		if (a[i] == key) {//値が同じなら終了
			
		}
		else {
			if (a[i] > key) {//処理する値がそれ未満なら、不可能
				flag = false;
				break;
			}
			else {//a[i]<keyの時

				ll s = (b[(i - 1 + n) % n] + b[(i + 1) % n]);
				ll t = b[i] - a[i];

				ans += t / s;

				if ((t / s) == 0) {
					flag = false;
					break;
				}

				key -= (t / s) * s;
				b[i] = key;
				q.push({ key,i });
			}
		}
	}

	for (int i = 0; i < n; i++) {
		if (a[i] != b[i]) {
			flag = false;
			break;
		}
	}


	
	if (flag) {
		cout << ans << endl;
	}
	else {
		cout << -1 << endl;
	}


	return 0;
}

Measured memory_bytes: 9584
#include<iostream>
#include<cstdio>
#include<cmath>
using namespace std;


int main(){
	int n[10000],q[500],x,y,s=0;
	cin >> x;
	for(int i=0; i<x ; i++) cin >> n[i];
	cin >> y;
	for(int i=0; i<y; i++) cin >> q[i];
	

	for(int i=0; i<y; i++){
		for(int j=0; j<x; j++){
			if( q[i]==n[j] ){
				s++;
				break;
			}
		}
	}

	cout << s << "\n";
	return 0;
}

Measured memory_bytes: 3160
import math
X=int(input())
if X==2:
    print(2)
else:
    n=1
    while n==1:
        for j in range(2,int(math.sqrt(X))+1):
            if j==int(math.sqrt(X)) and X%j!=0:
                n=0
                print(X)
            elif X%j==0:
                X+=1
                break

Measured memory_bytes: 38896
S = input()
T = input()

mS = []
d = len(S) - len(T)
m = 0

if len(S) == len(T) :
    for i in range(len(T)):
        if S[i] != T[i] :
            m += 1
    print(m)

else :

    for j in range(d):
        m = 0
        for i in range(len(T)):
            if S[i] != T[i] :
                m += 1

        mS.append(m)
        S = S[1:]
    print(min(mS))


Measured memory_bytes: 8916
#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
int
main
() {
	int	n;
	long long
		X
		=
		0
		, x
		=
		0
		, ans
		=
		1000000000000000000LL
		;
	cin
		>>
		n;
	vector
		<
		long
		long
		>
		a(n);
	for
		(
			int
			i
			=
			0
			; i
			<
			n; i
			++
			) {
		cin
			>>
			a[i];
		X
			+=
			a[i];
	}
	for
		(
			int
			i
			=
			0
			; i
			<
			n; i
			++
			) {
		x
			+=
			a[i];
		if
			(i
				+
				1
				<
				n)ans
			=
			min(ans, abs(X
				-
				2
				*
				x));
	}
	cout
		<<
		ans
		<<
		endl;
}

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

int main() {
  int a,b,c; cin >> a >> b;
  cout << 6 - a - b << endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <complex>
#include <fstream>
#include <cmath>

using namespace std;

int main(void){
    int a, b, c; cin >>a >> b >> c;
    if(a!=b && b!=c && c!=a){
        cout << "3" << endl;
    }else if(a==b&&b==c&&c==a){
        cout << "1" << endl;
    }else{
        cout << "2" << endl;
    }
    return 0;
}


Measured memory_bytes: 256
import sys
input = sys.stdin.readline

N = int(input())
A = [int(input()) for _ in range(N)]

ind = [None]*N
for i, a in enumerate(A):
    ind[a-1] = i

p = 0
pre = -1
k = 0
for i in ind:
    if i > pre:
        k += 1
    else:
        k = 1
    p = max(p, k)
    pre = i

print(N-p)

Measured memory_bytes: 18888
N = int(input())
from collections import Counter
A = list(map(int, input().split()))
B = list(map(int, input().split()))
ca = Counter(A)
cb = Counter(B)
mod = 10**6
cnts = [set() for _ in range(N+1)]
for i in range(1,N+1):
  if ca[i]+cb[i]>N:
    print('No')
    exit()
  if ca[i]+cb[i]>0:
    cnts[ca[i]+cb[i]].add(i)

def get_any(counts,r):
  for k in counts.keys():
    if counts[k]>0 and k!=r:
      return k

def update_cnt(cnt_,r):
  cnt_[r] -= 1
  if cnt_[r]==0:
    del cnt_[r]

lis = [[] for _ in range(N+1)]
for i in range(N,0,-1):
  if len(cnts[i])==2:
    p,q = cnts[i]
    for j in range(ca[p]):
      lis[p].append(q)
    for j in range(ca[q]):
      lis[q].append(p)
    break
  elif len(cnts[i])==1:
    p, = cnts[i]
    for j in range(ca[p]):
      q = get_any(cb,p)
      update_cnt(cb,q)
      lis[p].append(q)
    for j in range(cb[p]):
      q = get_any(ca,p)
      update_cnt(ca,q)
      lis[q].append(p)
    break
  else:
    p = get_any(ca,-1)
    q = get_any(cb,p)
    lis[p].append(q)
    cnts[ca[p]+cb[p]].remove(p)
    cnts[ca[q]+cb[q]].remove(q)
    update_cnt(ca,p)
    update_cnt(cb,q)
    cnts[ca[p]+cb[p]].add(p)
    cnts[ca[q]+cb[q]].add(q)
ans = []
for i in range(1,N+1):
  for b in lis[i]:
    ans.append(b)
print('Yes')
print(*ans)


Measured memory_bytes: 207068
#include<bits/stdc++.h>
using namespace std;
#define all(v) v.begin(), v.end()
using in = int64_t;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define Yes cout<<"Yes"<<endl 
#define No cout<<"No"<<endl
#define yes cout<<"yes"<<endl 
#define no cout<<"no"<<endl
#define vec(a,y,x)  vector<vector<char>> a (y,vector<char>(x))
const double PI=3.14159265358979323846;
const in MOD = 1000000007;
const in INF=1e18+7;
const int inf=1e9+7;
const vector<int> dx={1,0,-1,0};
const vector<int> dy={0,1,0,-1};

int main(){
  int n;
  cin>>n;
  for(int i=1;i<=n;i++){
    in ans=0;
    //int d=sqrt(i)+1;
    
    
    for(int x=1;x*x<=i;x++){
      int m=i;
      //m-=x*x;
      //if(m<=0) continue;
      for(int y=1;y<=x;y++){
        //m-=y*y;
        //if(m<=0) continue;
        for(int z=1;z<=y;z++){
          //m-=z*z;
          //if(m<=0) continue;
          if(x*x+y*y+z*z+x*y+y*z+z*x==m){
            int s=0;
            if(x!=y)s++;
            if(y!=z)s++;
            if(s==0) ans++;
            if(s==1) ans+=3;
            if(s==2) ans+=6;
            //if(s>2) cout<<"????";
            //break;
          }
        }
      }
    }
    cout<<ans<<endl;
  }
  
}

Measured memory_bytes: 3572
//
//  main.cpp
//  joi
//
//  Created by 8595198919 on 14/06/09.
//  Copyright (c) 2014年 8595198919. All rights reserved.
//

#include <iostream>
#include <list>
#include <stack>
#include <cstdio>
#define rep(i,n) for(int i = 0;i < n;i++)
#define Rep(i,n) for(int i = 1;i <= n;i++)
#define fs first
#define sc second
#define mp make_pair
using namespace std;

int w,h;
int xs,ys,xg,yg;
int n;
int goal[2];
int dx[4]={1,0,0,-1};
int dy[4]={0,1,-1,0};
int map_[105][105];
bool went[105][105];
int c,d,x,y;

bool search(int x,int y){
    if(map_[x][y]==0)
        return 0;
    if(x==xg&&y==yg)
        return 1;
    rep(i,4){
        int xnext = x +dx[i];
        int ynext = y +dy[i];
        if(went[xnext][ynext])
            continue;
        if(map_[xnext][ynext]==map_[x][y]){
            went[x][y]=true;
            if(search(xnext,ynext))
                return 1;
        }
    }
    return 0;
}


int main(){
    while(scanf("%d %d",&w,&h),(w!=0&&h!=0)){
        rep(i,w+5){
            rep(j,h+5){
                map_[i][j]=0;
                went[i][j]=0;
            }
        }
        scanf("%d %d %d %d %d",&xs,&ys,&xg,&yg,&n);
        xs++,ys++,xg++,yg++;
        rep(i,n){
            scanf("%d %d %d %d",&c,&d,&x,&y);
            x++,y++;
            rep(i,(dx[d]+1)*2){
                rep(j,(dy[d]+1)*2){
                    map_[x+i][y+j] = c;
                }
            }
        }
        if(search(xs,ys))
            cout << "OK" << endl;
        else
            cout <<"NG"<<endl;
    }
}

Measured memory_bytes: 1252
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define F first
#define S second
#define mod 1000000007
vector<pair<int,int> > v;
int main(){
    ios::sync_with_stdio(false);cin.tie(0);
    
    int n;
    cin>>n;
    for(int i=1;i<=n;i++){
        int x;
        cin>>x;
        v.pb({x,i});
    }

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

    int c=1;
    int ans=0;
    for(auto i:v){
        if(i.S%2!=c%2)ans++;

        c++;
    }
    cout<<ans/2;
    return 0;
}

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

using namespace std;

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

	int i = 0;
	long long cnt = 0, black = 0;
	string s ;
	cin >> s;
	int n = s.size();
	while(i < n) {

		if(s[i] == 'B')
			black++;
		else if(s[i] == 'W') {

			cnt += black;

		}
		i++;


	}
	cout << cnt;

	return 0;
}

Measured memory_bytes: 720
#include <fstream>
#include <iostream>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <bitset>
#include <iomanip>
 
using namespace std;
typedef long long ll;
typedef unsigned long long ull;

int main(int argc, const char * argv[]) {
    int X; cin >> X;
    int N; cin >> N;
    vector<int> p(N);
    for (int i = 0; i < N; i++) cin >> p[i];
    sort(p.begin(), p.end());

    for (int i = 0; i <= 100; i++) {
        int tmp = X - i;
        if (!binary_search(p.begin(), p.end(), tmp)) {
            cout << tmp << endl;
            break;
        }

        tmp = X + i;
        if (!binary_search(p.begin(), p.end(), tmp)) {
            cout << tmp << endl;
            break;
        }
    }

    return 0;
}


Measured memory_bytes: 3164
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#define INF 99999999
using namespace std;

int main() {
    int n, a, b;
    cin >> n >> a >> b;
    cout << min(a,b) << " " << max(0, a+b-n) << endl;
    return 0;
}


Measured memory_bytes: 504
#include <bits/stdc++.h>
using namespace std;
int n,l;

int main() {
  cin >>n>>l;
  vector<string> s(n);
  for (int i=0;i<n;i++) cin >> s.at(i);
  
  sort(s.begin(),s.end());
  
  for (int i=0;i<n;i++) cout <<s.at(i);
  cout << endl;
}

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

int main() {
  int s = 0, n, N;
  cin >> n; N = n;
  while (n > 0) {
    s += n % 10;
    n /= 10;
  }
  cout << ((N%s==0)?"Yes":"No") << endl;
  return 0;
}

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

int main() {

  string N;
  cin >> N;

  if(N[0] == '7' || N[1] == '7' || N[2] == '7'){
    cout << "Yes" << endl;
  }else{
    cout << "No" << endl;
  }
}


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

typedef pair<int,int> P;

const int M = 1e9;
  
int h, w, n;
unordered_set<int> black, used;
int ans[10], C;

void check(P point){
  
  for(int i=-2;i<=2;i++){
    
    for(int j=-2;j<=2;j++){
      
      int y1 = point.first + i;
      int x1 = point.second + j;
      int y2 = y1 + 2;
      int x2 = x1 + 2;
      
      if( y1 < 0 || x1 < 0 || h <= y1 || w <= x1 ) continue;
      
      if( y2 < 0 || x2 < 0 || h <= y2 || w <= x2 ) continue;
      
      if( used.count( y1 * M + x1 ) ) continue;
      
      used.insert( y1 * M + x1 );
      
      int cnt = 0;
      
      for(int k=y1;k<=y2;k++){
	
	for(int l=x1;l<=x2;l++){
	  
	  if( black.count( k * M + l ) ) cnt++;
	  
	}
	
      }
      
      if( cnt == 0 ) continue;
      
      ans[cnt]++;
      
      C++;
      
    }
    
  }
  
}

int a[100005], b[100005];

signed main(){
  
  cin>>h>>w>>n;
  
  for(int i=0;i<n;i++){
    
    cin>>a[i]>>b[i];
    
    black.insert( (a[i]-1) * M + b[i]-1 );
    
  }
  
  for(int i=0;i<n;i++){
    
    check( P( a[i] - 1, b[i] - 1 ) );
    
  }
  
  cout<<(h-2)*(w-2)-C<<endl;
  
  for(int i=1;i<10;i++) cout<<ans[i]<<endl;
  
  return 0;
}


Measured memory_bytes: 123728
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n,k;
    cin>>n>>k;
    long long h[n],cost[n];
    cost[0]=0;cost[1]=abs(h[1]-h[0]);
    for(int i=2;i<n;i++)
    cost[i]=1000000000;
    for(int i=0;i<n;i++)
    cin>>h[i];
    cost[0]=0;cost[1]=abs(h[1]-h[0]);
    int step;long long tmp;
    for(int i=2;i<n;i++)
    {
        step=1;
        while(true)
        {
            tmp=abs(h[i]-h[i-step])+cost[i-step];
            cost[i]=min(tmp,cost[i]);
            step++;
            if((step>k)||(i-step<0))
            break;
        }
    }
    cout<<cost[n-1]<<endl;
    return 0;
}

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

 int main() {
int N,M,p;
cin>>N>>M>>p;
int d[10001];
d[0]=p;

for (int i = 1; i <= M; i++) {
  cin>>d[i];
}
sort(d,d+M+1);
int c_min =N-1;
for (int i = 0; i < M+1; i++) {
  int q =d[i];
  int r1 =d[(i-1+M+1)%(M+1)];
  int r2 =d[(i+1)%(M+1)];

  int c1 =((p-q+N)%N)*2+(r1-p+N)%N;
  int c2 =((q-p+N)%N)*2+(p-r2+N)%N;

c_min =min(c_min,min(c1,c2));

}
cout <<c_min*100 << endl;
  return 0;
}

Measured memory_bytes: 3116
//#pragma GCC optimize("Ofast")
//#pragma GCC target("avx2,tune=native")
//#pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define pb push_back
using namespace std;
using ll = long long;
using ld = long double;
using vi = vector<ll>;
using vvi = vector<vi>;
using pi = pair<ll, ll>;
const ll mod = 1e9 + 7;

int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	ll n, m, l;
	string s, t;
	cin >> n >> m >> s >> t;
	l = n*(m/__gcd(n, m));
	int i = 0, j = 0, x=0, y=0;
	for(; x < n && y < m;) {
		if(i==j&&s[x]!=t[y]) return cout << -1, 0;
		if(i < j)
			i += l/n, x++;
		else
			j += l/m, y++;
	}
	cout << l << "\n";
}


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

int main(){
  int a,b,c,v;
  cin >> a >> b >> c;
  if(a+b<c){
    v=b+c-(c-a-b)+1;
  }else{
    v=b+c;
  }
  cout << v << endl;
}


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

typedef int Weight;
struct Edge {  
  int src, dst;
  Weight weight;
  Edge(int src, int dst, Weight weight) :
    src(src), dst(dst), weight(weight) { }
};
bool operator < (const Edge &e, const Edge &f) {
  return e.weight != f.weight ? e.weight > f.weight : 
    (e.src != f.src ? e.src < f.src : e.dst < f.dst);
}
typedef vector<Edge> Edges;
typedef vector<Edges> Graph;

pair<Weight, Edges> prim(const Graph &g, int r = 0) {
  int n = g.size();
  Edges T;
  Weight total = 0;
  vector<bool> visited(n);
  priority_queue<Edge> Q;
  Q.push( Edge(-1, r, 0) );    
  while (!Q.empty()) {
    Edge e = Q.top(); Q.pop();
    if (visited[e.dst]) continue;
    T.push_back(e);
    total += e.weight;
    visited[e.dst] = true;
    for(auto f : g[e.dst]){
        if(!visited[f.dst]) Q.push(f);
    }
  }
  T.erase(T.begin());
  return pair<Weight, Edges>(total, T);
}

int main(){
    while(1){
        int n, m; cin >> n >> m;
        if(n==0) break;
        Graph g(n);
        int a, b, cost;
        for(int i=0; i<m; i++){
            cin >> a >> b >> cost;
            g[a].push_back(Edge(a, b, cost));
            g[b].push_back(Edge(b, a, cost));
        }

        cout << prim(g).first << endl;
    }
}


Measured memory_bytes: 3104
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <time.h>
#include <tuple>
#include <utility>
#include <vector>
#define ll long long
#define itn int
#define endl '\n'
#define co(ans) cout<<ans<<endl
#define COYE cout<<"YES"<<endl
#define COYe cout<<"Yes"<<endl
#define COye cout<<"yes"<<endl
#define CONO cout<<"NO"<<endl
#define CONo cout<<"No"<<endl
#define COno cout<<"no"<<endl
#define FORE(i,a) for(auto &i:a)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define FFOR(i,a,b) for(int i=(a);i<=(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define RREP(i,n)  FFOR(i,1,n)
#define PB push_back
#define MP make_pair
#define ALL(V) (V).begin(),(V).end()
#define SORT(V) sort((V).begin(),(V).end())
#define REVERSE(V) reverse((V).begin(),(V).end())
#define EACH(V,i) for(typeof((V).begin()) i=(V).begin();i!=(V).end();++i)
#define equals(a,b) (fabs((a)-(b))<EPS)
#define INF ((1LL<<62)-(1LL<<31))
#define EPS 1e-10
#define PI 3.141592653589793238
#define MOD 1000000007
#define MMOD 998244353
#define MAX 2010101
using namespace std;
using Edge=pair<ll,ll>;
using Graph=vector<vector<int>>;
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>bool chmax(T &a,const T &b){if(a<b){a=b;return 1;}return 0;}
template<class T>bool chmin(T &a,const T &b){if(b<a){a=b;return 1;}return 0;}
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;
const int dx[4]={0,1,0,-1},dy[4]={1,0,-1,0};
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(){
  ll N,C;
  cin>>N>>C;
  ll A[N+1],B[N+1];
  RREP(i,N) cin>>A[i];
  RREP(i,N) cin>>B[i];
  
  ll DP[N+1][C+1];
  REP(i,N+1) REP(j,C+1) DP[i][j]=0;
  DP[0][0]=1;
  
  ll POW[500][500]; // POW[i][j]=i^j
  REP(i,500) POW[i][0]=1;
  RREP(i,400){
    RREP(j,400){
      POW[i][j]=POW[i][j-1]*i%MOD;
    }
  }
  
  ll SUM[500][500]; // SUM[i][j]=Σx^j(1<=x<=i);
  REP(i,500) SUM[i][0]=i;
  RREP(j,400){
    RREP(i,400){
      SUM[i][j]+=SUM[i-1][j]+POW[i][j];
      SUM[i][j]%=MOD;
    }
  }
  
  
  RREP(i,N){
    REP(j,C+1){
      REP(k,j+1){
        DP[i][j]+=DP[i-1][j-k]*(SUM[B[i]][k]-SUM[A[i]-1][k]);
        DP[i][j]%=MOD;
      }
    }
  }
  
  ll ans=DP[N][C];
  ans=(ans%MOD+MOD)%MOD;
  cout<<ans<<endl;
  return 0;
}

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

#define all(container) container.begin(), container.end()
#define sortall(container) (sort(container.begin(), container.end()))
#define yn(cond) ((cond) ? (cout << "yes" << endl) : (cout << "no" << endl))
#define Yn(cond) ((cond) ? (cout << "Yes" << endl) : (cout << "No" << endl))
#define YN(cond) ((cond) ? (cout << "YES" << endl) : (cout << "NO" << endl))

typedef long long       ll;

typedef vector<int>     vi;
typedef vector<ll>      vll;
typedef vector<double>  vd;
typedef vector<bool>    vb;
typedef vector<char>    vc;
typedef vector<string>  vs;
typedef pair<int, int>  pii;
typedef pair<ll, ll>    pll;
typedef vector<vi>		vvi;
typedef vector<vll>		vvll;
typedef vector<vd>		vvd;
typedef vector<vb>		vvb;
typedef vector<vc>		vvc;
typedef vector<vs>		vvs;
typedef vector<pii>     vpii;
typedef vector<pll>     vpll;

typedef struct edge_ {
	ll to;
	ll cost;
} edge;

typedef struct point_ {
	ll x, y;
	point_(ll x = 0, ll y = 0) : x(x), y(y) {}
} point;

template <typename T>
using mat2d = vector<vector<T>>;

constexpr double	PI = 3.14159265358979323846;
constexpr ll		INF = 1 << 15;
constexpr ll		MOD = (ll)1e9 + 7;
constexpr double	EPS = 1e-7;
constexpr int		dy4[4] = { 0, 1, 0, -1 };
constexpr int		dx4[4] = { 1, 0, -1, 0 };
constexpr int		dy8[8] = { 0, 1, 1, 1, 0, -1, -1, -1 };
constexpr int		dx8[8] = { 1, 1, 0, -1, -1, -1, 0, 1 };

template<typename T>
istream& operator >> (istream& is, vector<T>& vec) {
	for (T& x : vec) is >> x;
	return is;
}

template<typename T>
ostream& operator << (ostream& os, const vector<T>& vec) {
	for (const T& x : vec) os << x << " ";
	return os;
}

template<typename S, typename T>
istream& operator >> (istream& is, pair<S, T>& p) {
	is >> p.first >> p.second;
	return is;
}

istream& operator >> (istream& is, point& p) {
	is >> p.x >> p.y;
	return is;
}

template<typename S, typename T>
ostream& operator << (ostream& os, const pair<S, T>& p) {
	os << "{" << p.first << " : " << p.second << "}";
	return os;
}

template<typename T>
ostream& operator << (ostream& os, const set<T>& s) {
	for (const T& x : s) os << x << " ";
	return os;
}

ostream& operator << (ostream& os, const edge e) {
	os << "{to: " << e.to << ", cost: " << e.cost << "}";
	return os;
}

ostream& operator << (ostream& os, const point& p) {
	os << "(" << p.x << " " << p.y << ")";
	return os;
}

/******************************************************************************/
/**********************         Don't make WA !!         **********************/
/******************************************************************************/

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

	ll mi = A * (N - 1) + B;
	ll ma = A + B * (N - 1);

	cout << max(ma - mi + 1, 0LL) << endl;
	
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, a, n) for(int i = a; i < n; i++)
#define int long long
using namespace std;
typedef pair<int, int> P;
const int mod = 1000000007;
const int INF = 1e18;

signed main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    vector<int> a(n);
    rep(i, 0, n){
        cin >> a[i];
    }
    vector<int> b(60);
    rep(i, 0, n){
        rep(j, 0, 60){
            if(a[i] & (1LL << j)){
                b[j]++;
            }
        }
    }
    int ans = 0;
    rep(i, 0, 60){
        ans += (1LL << i) % mod * ((b[i] * (n - b[i])) % mod) % mod;
        ans %= mod;
    }
    cout << ans % mod << endl;
}


Measured memory_bytes: 2560
#include<bits/stdc++.h>
typedef long long ll;
#define INF 100000000
#define MOD 100000007
int dx[4]={1,0,-1,0},dy[4]={0,-1,0,1};
using namespace std;
int main(void){
    int n;
    cin>>n;
    ll a[n],b[n];
    vector<ll>diff;
    ll sum=0;
    for(int i=0;i<n;i++){
        cin>>a[i];
        sum+=a[i];
    }
    ll minus=0;
    int cnt=0;
    for(int i=0;i<n;i++){
        cin>>b[i];
        if(a[i]>b[i]){
            diff.push_back(a[i]-b[i]);
        }else if(b[i]>a[i]){
            cnt++;
            minus+=(b[i]-a[i]);
        }
        sum-=b[i];
    }

    sort(diff.begin(),diff.end());
    if(sum<0){
        cnt=-1;
    }else{
        int r=diff.size()-1;
        while(minus>0){
            minus-=diff[r];
            r--;
            cnt++;
        }
    }
    cout<<cnt<<endl;
   return 0;
}

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

int main()
{
    long long int n, b;
    cin >> n;
    long long int cnt = 0;
    long long int a = 100;
    while (1) {
        if (n <= a) {
            cout << cnt << endl;
            break;
        }
        cnt++;
        b = a * 0.01;
        a = a + b;
    }
}


Measured memory_bytes: 3632
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
	ios_base::sync_with_stdio(0); 
    cin.tie(0);   
	ll n,a[200009],m,k,ans=0,fl=0;
	string s;
	cin>>n>>m>>k;
	n=abs(n);
	ll temp=n/k;
	if(temp>m)
	{
		cout<<n-(m*k)<<endl;
	}
	else
	{
		if((temp%2==0 && m%2==0) || (temp%2==1 && m%2==1))
			cout<<n%k<<endl;
		else
			cout<<k-(n%k)<<endl;
	}
	return 0;
}

Measured memory_bytes: 3588
package main
 
import (
    "bufio"
    "fmt"
    "os"
    "strconv"
)

func main(){
    
    N := nextInt()
    abc := make([][]int, N)
    for i:=0;i<N;i++ {
        abci := nextInts(3)
        abc[i] = abci
    }
    
    dp := make([][]int, N)
    for i:=0;i<N;i++ {
        dp[i] = make([]int, 3)
    }
    dp[0][0] = abc[0][0]
    dp[0][1] = abc[0][1]
    dp[0][2] = abc[0][2]
    for i:=1;i<N;i++ {
        for j:=0;j<3;j++ {
            for k:=0;k<3;k++ {
                if j==k {
                    continue
                }
                dp[i][j] = Max([]int{dp[i][j], abc[i][j] + dp[i - 1][k]});
            }
        }
    }
    
	fmt.Println(Max([]int{dp[N-1][0], dp[N-1][1], dp[N-1][2]}) )
}

/* templates */


func Max(a []int) int {
    r := a[0]
    for i := 0; i < len(a); i++ {
        if r < a[i] {
            r = a[i]
        }
    }
    return r
}
 
func Min(a []int) int {
    r := a[0]
    for i := 0; i < len(a); i++ {
        if r > a[i] {
            r = a[i]
        }
    }
    return r
}
 
func Sum(a []int) (r int) {
    for i := range a {
        r += a[i]
    }
    return r
}
 
func Abs(a int) int {
    if a < 0 {
        return -a
    }
    return a
}
 
type Pair struct {
    a, b int
}
 
type Pairs []Pair
 
func (p Pairs) Len() int {
    return len(p)
}
 
func (p Pairs) Swap(i, j int) {
    p[i], p[j] = p[j], p[i]
}
 
func (p Pairs) Less(i, j int) bool {
    return p[i].b < p[j].b
}
 
var nextReader func() string
 
func init() {
    nextReader = NewScanner()
}
 
func NewScanner() func() string {
    r := bufio.NewScanner(os.Stdin)
    r.Buffer(make([]byte, 1024), int(1e+11))
    r.Split(bufio.ScanWords)
    return func() string {
        r.Scan()
        return r.Text()
    }
}

func nextString() string {
    return nextReader()
}
 
func nextInt64() int64 {
    v, _ := strconv.ParseInt(nextReader(), 10, 64)
    return v
}
 
func nextInt() int {
    v, _ := strconv.Atoi(nextReader())
    return v
}
 
func nextInts(n int) []int {
    r := make([]int, n)
    for i := 0; i < n; i++ {
        r[i] = nextInt()
    }
    return r
}

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

func nextFloat64() float64 {
    f, _ := strconv.ParseFloat(nextReader(), 64)
    return f
}


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

#define K 100000

int dp[K+1];

int main(void){
  int a[100];
  int n,k;
  
  cin >> n >> k;
  for (int i=0; i<n; i++) cin >> a[i];
  dp[0] = 0;
  for (int i=1; i<=k; i++){
    dp[i] = 0;
    for (int j=0; j<n; j++){
      if (i-a[j]>=0){
        dp[i] |= !dp[i-a[j]];
      }
    }
//    cout << i << ": " << dp[i] << endl;
  }
  cout << (dp[k]?"First":"Second") << endl;
  return 0;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
int main() {
	string s;
	cin >> s;
	
	sort(s.begin(), s.end());
	if((s[0] == s[1] && s[2] == s[3]) && (s[0] != s[2])) cout << "Yes";
	else cout << "No";
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<ctype.h>
#include<cstring>
using namespace std;
inline int read(){
	int x=0,f=0;char ch=getchar();
	while(!isdigit(ch))f|=ch=='-',ch=getchar();
	while(isdigit(ch))x=x*10+(ch^48),ch=getchar();
	return f?-x:x;
}
char c[100007];
int main(){
	scanf("%s",c);int l=strlen(c),g=0;
	for(int i=0;i<l;++i)if(c[i]=='g')g++;
	printf("%d\n",min(l/2,g)-min(l-l/2,l-g));
    return 0;
}

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

int main()
{
    int a, b, ans;
    cin >> a >> b;
    if (a <= 5)
    {
        ans = 0;
    }
    else if (a <= 12)
    {
        ans = b / 2;
    }
    else
    {
        ans = b;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<stdio.h>
using namespace std;
typedef long long ll;
int main()
{
	int n,m;
	while(scanf("%d%d",&n,&m)!=EOF&&n!=0)
	{
		int  f[1500]={0};
		bool flag=false;
		for(int i=0;i<n;i++)
		scanf("%d",&f[i]);
		sort(f,f+n);
		int l=0,r,ans=0;
		for(int i=0;i<n;i++)
		{
			int s=m-f[i];
			int j=upper_bound(f,f+n,s)-f;
			j--;
			if(j==i)
			j--;
			if(j>=0&&j<n&&(f[i]+f[j]<=m))
			{
				flag=true;
				ans=max(ans,f[i]+f[j]);
			}
		} 
		if(flag)
		printf("%d\n",ans);
		else
		printf("NONE\n");
	}
	return 0;
}


Measured memory_bytes: 3244
#!/usr/bin/env python3
# sys.stdin.readline()

import sys
import numpy as np
input = sys.stdin.readline
#n = int(input())
#n,k = map(int,input().split())
#A = list(map(int,input().split()))
#s=input()
#a = input()
n,m,x = map(int,input().split())
A = np.array([list(map(int,input().split())) for _ in range(n)])
ans = 10**8
for i in range(1,2 ** n):
    bag = np.array([])
    total = 0
    for j in range(n):  # このループが一番のポイント
        if ((i >> j) & 1):  # 順に右にシフトさせ最下位bitのチェックを行う
              # フラグが立っていたら bag に果物を詰める
            total += A[j]
            
              # 買い物累計額にも加算

    if x <= min(list(total[1::])):
        ans = min(ans , total[0])

if ans !=10**8:
    print(ans)
else:
    print(-1)

Measured memory_bytes: 27232
line = input().split(" ")
n = int(line[0])
m = int(line[1])
a = []
b = []

for i in range(n):
    a.append(input())
for i in range(m):
    b.append(input())

for nh in range(n-m+1):
    for nw in range(n-m+1):
        for k in range(m):
            s1 = a[nh+k][nw : nw+m]
            s2 = b[k]
            if s1 != s2:
                break
        else:
            print("Yes")
            exit()

print("No")


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

using namespace std;



vector<int> primVec(int N){
	vector<int> res, vec;
	vec= vector<int>(N+1,1);
	for(int i=2; i<N+1; i++){
		if(vec.at(i)==1){
			for(int j = 0; i*(j+2)<N+1; j++){
				vec.at(i*(j+2))=0;
			}
		}
	}
	for(int i=2; i<N+1; i++){
		if(vec.at(i)==1) res.push_back(i);
	}
	return res;
}



int main(){
	int N;
	cin >> N;
	
	vector<int> vec = primVec(55555);
	vector<int> res;
	
	for(int i=0; i<1000 && (int)res.size()<N; i++){
		if(vec.at(i)%5 == 2) res.push_back(vec.at(i));
	}
	
	for(int i=0; i<N; i++){
		cout << res.at(i) << " " ;
	}
	cout << endl;
	
	
}




Measured memory_bytes: 512
#include <algorithm>
#include <iostream>
#include <limits>
#include <numeric>
#include <vector>
#include <set>

#define rep(i, x, n) for(int i = x; i < n; i++)
using namespace std;
const long long INF = 1LL << 60;
bool compare_by_b(pair<int, long long> a, pair<int, long long> b) {
    if(a.second != b.second) {
        return a.second > b.second;
    } else {
        return a.first > b.first;
    }
}

using type = pair<int, long long>; // 1: query, 0: delete, -1: insert
using event = pair<long long, type>;

int main() {
    int N,Q;
    cin>>N>>Q;
    vector<event> v;
    rep(i,0,N){
        int s,t,x;
        cin>>s>>t>>x;
        v.push_back({s-x,type(-1,x)});
        v.push_back({t-x,type(0,x)});
    }
    rep(i,0,Q){
        int d;
        cin>>d;
        v.push_back({d,type(1,i)});
    }
    sort(v.begin(),v.end());
    vector<long long> res(Q);
    multiset<long long> se;
    for(auto p:v){
        long long x=p.first;
           int type =p.second.first;
        long long val =p.second.second;
        if(type==-1){
            se.insert(val);
        }else if(type==0){
            se.erase(se.lower_bound(val));
        }else{
            if(se.empty()){res[val]=-1;}else{
res[val]=*(se.begin());
            }
        }

    }
    for(auto v:res)cout<<v<<endl;

}

Measured memory_bytes: 28132
#include <bits/stdc++.h>
using namespace std;
#define rep(i,N) for(int i = 0; i < (N); i++)
#define repo(i,N) for(int i = 1; i < (N); i++)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define all(x) (x).begin(),(x).end()
//#define num 1000000007
#define pi acos(-1.0)
//intの最大値2147483647 ≒ 2×10^9
//long longの最大値9223372036854775807 ≒ 9×10^18
//#define int long long


int main() {
  int N;
  cin >> N;
   
  vector<tuple<string, int, int>> p(N);
  
  
  rep(i, N) {
  string a;
  int b;
  cin >> a >> b;
  p.at(i) = make_tuple(a, -b, i+1);
  }
  
  sort(all(p));
  
  rep(i, N) {
  cout << get<2>(p.at(i)) << endl;
  }
  
  
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <stdio.h>
#include <vector>
#include <map>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
#define F first
#define S second
#define PB push_back
#define INF 2000000
ll n,L,br[200005],brd[200005],x[200005],y[200005],ans;
P sgx[1<<20],sgy[1<<20];
vector<ll>cm;
map<ll,ll>pr;
void upx(ll a,ll p){
    a+=(1LL<<19)-1;
    if(sgx[a].F<p)sgx[a].F=p;
    if(sgx[a].S>p)sgx[a].S=p;
    while(a>0){
        a=(a-1)/2;
        sgx[a].F=max(sgx[a*2+1].F,sgx[a*2+2].F);
        sgx[a].S=min(sgx[a*2+1].S,sgx[a*2+2].S);
    }
}
void upy(ll a,ll p){
    a+=(1LL<<19)-1;
    if(sgy[a].F<p)sgy[a].F=p;
    if(sgy[a].S>p)sgy[a].S=p;
    while(a>0){
        a=(a-1)/2;
        sgy[a].F=max(sgy[a*2+1].F,sgy[a*2+2].F);
        sgy[a].S=min(sgy[a*2+1].S,sgy[a*2+2].S);
    }
}
P quex(int a,int b,int l,int r,int k){
    if(r<a||b<l)return P(0,INF);
    if(a<=l&&r<=b)return sgx[k];
    P s=quex(a,b,l,(l+r-1)/2,k*2+1),t=quex(a,b,(l+r+1)/2,r,k*2+2);
    return P(max(s.F,t.F),min(s.S,t.S));
}
P quey(int a,int b,int l,int r,int k){
    if(r<a||b<l)return P(0,INF);
    if(a<=l&&r<=b)return sgy[k];
    P s=quey(a,b,l,(l+r-1)/2,k*2+1),t=quey(a,b,(l+r+1)/2,r,k*2+2);
    return P(max(s.F,t.F),min(s.S,t.S));
}
int main(void){
    scanf("%lld%lld",&n,&L);
    for(int i=0;i<n;i++){
        scanf("%lld%lld%lld",x+i,y+i,br+i);
        brd[i]=br[i]+L;
        cm.PB(br[i]);
        cm.PB(brd[i]);
    }
    sort(cm.begin(),cm.end());
    cm.erase(unique(cm.begin(),cm.end()),cm.end());
    for(int i=0;i<cm.size();i++)pr[cm[i]]=i;
    for(int i=0;i<1<<20;i++){
        sgx[i]=P(0,INF);
        sgy[i]=P(0,INF);
    }
    for(int i=0;i<n;i++){
        br[i]=pr[br[i]];
        brd[i]=pr[brd[i]];
        upx(br[i],x[i]);
        upy(br[i],y[i]);
    }
    for(int i=0;i<n;i++){
        P s=quex(br[i],brd[i],0,(1<<19)-1,0),t=quey(br[i],brd[i],0,(1<<19)-1,0);
        ans=max(ans,(s.F-s.S)*(t.F-t.S));
    }
    printf("%lld\n",ans);
}



Measured memory_bytes: 69988
import java.util.Arrays;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);

		int N = sc.nextInt();
		int[]d = new int[N];

		for (int i=0; i<N; i++) {
			d[i] = sc.nextInt();
		}

		Arrays.sort(d);
		System.out.println(d[N/2] - d[(N/2) -1]  );
	}


}

Measured memory_bytes: 50808
seq = input()
if seq == seq[::-1]:
    if seq[:int((len(seq) - 1) / 2)] == seq[:int((len(seq) - 1) / 2)][::-1]:
        if seq[int((len(seq) + 3) / 2) - 1:] == seq[int((len(seq) + 3) / 2) - 1:][::-1]:
            # print(seq[int((len(seq) + 3) / 2) - 1:])
            print("Yes")
        else:
            print("No")
    else:
        print("No")
else:
    print("No")

Measured memory_bytes: 3064
NUM = input().rstrip().split(' ')

NUM.sort(key=int,reverse=False)

if int(NUM[0]) == 5:
        if int(NUM[1]) == 5:
            if int(NUM[2]) == 7:
                print("YES")
            else:
                print("NO")
        else:
            print("NO")
else:
        print("NO")




Measured memory_bytes: 2940
#include<iostream>
#include<vector>
#include<algorithm>
#include<tuple>
#include<string>
#define rep(i,n) for (int i=0; i<n; i++)
using namespace std;
int main() {
  int n,k;
  cin >> n >> k;
  int ans = n%k;
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <math.h>
#include <vector>
using namespace std;

int main(){
    string s;
    cin >> s;
    long long int i = 0, j, ans = 0;
    j = s.length() - 1;
    while(true){
        if(i >= j){
            break;
        }
        if(s[i] == s[j]){
            i++;
            j--;
        }
        else{
            if(s[i] == 'x'){
                ans++;
                i++;
            }
            else if(s[j] == 'x'){
                ans++;
                j--;
            }
            else{
                cout << -1 << endl;
                return 0;
            }
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 512
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
using namespace std;
char s[101][101];
int a[26];
int H,W;
int f(int v){
  for(int i=0;i<26;i++){
    if(a[i]>=v){
      a[i]-=v;
      return 1;
    }
  }
  return 0;
}
int main(){
  scanf("%d %d",&H,&W);
  for(int i=0;i<H;i++)scanf("%s",&s[i]);
  for(int i=0;i<H;i++){
    for(int j=0;j<W;j++){
      a[s[i][j]-'a']++;
    }
  }
  for(int i=0;i<H/2;i++){
    for(int j=0;j<W/2;j++){
      if(!f(4)){
	printf("No\n");
	return 0;
      }
    }
  }

  if(H%2==1){
    for(int i=0;i<W/2;i++){
      if(!f(2)){
	printf("No\n");
	return 0;
      }
    }
  }

  if(W%2==1){
    for(int i=0;i<H/2;i++){
      if(!f(2)){
	printf("No\n");
	return 0;
      }
    }
  }

  if(H%2==1 && W%2==1){
    if(!f(1)){
      printf("No\n");
      return 0;
    }
  }
  printf("Yes\n");
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstring>
#include <string>
#include <algorithm>
#include <queue>
#include <stack>
#include <stdio.h>
#include <cmath>
#include <string.h>
#include <vector>

#define ll long long
using namespace std;

int main()
{
    //freopen("C:\\Users\\23733\\Desktop\\in.txt","r",stdin);
    ll n, m;
    cin >> n >> m;
    if(n > m){
        ll t = n; 
        n = m;
        m = t;
    }
    ll ans;
    if (n == 1)
    {
        if (m == 1)
        {
            ans = 1;
        }else
        {
            ans = m - 2;
        }
    }else
    {
        ans = (n - 2) * (m - 2);
    }
    
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using pint = pair<int, int>;
using ll = long long;
using ull = unsigned long long;
using vll = vector<long long>;
using pll = pair<ll, ll>;
#define FOR(i, begin, end) \
    for (int i = (begin), i##_end_ = (end); i < i##_end_; i++)
#define IFOR(i, begin, end) \
    for (int i = (end)-1, i##_begin_ = (begin); i >= i##_begin_; i--)
#define REP(i, n) FOR(i, 0, n)
#define IREP(i, n) IFOR(i, 0, n)
#define VREP(s, ite) for (auto ite = s.begin(); ite != s.end(); ++ite)
#define FI first
#define SE second
#define ALL(v) v.begin(), v.end()
//#define endl "\n"
#define ciosup  \
    cin.tie(0); \
    ios::sync_with_stdio(false);
#define eb emplace_back
#define vint vector<int>
constexpr ll INF = 1e15 + 7LL;
constexpr ll MOD = 1e9 + 7LL;
template <typename T>
istream &operator>>(istream &is, vector<T> &v) {
    for (int i = 0; i < v.size(); ++i) {
        is >> v[i];
    }
    return is;
}
template <typename T>
ostream &operator<<(ostream &os, const vector<T> &v) {
    for (int i = 0; i < v.size() - 1; ++i) {
        os << v[i] << " ";
    }
    if (v.size() > 0) {
        os << v[v.size() - 1] << endl;
    }
    return os;
}

int main() {
    int a;
    cin>>a;
    cout << a + pow(a, 2) + pow(a, 3) << endl;
}

Measured memory_bytes: 4148
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define REPR(i, n) for(int i = (int)(n); i >= 0; i--)
#define FOR(i, s, n) for (int i = (s); i < (int)(n); i++)
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef unsigned long long ll;
int N, n, M, K;

bool MONTH(int a){
    if(a >0 && a < 13) return true;
    else return false;
}

int main(){
    cin >> N >>K;
    double prob = 0;
    for(int i = 1; i < N+1; ++i){
        double p = 1.0/N, score = 1.0*i;
        while(score < K){
            score *= 2;
            p *= 0.5;
        }
        prob += p; 
    }
    cout << setprecision(12) << prob;
    return 0;
}

Measured memory_bytes: 256