akhauriyash/Code-Regression huggingface dataset:
#include <algorithm>
#include <cassert>
#include <cfloat>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <deque>
#include <iostream>
#include <iterator>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

#define FOR(i,k,n) for(int(i)=(k);(i)<(n);++(i))
#define rep(i,n) FOR(i,0,n)
#define all(v) begin(v),end(v)
#define debug(x) std::cerr<<#x<<": "<<x<<"\n"
#define debug2(x,y) std::cerr<<#x<<": "<<x<<", "<<#y<<": "<<y<<"\n"
#define debug3(x,y,z) std::cerr<<#x<<": "<<x<<", "<<#y<<": "<<y<<", "<<#z<<": "<<z<<"\n"

using ll=long long;
using vi=std::vector<int>;
using vvi=std::vector<vi>;
using vll=std::vector<ll>;
using vvll=std::vector<vll>;
template<typename T> using vvec=std::vector<std::vector<T>>;
template<typename T>
auto make_v(size_t sz){return std::vector<T>(sz);}
template<typename T,typename... Ts>
auto make_v(size_t sz,Ts...ts){return std::vector<decltype(make_v<T>(ts...))>(sz,make_v<T>(ts...));}
template<typename T>
void fill_v(T&var,const T&x){var=x;}
template<typename V,typename T>
void fill_v(V&v,const T&x){for(auto&& w:v){fill_v(w,x);}}

template<typename T> std::ostream& operator<<(std::ostream&s,const std::vector<T>&v){
  int sz=v.size();s<<"\n";rep(i,sz){s<<v[i];if(i<sz-1){s<<"\t";}}s<<"\n";return s;}
template<typename T> std::ostream& operator<<(std::ostream&s,const std::vector<std::vector<T>>&v){
  for(auto&& w:v){s<<w;}return s;}
template<typename T> std::ostream& operator<<(std::ostream&s,const std::deque<T>&v){
  int sz=v.size();s<<"\n";rep(i,sz){s<<v[i];if(i<sz-1){s<<"\t";}}s<<"\n";return s;}
template<typename T> std::ostream& operator<<(std::ostream&s,const std::deque<std::deque<T>>&v){
  for(auto&& w:v){s<<w;}return s;}
template<typename T> std::ostream& operator<<(std::ostream&s, const std::set<T>&v){
  s<<"\n";for(auto&& elm:v){s<<elm<<"\t";}s<<"\n";return s;}

inline void scan(int&a){scanf("%d",&a);}
inline void scan(ll&a){scanf("%lld",&a);}
inline void scan(char&a){scanf(" %c",&a);}
inline void scan(double&a){scanf("%lf",&a);}
template<typename T>
inline void scan(std::vector<T>&v){for(auto&& sv:v){scan(sv);}}
template<typename First,typename...Args>
inline void scan(First&f,Args&...args){scan(f);scan(args...);}
inline void scan(std::string&s){char BUF[3000000];scanf(" %s",BUF);s=std::string(BUF);}
inline void print(int a){printf("%d\n",a);}
inline void print(ll a){printf("%lld\n",a);}
inline void print(double a){printf("%.12f\n",a);}
inline void print(std::string s){std::cout<<s<<"\n";}

using namespace std;

int main() {
  string s; scan(s);
  s[3] = '8';
  print(s);
  return 0;
}


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

int a,b;
char op;

int main()
{
	scanf("%d %c %d",&a,&op,&b);
	if(op=='+')
	{
		printf("%d\n",a+b);
	}
	else
	{
		printf("%d\n",a-b);
	}
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, to) for (int i = 0; i < (to); ++i)
#define repf(i, from, to) for (int i = (from); i < (to); ++i)
#define unless(cond) if (!(cond))
using namespace std;
using ll = long long;
template <typename T>
using V = vector<T>;
template <typename T, typename U>
using P = pair<T, U>;

int main() {
  int a, b, c, x, y;
  cin >> a >> b >> c >> x >> y;

  int min_price = x * a + y * b;
  rep(c_num, max(x * 2, y * 2) + 1) {
    int a_num = max(x - c_num / 2, 0);
    int b_num = max(y - c_num / 2, 0);

    int price = a_num * a + b_num * b + c_num * c;
    min_price = min(price, min_price);
  }

  cout << min_price << endl;
}

Measured memory_bytes: 3540
#include <stdio.h>

int A[100][100];
int color[100],pi[100],d[100];
#define BLACK 1
#define WHITE 0
#define GRAY 2
#define inf 2001

int prim(int n)
{
  int i,u,mincost,w;
  for(i=0;i<n;i++)
    {
      d[i]=inf;
      color[i]=WHITE;
    }
  d[0]=0;
  color[0]=GRAY;
  w=0;

  while(1)
    {
      u=-1;
      mincost=inf;
      for(i=0;i<n;i++)
	{
	  if(color[i]==GRAY && d[i]<mincost)
	    {
	      mincost=d[i];
	      u=i;
	    }
	}
      
      if(u==-1)break;

      color[u]=BLACK;

      w+=d[u];

      for(i=0;i<n;i++)
	{
          if(color[i]!=BLACK && A[u][i]<inf)
	    {
	      color[i]=GRAY;
	      if(d[i]>A[u][i])
		{
		  d[i]=A[u][i];
		}
	    }

	}
    }
  
  return w;
  
}

int main()
{
  int n,i,j,w;
  scanf("%d",&n);
  for(i=0;i<n;i++)
    {
      for(j=0;j<n;j++)
	{
	  scanf("%d",&w);
	  if(w == -1){A[i][j]=inf;}
	  else A[i][j]=w;
	}
    }

  printf("%d\n",prim(n));
  
  return 0;
}

  
  
      
  



Measured memory_bytes: 2108
n=int(input())
h=list(map(int,input().split()))
a=[0]
i=0
c=0
while i<n-1:
  c=0
  while i<n-1:
    if h[i]>=h[i+1]:
      c+=1
      i+=1
    else:
      a.append(c)
      i+=1
      break
a.append(c)
print(max(a))

Measured memory_bytes: 14224
#include<bits/stdc++.h>
#define REP(i,n) for(int i=0;i<(n);++i)
#define ALL(v)   (v).begin(),(v).end()
#define INF      (int)1e9
#define MOD      ((int)1e9+7)
using namespace std;
typedef long long     llong;
typedef pair<int,int> pii;
typedef vector<int>   vi;
typedef vector<vi >   vvi;
typedef vector<vvi >  vvvi;
template<class Type> void join(const Type &a){for(auto elem:a)cout<<elem<<' ';cout<<endl;}

int main(){
	int a,b;
	cin>>a>>b;
	
	int ans=a-b-b;
	
	if(ans<0) cout<<0<<endl;
	else cout<<ans<<endl;
}

Measured memory_bytes: 256
#include<stdio.h>  
#define MAX 100
#define INF 1000000
#define WHITE 0
#define GRAY 1
#define BLACK 2
int n, u;
int M[MAX][MAX];
 
void MST(){
  int i,min,d[MAX],color[MAX]={WHITE};
  for(i = 0;i < n;i++){
    d[i] = INF;
  }
  d[0] = 0;
  color[0] = GRAY;
  while(1){
    min = INF;
    u = -1;
    for(i = 0;i < n;i++)
      if(min > d[i] && color[i] != BLACK){
    u = i;
    min = d[i];
      }
    if(u == -1){
      break;
    }
    color[u] = BLACK;
    for(i = 0;i < n;i++)
      if(color[i] != BLACK && M[u][i] != INF){
    if(d[i] > d[u] + M[u][i]){
      d[i] = d[u] + M[u][i];
      color[i] = GRAY;
    }
      }
  }
  for(i = 0;i < n;i++){
    if(d[i] == INF){
      printf("%d -1\n",i);
    }
    else{
      printf("%d %d\n",i,d[i]);
    }
  }
}
  
int main(){
  int i,j,k,v,c;
  scanf("%d",&n);
  for(i = 0 ;i < n;i++){
    for(j = 0;j < n;j++){
      M[i][j] = INF;
    }
  }
  for(i = 0;i < n;i++){
    scanf("%d %d",&u,&k);
    for(j = 0;j < k;j++){
      scanf("%d %d",&v,&c);
      M[u][v] = c;
    }
  }
  MST();
  return 0;
}

Measured memory_bytes: 636
#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
#include <queue>
#include <array>
#include <set>
#include <unordered_set>
#include <unordered_map>
#include <cmath>
#include <algorithm>
#include <numeric>
#include <cassert>
#include <utility>
#include <functional>

using namespace std;
using lli = long long int;

int main() {

    double N, T, A;
    cin >> N >> T >> A;

    vector<double > temps(N);
    for (int i = 0; i < N; ++i) {
        int h;
        cin >> h;
        double average =  T - h * 0.006;
        double distance = abs(A - average);
        temps[i] = distance;
    }

    unsigned long minElementIndex = min_element(temps.begin(),temps.end()) - temps.begin();
    cout << minElementIndex + 1 << endl;
}

Measured memory_bytes: 256
package main

import "fmt"

func main() {
	var n int
	fmt.Scan(&n)
	b := make([]int, n)
	a := make([]int, n)
	for i := 0; i < len(b)-1; i++ {
		fmt.Scan(&b[i])
	}
	b[n-1] = 10000000
	// fmt.Println("n", n, "b", b, "a", a)
	// a[len(a)-1] = b[len(b)-1]
	ans := 0
	for i := len(a) - 1; i >= 0; i-- {
		//fmt.Printf("before - i %d\n", i)
		if i > 0 {
			a[i] = min(b[i], b[i-1])
		} else {
			//a[i] = a[i+1]
			a[i] = b[i]
		}
		ans += a[i]
		// fmt.Printf("after  - i %d, a %v, ans %d\n", i, a, ans)
	}
	fmt.Println(ans)
}
func min(a, b int) int {
	if a >= b {
		return b
	}
	return a
}


Measured memory_bytes: 512
#include <iostream>
#include <algorithm>
#include <string>
#include <fstream>
#include <vector>
#include <cstdio>
#include <cmath>
#include <queue>
#include <stack>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <string>
#include <set>
#include <map>
using namespace std;
typedef long long ll;

// #define DEBUG

class Point;
Point pointprojection(Point a, Point b, Point c);
Point pointreflection(Point a, Point b, Point c);
class Point
{
    double x;
    double y;

public:
    void printpoint();
    double norm();
    friend Point operator+(Point a, Point b);
    friend double operator*(Point a, Point b);
    friend Point operator*(double a, Point b);
    friend Point operator*(Point a, double b);
    friend Point operator/(Point a, double b);
    friend Point operator-(Point a, Point b);
    double dot(Point b);
    Point(double a, double b)
    {
        x = a;
        y = b;
    }
    double get_x() { return x; }
    double get_y() { return y; }
};

void Point::printpoint()
{
    printf("%.8f  %.8f\n", x, y);
}

double Point::norm()
{
    return sqrt(x * x + y * y);
}

Point operator+(Point a, Point b)
{
    return Point(a.x + b.x, a.y + b.y);
}

double operator*(Point a, Point b)
{
    return double(a.y * b.x - a.x * b.y);
}
Point operator*(double a, Point b)
{
    return Point(a * b.get_x(), a * b.get_y());
}
Point operator*(Point a, double b)
{
    return Point(a.get_x() * b, a.get_y() * b);
}
Point operator/(Point a, double b)
{
    return Point(a.get_x() / b, a.get_y() / b);
}
Point operator-(Point a, Point b)
{
    return Point(a.x - b.x, a.y - b.y);
}

double Point::dot(Point b)
{
    return x * b.x + y * b.y;
}

void printarray(int n, int a[])
{
    for (int i = 1; i < n + 1; i++)
    {
        cout << a[i];
        if (i != n)
            cout << " ";
    }
    cout << endl;
}

Point pointprojection(Point a, Point b, Point c)
{
    Point v1 = b - a;
    Point v2 = c - a;
    Point d = v1 * (v1.dot(v2) / (v1.norm() * v1.norm())) + a;
    return d;
}

Point pointreflection(Point a, Point b, Point c)
{
    Point d = pointprojection(a, b, c);
    Point e = 2 * d - c;
    return e;
}

int main()
{

#ifdef DEBUG
    cout << "DEBUG MODE" << endl;
    ifstream in("input.txt"); //for debug
    cin.rdbuf(in.rdbuf());    //for debug
#endif

    double a, b, c, d, e, f, q;
    cin >> a >> b >> c >> d;
    Point p1(a, b);
    Point p2(c, d);
    cin >> q;
    for (int i = 0; i < q; i++)
    {
        cin >> e >> f;
        Point p3(e, f);
        Point p5 = pointreflection(p1, p2, p3);
        p5.printpoint();
    }
    return 0;
}

// getline(cin,s);
// a = strtok(s, ",");  ","で分解
// for (int i = 0; i < n; i++)


Measured memory_bytes: 3296
#include <bits/stdc++.h>
using namespace std;
int main(){
  int N;
  cin>>N;
 string S;
  cin>>S;
  int x=0;

  vector<int> b(N);
  for(int i=0;i<N;i++){
    if(S.at(i)=='I'){
      x++;

      b.at(i)=x;
    }
    else{
      x--;
 
    b.at(i)=x;   
  }
  }

  sort(b.begin(),b.end());
  cout<<max(0,b.at(N-1))<<endl;

 
}

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

int main(){
    int n, l;
    string m;
    cin >> n;
    int a[4][13];
    for (int i = 0; i < 4; i++) {
        for (int j = 0; j < 13; j++) {
            a[i][j] = 0;
        }
    }
    for (int i = 0; i < n; i++) {
        cin >> m >> l;
        if (m == "S") {
            a[0][l - 1] = 1;
        } else if (m == "H") {
            a[1][l - 1] = 1;
        } else if (m == "C") {
            a[2][l - 1] = 1;
        } else {
            a[3][l - 1] = 1;
        }
    }
    for (int i = 0; i < 13; i++) {
        if (a[0][i] != 1) {
            cout << "S " << i + 1 << endl;
        }
    }
    for (int i = 0; i < 13; i++) {
        if (a[1][i] != 1) {
            cout << "H " << i + 1 << endl;
        }
    }
    for (int i = 0; i < 13; i++) {
        if (a[2][i] != 1) {
            cout << "C " << i + 1 << endl;
        }
    }
    for (int i = 0; i < 13; i++) {
        if (a[3][i] != 1) {
            cout << "D " << i + 1 << endl;
        }
    }
    return 0;
}


Measured memory_bytes: 3144
#include<stdio.h>

int main(void){
    int n;
    scanf("%d", &n);
    int x, order[n];
    for(int i = 0; i < n; i++){
        scanf("%d", &x);
        order[x - 1] = i + 1;
    }
    for(int i = 0; i < n; i++){
        printf("%d ", order[i]);
    }
    printf("\n");
    return 0;
    
}

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


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

def main():
    n, m, q = map(int, input().split())

    # Two-dimensional Cumulative Sum
    cs = [[0] * (n+1) for _ in range(n+1)]

    for _ in range(m):
        l, r = map(int, input().split())
        cs[l][r] += 1

    for l in range(1, n+1):
        for r in range(1, n+1):
            cs[l][r] += cs[l][r-1]
        for r in range(1, n+1):
            cs[l][r] += cs[l-1][r]

    ans = [-1] * q
    for lap in range(q):
        l, r = map(int, input().split())
        ans[lap] = cs[n][r] - cs[l-1][r]

    for i in ans:
        print(i)

main()

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

#define pb push_back
using namespace std;

using ll = long long;

constexpr int N = 200111;

int n, arr[N], t;

int main(){
    cin >> t;
    cout << fixed << setprecision(20);
    cout << 2.0 * t * (22.0 / 7.0) << endl;
}

Measured memory_bytes: 3752
#include <iostream>
#include <cmath>
#include <string>
#include <numeric>
#include <algorithm>
#include <iomanip>
#include <queue>
using namespace std;
#define INF 1000000007
#define ll long long
#define rep(i_, __start, __end) for(ll i_=(ll)__start; i_<(ll)__end; i_++)
#define print(_a) cout << _a << endl;
#define printarray(a, len) rep(ii,0,len) cout << a[ii] << " ";
#define printarray2(aa, len) rep(ij,0,len) printarray(aa[ij], aa[ij].size()); print("");

vector<ll> tree[100010];
ll node[100010] = {};
ll n, a, b;
ll max_color = 0;

void make_tree(ll parent, ll now, ll used_color){
  ll color = 1;
  for(ll i=0; i<tree[now].size(); i+=2){
    if(tree[now][i] != parent){
      if(color == used_color) color++;
      node[tree[now][i+1]] = color;
      make_tree(now, tree[now][i], color);
      color++;
    }
  }
}

int main(){
    
    cin >> n;
    rep(i, 0, n-1){
      cin >> a >> b;
      tree[a].push_back(b);
      tree[a].push_back(i);
      tree[b].push_back(a);
      tree[b].push_back(i);
    }

    rep(i, 0, n){
      if(tree[i].size()/2 > max_color){
        max_color = tree[i].size()/2;
      }
    }
    print(max_color);

    make_tree(0, 1, 0);

    rep(i, 0, n-1){
      print(node[i]);
    }
  
  return 0;
}

Measured memory_bytes: 10752
import sys
x,y=map(int,input().split())
if y%2:
  print('No')
  sys.exit()
a2=4*x-y
b2=y-2*x
if a2==0 and b2==0:
  print('No')
elif a2 < 0:
  print('No')
elif b2 < 0:
  print('No')
else:
  print('Yes')


Measured memory_bytes: 9184
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <deque>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <cstring>
#include <iomanip>
#include <utility>
 
#define rep(i,n) for(int i=0;i<(n);i++)
#define reps(i,n) for(int i=1;i<=(n);i++)
#define lol long long
const int INF = 0x3f3f3f3f;
const long long LINF = 0x3f3f3f3f3f3f3f3fLL;
 
using namespace std;
 
int h,w,sx,sy,gx,gy,tx,ty;
char house[505][505];   
bool isvisited[505][505]={false};
 
void search(int x,int y){
    if(isvisited[x][y]){
        return;
    }
    isvisited[x][y]=true;
 
    if(x<=0 || x>h || y<=0 || y>w){
        return;
    }
 
    if(house[x][y]=='#'){
        return;
    }
 
    search(x-1,y-1);
    search(x-1,y);
    search(x-1,y+1);
    search(x,y-1);
    search(x,y);
    search(x,y+1);
    search(x+1,y-1);
    search(x+1,y);
    search(x+1,y+1);
}
 
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    lol k=1,n,sum=0;
    
    cin>>n;

    while(n!=1){
      sum+=k;
      k*=2;
      n/=2;
    }
    cout<<sum+k<<'\n';
    
    return 0;
}


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

int main(){
    int N, K;
    cin >> N >> K;
    long A[N+1];
    rep1(i, N) cin >> A[i];

    ll sum = 0;
    rep1(i, K) sum += A[i];

    for(int i = K+1; i <= N; i++){
        if (A[i] > A[i-K]){
            cout << "Yes" << endl;
        }else{
            cout << "No" << endl;
        }
    }
    
    return 0;
}

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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
int c[3][3];
int a[3];
int b[3];
int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    //freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);

    for(int i=0;i<3;i++)for(int j=0;j<3;j++)cin>>c[i][j];
    for(int k=0;k<=c[0][0];k++){
        a[0] = k;
        b[0] = c[0][0]-a[0];
        a[1] = c[1][0]-b[0];
        b[1] = c[0][1]-a[0];
        a[2] = c[2][0]-b[0];
        b[2] = c[0][2]-a[0];
        bool ans = true;
        for(int i=0;i<3;i++){
            for(int j=0;j<3;j++){
                if(a[i]+b[j]!=c[i][j]){
                    ans=false;
                }
            }
        }
        if(ans){
            cout<<"Yes";
            return 0;
        }
    }
    cout<<"No";
    return 0;
}


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

#define times(n, i)      uptil(0, n, i)
#define rtimes(n, i)     downto((n) - 1, 0, i)
#define upto(f, t, i)    for(int _##i = (t), i = (f); i <= _##i; i++)
#define uptil(f, t, i)   for(int _##i = (t), i = (f); i <  _##i; i++)
#define downto(f, t, i)  for(int _##i = (t), i = (f); i >= _##i; i--)
#define downtil(f, t, i) for(int _##i = (t), i = (f); i >  _##i; i--)
typedef long double LD;
#define long long long

#if defined(EBUG) && !defined(ONLINE_JUDGE)
#define debug true
#define ln << endl
#else
#define debug false
#define ln << '\n'
#endif
#define tb << '\t'
#define sp << ' '


pair<long, long> XY[200000];

signed main() { // long: 64bit
    if(!debug) {
        cin.tie(0);
        ios::sync_with_stdio(0);
    }

    int N;
    scanf("%d",&N);

    long xm = LLONG_MAX, xM = 0, ym = LLONG_MAX, yM = 0;
    times(N, i) {
        int X, Y;
        scanf("%d%d",&X,&Y);
        long x = min(X, Y), y = max(X, Y);
        XY[i] = {x, y};
        xm = min(x, xm);
        xM = max(x, xM);
        ym = min(y, ym);
        yM = max(y, yM);
    }
    sort(XY, XY + N);

    long k = LLONG_MAX, l = XY[N-1].first, yl = LLONG_MAX;
    times(N, i) {
        if(XY[i].first > yl) {
            k = min(k, l - yl);
            if(debug) cout << "*" << k ln;
            break;
        }
        yl = min(yl, XY[i].second);
        k = min(k, l - XY[i].first);
        l = max(l, XY[i].second);
        if(debug) cout << "*" << k sp << l ln;
    }

    cout << min((yM - ym) * (xM - xm), (yM - xm) * k) ln;

    return 0;
}


Measured memory_bytes: 3456
require 'set'
n, m = gets.split.map(&:to_i)
ni = Set.new
pi = Set.new
m.times do
  a, b = gets.split.map(&:to_i)
  ni << b if a == 1
  pi << a if b == n
  pi << b if a == n
end

ni.each do |x|
  if pi.include?(x)
    puts "POSSIBLE"
    exit
  end
end

puts "IMPOSSIBLE"


Measured memory_bytes: 14844
#include <bits/stdc++.h> 
using namespace std; 
typedef long long int ll;
int main()
{
    int t=1;
    //cin>>t;
    while(t--)
    {
        string s;
        cin>>s;
        if(s[2]==s[3]&&s[4]==s[5])
        {
        	cout<<"Yes"<<endl;
        }
        else
        {
        	cout<<"No"<<endl;
        }

    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
using namespace std;
int N,M,L,K;

int main() {
	cin >> N >> K;
	vector<ll> h(N);
	for (int i = 0; i < N; i++)
	{
		cin >> h[i];
	}
	sort(h.begin(), h.end());
	ll ans = 1e9;
	for (int i = 0; i < N-K+1; i++)
	{
		ans = min(ans, abs(h[i] - h[i + K - 1]));
	}
	cout << ans << endl;
}


Measured memory_bytes: 1152
# C Traveling Salesman around Lake

K, N = map(int, input().split())
A = list(map(int, input().split()))

ans = 0
before = A[0]
for i in range(1, len(A)):
  ans = max(ans, A[i] - before)
  before = A[i]
  
ans = max(ans, A[0] + K - A[N-1])

print(K - ans)

Measured memory_bytes: 32256
#include <iostream>
#include <cmath>
#include <vector>
#include <string>
#include <map>
#include <algorithm>
#include <tuple>
#include <set>
#include <stack>
#include <queue>
#include <deque>
#include <cstdio>
#include <numeric>
#define REP(i, n) for(LL i = 0;i < n;i++)
#define REPR(i, n) for(LL i = n;i >= 0;i--)
#define FOR(i, m, n) for(LL i = m;i < n;i++)
#define FORR(i, m, n) for(LL i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define pb(a) push_back(a)
#define all(x) (x).begin(),(x).end()
#define INF (LL)1e15
#define MOD 1000000007
using namespace std;
typedef long long LL;
typedef pair<int, int> P;
typedef pair<LL, LL> LP;
typedef pair<int, P> PP;
typedef pair<LL, LP> LPP;
int dy[]={0, 0, 1, -1, 0};
int dx[]={1, -1, 0, 0, 0};

#define int long long

/*************** using variables ***************/
int n, a;
vector<int> x;
LL dp[55][55][2505];
LL ans = 0;
/**********************************************/

signed main(){
    cin >> n >> a;
    x.resize(n+1);
    REP(i, n) cin >> x[i+1];
    
    dp[0][0][0] = 1;
    REP(i, n+1){
        REP(j, n+1){
            REP(k, a*n+1){
                if(i >= 1 && k < x[i]){
                    dp[i][j][k] = dp[i-1][j][k];
                }else if(i >= 1 && j >= 1 && k >= x[i]){
                    dp[i][j][k] = dp[i-1][j][k] + dp[i-1][j-1][k-x[i]];
                }
                //cout << "i, j, k: " << i << " " << j << " " << k << " " << dp[i][j][k] << endl;
            }
        }
    }

    FOR(i, 1, n+1){
        ans += dp[n][i][i*a];
    }

    cout << ans << endl;
}


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

// #define int long long

using namespace std;

signed main(void) {

  int n; cin >> n;
  vector<string> c;
  // map<string, vector<pair<int, int>>> mem;
  map<string, vector<int>> mem;
  map<pair<string, int>, int> book;

  for (int i = 0; i < n; ++i) {
    string city;
    int point;
    cin >> city >> point;
    c.push_back(city);
    if (!mem.count(city)) {
      mem[city] = vector<int>();
    }
    mem[city].push_back(point);
    book.insert(make_pair(make_pair(city, point), i+ 1));
  }

  sort(c.begin(), c.end());
  c.erase(unique(c.begin(), c.end()), c.end());

  for (auto it = c.begin(); it != c.end(); ++it)  {
    auto p = mem[*it];
    sort(p.begin(), p.end(), greater<int>());
    for (int j = 0; j < p.size(); ++j) {
      cout << book[make_pair(*it, p[j])] << endl;
    }
  }
  
  
  return 0;
}


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

int main(){
    int a,b,c,d,e,f,total;
    cin >>a>>b>>c>>d;
    if (a>b){e=b;}else{e=a;}
    if (c>d){f=d;}else{f=c;}
    total=e+f;
    cout << total;
    return 0;

}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <queue>
using namespace std;
 
const int inf = 1e9;
const int maxN = 1e5 + 5;
int dp[maxN], l[maxN], N, d[maxN], minn = inf, cnt, e, val[maxN];
bool vis[maxN];
char s[maxN];
struct edge{
	int v, fa;
}G[maxN << 1];
 
void add(int u, int v) {
	G[e].v = v; G[e].fa = l[u]; l[u] = e++;
}
 
int que(int i) {
	if(val[i] == 0) return 1;
	return -1; 
}
 
void dfs(int u, int p) {
	//cout << val[u] << ' ' << s[u] << ' ' << u << "***********"<<endl;
	int t1 = inf, t2 = inf;
	for(int i = l[u]; i != -1; i = G[i].fa) {
		int v = G[i].v; if(vis[v] || v == p) continue;
		dfs(v, u);
		if(dp[v] <= t1) t2 = t1, t1 = dp[v];
		else if(dp[v] < t2) t2 = dp[v];
	}
	dp[u] = -1 + que(u);
	if(t1 < inf) dp[u] = min(t1 + que(u) - 1, dp[u]);
	if(t1 < inf && t2 < inf) minn = min(t1 + t2 - 1 + que(u), minn);
	minn = min(minn, dp[u]);
	//cout << u << ' ' << dp[u] << ' ' << "@@@@@@@@@@@@@@@@" << endl;
}
 
int main() {
	scanf("%d", &N); for(int i = 1; i <= N; ++i) l[i] = -1;
	for(int i = 1; i < N; ++i) {
		int u, v; scanf("%d%d", &u, &v);
		add(u, v); add(v, u); d[u]++; d[v]++;
	}
	scanf("%s", s + 1);
	queue<int> q;
	int n = N;
	cnt = 0;
	for(int i = 1; i <= N; ++i) {
		cnt += s[i] == 'W';
		if(d[i] <= 1 && s[i] == 'B') q.push(i), vis[i] = 1, n--;
	}
	while(!q.empty()) {
		int new_ = q.front(); q.pop();
		for(int i = l[new_]; i != -1; i = G[i].fa) {
			int v = G[i].v; if(vis[v]) continue;
			d[v]--;
			if(d[v] <= 1 && s[v] == 'B') q.push(v), vis[v] = 1, n--;
		}
	}
	//cout << n << endl;
	if(n <= 1) {
		cout << n << endl; return 0;
	}
	int ans = 2 * (n - 1);
	for(int i = 1; i <= N; ++i) {
		if(!vis[i]) val[i] = ((s[i] == 'W') + d[i]) % 2, ans += val[i];
	}
	for(int i = 1; i <= n; ++i) {
		if(!vis[i]) {
			dfs(i, -1); break;
		}
	}
	if(minn < 0) ans += minn;
	cout << ans << endl;
}

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

int main() {
  int nI;
  scanf("%d", &nI);
  std::vector<int> cost(nI);
  std::vector<int> value(nI);
  for (int i = 0; i < nI; ++i) {
    scanf("%d", &value[i]);
  }
  for (int i = 0; i < nI; ++i) {
    scanf("%d", &cost[i]);
  }
  std::vector<int> perm(nI);
  for (int i = 0; i < nI; ++i) {
    perm[i] = i;
  }
  std::sort(perm.begin(), perm.end(), [&](const int& left, const int& right) {
    return value[left] - cost[left] > value[right] - cost[right];
  });  
  int result = 0;
  for (int i = 0; i < nI; ++i) {
    int ind = perm[i];
    int delta = value[ind] - cost[ind];
    if (delta < 0) {
      break;
    }
    result += delta;
  }
  printf("%d", result);
  return 0;
}

Measured memory_bytes: 256
n = int(input())
dic = {}
m = 0
for ind in range(n):
    word = input()
    if not word in dic.keys():
        dic[word] = 1
    else:
        dic[word] = dic[word] + 1
    m = max(m, dic[word])

l = []
for key in dic.keys():
    if dic[key] == m:
        l.append(key)
l.sort()
for elm in l:
    print(elm)

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

const std::string ans[2] = {"No\n", "Yes\n"};
constexpr ll MOD         = 1'000'000'007;

int main() {
    using namespace std;
    int h, n;
    cin >> h >> n;
    int a;
    for (int i = 0; i < n; i++) {
        cin >> a;
        h -= a;
    }
    cout << ans[(h <= 0) ? 1 : 0];
    return 0;
}

Measured memory_bytes: 256
def calcs(x,y,ax,ay,bx,by) ((ax-x)*(by-y)-(bx-x)*(ay-y))/2.0 end

def inpf() a=gets.chomp.split(" ").map(&:to_f)end

def inps() a=gets.chomp.split(" ")end

def copy(a) Marshal.load(Marshal.dump(a)) end

def factorial(n)(n < 2)? 1 : (2..n).inject(:*) end

def scount(a) b=na(a.max+1);a.each{|n|b[n]+=1};return b end

def na(n,d=0) Array.new(n,d)end

def na2(n,m,d=0) Array.new(n){Array.new(m,d)}end

def na3(n,m,l,d=0) Array.new(n){Array.new(ym){Array.new(l,d)}}end

def yn(f) return (f)? "Yes": "No" end

def ynb(f) return (f)? "YES": "NO" end

def ap(a) a.each{|u| p u} end

def bit(n) n.to_s(2).split("").map(&:to_i) end

def inp() a=gets.chomp.split(" ").map(&:to_i)end
s = gets.chomp
ans = 0
s.each_char.with_index do |c,i|
  if(i.odd?)
    if(c == "g")
      ans += 1
    end
  else 
    if(c == "p") 
      ans -= 1
    end
  end
end
p ans

Measured memory_bytes: 2044
import sys
input = sys.stdin.readline
from itertools import groupby
from operator import itemgetter
def print_ans(N, M, ar):
    """Test Case
    >>> print_ans(2, 5, [['1', 'WA'], ['2', 'WA'], ['2', 'AC'], ['2', 'WA'], ['1', 'AC']])
    2 2
    >>> print_ans(100000, 3, [['7777', 'AC'], ['7777', 'AC'], ['7777', 'AC']])
    1 0
    >>> print_ans(6, 0, [])
    0 0
    """
    correct = 0
    wrong = 0
    ar = sorted(ar, key=itemgetter(0))
    if M == 0:
        print(0, 0)
    else:
        for (k, g) in groupby(ar, key=itemgetter(0)):
            tmp_wrong = 0
            ac_flg = False
            for item in g:
                if item[1] == "AC":
                    correct += 1
                    ac_flg = True
                    break
                else:
                    tmp_wrong += 1
            if ac_flg == True:
                wrong += tmp_wrong
        print("{} {}".format(correct, wrong))
if __name__ == '__main__':
    N, M = map(int, input().rstrip().split())
    if M == 0:
        ar = []
    else:
        ar = [list(map(str, input().rstrip().split())) for i in range(M)]
    print_ans(N, M, ar)

Measured memory_bytes: 34576
import java.util.Scanner

object Main extends App {
  val sc = new Scanner(System.in)
  val N = sc.nextInt
  val L = Array.fill(N)(sc.nextInt)

  val z = L.zipWithIndex.combinations(3).filter(x => {
    val Array(a, b, c) = x.map(_._1)

    a != b && a != c && b != c && a + b > c && b + c > a && c + a > b
  }).map(_.map(_._2 + 1)).size

  println(z)
}


Measured memory_bytes: 62424
sumajedan = 0
sumadva = 0

n = int(input())

a = list(map(int,input().split()))

a.sort(reverse = True)

for x in range(n):
    if x%2 == 0:
        sumajedan=sumajedan + a[x]
    else:
        sumadva = sumadva + a[x]
print(sumajedan - sumadva)

Measured memory_bytes: 3064
#include<stdio.h>
int main()
{
	int kimatsu[5], goukei = 0,a,i;
	for (i = 0; i < 5; i++)
	{
		scanf("%d", &kimatsu[i]);
		for (a = 40; kimatsu[i] < a;)
		{
			kimatsu[i] = 40;
		}
	}
	goukei =( kimatsu[0] + kimatsu[1] + kimatsu[2] + kimatsu[3] + kimatsu[4])/5;
	printf("%d\n",goukei);

	return 0;
}

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

using namespace std;
#ifdef _DEBUG
#define _GLIBCXX_DEBUG
#include "dump.hpp"
#else
#define dump(...)
#endif

//#define int long long
typedef __int128_t Int;
#define DBG 1
#define rep(i, a, b) for (int i = (a); i < (b); i++)
#define rrep(i, a, b) for (int i = (b)-1; i >= (a); i--)
#define loop(n) rep(loop, (0), (n))
#define all(c) begin(c), end(c)
const int INF =
    sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)(1e9) + 7;
const double PI = acos(-1);
const double EPS = 1e-9;
#define fi first
#define se second
#define eb emplace_back
using pii = pair<int, int>;
// template<class T> ostream &operator<<(ostream &os,T &t){dump(t);return os;}
template <typename T, typename S>
istream &operator>>(istream &is, pair<T, S> &p) {
  is >> p.first >> p.second;
  return is;
}
template <typename T> void printvv(const vector<vector<T>> &v) {
  cerr << endl;
  rep(i, 0, v.size()) rep(j, 0, v[i].size()) {
    if (typeid(v[i][j]) == typeid(INF) and v[i][j] == INF) {
      cerr << "INF";
    } else
      cerr << v[i][j];
    cerr << (j == v[i].size() - 1 ? '\n' : ' ');
  }
  cerr << endl;
}

#ifndef _DEBUG
#define printvv(...)
#endif
void YES(bool f) { cout << (f ? "YES" : "NO") << endl; }
void Yes(bool f) { cout << (f ? "Yes" : "No") << endl; }
template <class T> bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <class T> bool chmin(T &a, const T &b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}

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

  int H, W;
  cin >> H >> W;
  vector<vector<int>> v(H, vector<int>(W));
  rep(i, 0, H) rep(j, 0, W) { cin >> v[i][j]; }
  auto np = [&](pii p) {
    int x = p.fi, y = p.se;
    if (y == W - 1 and x % 2 == 0)
      p.fi++;
    else if (y == 0 and x % 2 == 1)
      p.fi++;
    else if(x%2==0)
      p.se++;
    else if(x%2==1)p.se--;
    return p;
  };
  vector<pair<pii, pii>> ans;
  pii p(0, 0);
  loop(H * W - 1) {
    int x = p.fi, y = p.se;
    auto a = np(p);
    int f = a.fi, g = a.se;
    if (v[x][y] & 1) {
      ans.emplace_back(make_pair(p, np(p)));
      v[x][y]--;
      v[f][g]++;
    }
    p = a;
  }
  dump(v);

  cout << ans.size() << endl;
  for (auto ff : ans) {
    cout << ff.fi.fi+1 << " " << ff.fi.se+1 << " " << ff.se.fi+1 << " " << ff.se.se+1
         << endl;
  }

  return 0;
}


Measured memory_bytes: 5236
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstring>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

const int MOD = 1e9 + 7;
const int iINF = 1000000000;
const long long int llINF = 1000000000000000000;

using namespace std;
using ll = long long int;
using vv = vector<vector<ll>>;
using edge = struct {
  int to;
  int cost;
};
#define REP(i, n) for (ll i = 0; i < (n); i++)
#define FOR(i, a, b) for (ll i = (a); i < (b); i++)
#define AUTO(i, m) for (auto &i : m)
#define ALL(a) (a).begin(), (a).end()
#define MAX(vec) *std::max_element(vec.begin(), vec.end());
#define MIN(vec) *std::min_element(vec.begin(), vec.end());
#define BIT(n, num) std::bitset<(n)>((num)).to_string()
#define REV(T) greater<T>()

typedef pair<ll, ll> Pair;
bool pairCompare(const Pair &firstElof, const Pair &secondElof) {
  return firstElof.second > secondElof.second;
}

vector<ll> divisor(ll n) {
  vector<ll> ret;
  for (ll i = 1; i * i <= n; i++) {
    if (n % i == 0) {
      ret.push_back(i);
      if (i * i != n)
        ret.push_back(n / i);
    }
  }
  sort(begin(ret), end(ret));
  return (ret);
}

map<ll, int> prime_factor(ll n) {
  map<ll, int> ret;
  for (ll i = 2; i * i <= n; i++) {
    while (n % i == 0) {
      ret[i]++;
      n /= i;
    }
  }
  if (n != 1)
    ret[n] = 1;
  return ret;
}

ll factorial(int n) {
  ll ans = 1;
  for (int i = 2; i <= n; i++) {
    ans *= i;
    ans %= MOD;
  }
  return ans;
}
ll P(int n, int m) {
  ll ans = 1;
  for (int i = m + 1; i <= n; i++) {
    ans *= i;
    ans %= MOD;
  }
  return ans;
}
ll power(int n, int m) {
  if (m == 0) {
    return 1;
  } else if (m % 2 == 0) {
    ll tmp = power(n, m / 2);
    return (tmp * tmp) % MOD;
  } else {
    return (n * power(n, m - 1)) % MOD;
  }
}
ll C(int n, int m) {
  return (P(n, n - m) * power(factorial(m), MOD - 2)) % MOD;
}
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};

int main() {
  ll N, K;
  ll A = 0, B = 0;
  cin >> N >> K;
  ll one[50];
  REP(i, 50) { one[i] = 0; }
  REP(i, N) {
    ll a;
    cin >> a;
    REP(i, 50) {
      if (a >= (1 << i) && (a >> i) & 1)
        one[i]++;
    }
  }
  ll ans = 0;
  ll mans = 0;
  REP(i, 50) {
    if ((K >> i) & 1)
      mans += (1LL << i) * (N - one[i]);
    else
      mans += (1LL << i) * one[i];
  }
  for (ll i = 0; i < 50; i++) {
    ans = 0;
    if ((K >> i) & 1) {
      ans += (1LL << i) * one[i];
      FOR(j, i + 1, 50) {
        if ((K >> j) & 1)
          ans += (1LL << j) * (N - one[j]);
        else
          ans += (1LL << j) * one[j];
      }
      for (ll j = i - 1; j >= 0; j--) {
        ans += (1LL << j) * max(one[j], N - one[j]);
      }

      mans = max(ans, mans);
    }
  }

  cout << mans << endl;

  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdlib>
#include<cstring>
#include<stack>
#include<queue>
#include<algorithm>
#include<vector>
#include<math.h>
#include<bitset>
#include<iomanip>
using namespace std;

typedef stack<int> IntStack;
typedef queue<int> IntQueue;

/*ここまでテンプレ*//*ここまでテンプレ*//*ここまでテンプレ*//*ここまでテンプレ*/



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

	int d, r;
	double f;

	d = a / b;
	r = a % b;
	double ad = (double)a;
	double bd = (double)b;
	f = ad / bd;

	cout << d << " " << r << " " << fixed << setprecision(10) << f << endl;

	return 0;
}



Measured memory_bytes: 3256
using System;

public class Program{

	public static void Main(){
	
	
		var input = long.Parse(Console.ReadLine());
		
		var water = Array.ConvertAll(Console.ReadLine().Split(' '), long.Parse);
		var mountain = new long[input];
		
		long waterSum = 0;
		
		foreach(var x in water){
			waterSum += x;
		}
		
		long midSum = 0;
		
		for(int i = 1; i < input; i+=2){
			midSum += water[i]*2;
			
		}
		
		mountain[0] = waterSum - midSum;
		
		for(int i = 1; i < input; i++){
			Console.Write(mountain[i-1] + " ");
			mountain[i] = 2 * water[i-1] - mountain[i-1];
		}
		Console.WriteLine(mountain[input-1]);
		
		
	
	
	
	}


}

Measured memory_bytes: 32080
mod = 1000000007
eps = 10**-9


def main():
    import sys
    input = sys.stdin.readline

    N = int(input())
    for i in range(1, 100):
        if 1000 * i >= N:
            print(1000*i-N)
            break


if __name__ == '__main__':
    main()


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

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

    int n;
    cin >> n;
    vector<int> V(n);
    REP(i, n) cin >> V[i];

    map<int, int> mp[2];
    REP(i, n) mp[i%2][V[i]]++;

    vector<pair<int, int>> P[2];
    REP(i, 2){
        mp[i][0] = 0;
        /*
        `mp[i][0] = 0について`
        全部0入ってると思いきや違うみたいで、
        偶奇両者ともkeyが一つの場合、片方の全変が必要なので0をいれておく
        → 下ででてくるP[0][1].firstに0が入っていることにより、n/2-0 すなはち全部変えることになる
        */

        for(auto x : mp[i]){
            P[i].push_back({x.second, x.first});
        }
        sort(P[i].begin(), P[i].end(), greater<pair<int, int>>());
    }

    //最頻値の数値の種類が偶奇で違う場合
    if(P[0][0].second != P[1][0].second){
        int ans = n/2 - P[0][0].first + n/2 - P[1][0].first;
        cout << ans << endl;
    }else{
        int a1, a2;
        a1 = n/2 - P[0][1].first + n/2 - P[1][0].first;
        a2 = n/2 - P[0][0].first + n/2 - P[1][1].first;
        cout << min(a1, a2) << endl;
    }


    return 0;
}

Measured memory_bytes: 6524
#include <iostream>

using namespace std;

int main()
{
    int h[750],w[750],ih,iw,i,c;
    c=0;

    while(1){
        cin >> h[c] >> w[c];
        if(h[c]==0,w[c]==0)break;
        c++;
    }

    for(i=0;i<c;i++){
        for(ih=0;ih<h[i];ih++){
            for(iw=0;iw<w[i];iw++){

                if(ih%2==0){
                    if(iw%2==0){
                        cout << "#";
                    }
                    else{
                        cout << ".";
                    }
                }
                else{
                    if(iw%2==0){
                        cout << ".";
                    }
                    else{
                        cout << "#";
                    }
                }
            }
            cout << endl;
        }
        cout << endl;
    }

}


Measured memory_bytes: 3100
#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 k, s;
  cin >> k >> s;
  int ans = 0;
  for (int x = 0; x <= k; x++) {
    for (int y = 0; y <= k; y++) {
      int z = s - x - y;
      if (z >= 0 && z <= k) ans++;
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3652
#include<stdio.h>
#define MAX 251
#define NIL -2000000001
struct node{
  int key;
  int parent_key;
  int left_key;
  int right_key;
};
typedef struct node Node;
int main(){

  int n,i,size;
  Node heap[MAX];

  scanf("%d",&n);
  for(i = 1; i <= n; i++){
    heap[i].key = NIL;
    heap[i].parent_key = NIL;
    heap[i].left_key = NIL;
    heap[i].right_key = NIL;
  }
  for(i = 1; i <= n; i++){
    scanf("%d",&size);
    if(i == 1)
      heap[i].key = size;
    else if(i % 2 == 0){
      heap[i].key = size;
      heap[i].parent_key = heap[i/2].key;
      heap[i/2].left_key = heap[i].key;
    }
    else{
      heap[i].key = size;
      heap[i].parent_key = heap[i/2].key;
      heap[i/2].right_key = heap[i].key;
    }

  }
    for(i = 1; i <= n; i++){
      if(i == 1)
	printf("node %d: key = %d, left key = %d, right key = %d, \n",i,heap[i].key,heap[i].left_key,heap[i].right_key);
      else if(heap[i].left_key != NIL && heap[i].right_key != NIL)
	printf("node %d: key = %d, parent key = %d, left key = %d, right key = %d, \n",i,heap[i].key,heap[i].parent_key,heap[i].left_key,heap[i].right_key);
      else if(heap[i].right_key == NIL && heap[i].left_key != NIL)
	printf("node %d: key = %d, parent key = %d, left key = %d, \n",i,heap[i].key,heap[i].parent_key,heap[i].left_key);
      else
	printf("node %d: key = %d, parent key = %d, \n",i,heap[i].key,heap[i].parent_key);
    }
  return 0;
}

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

typedef long long ll;
typedef unsigned long long ull;
typedef unsigned __int128 HASH;
typedef pair<int,int> pii;
typedef pair<ll, ll> pll;
typedef pair<ull, ull> pullull;
typedef pair<ll,int> plli;
typedef pair<double, int> pdbi;
typedef pair<int,pii> pipii;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;
typedef vector<pii> vpii;

#define rep(i,n) for (int i=0;i<(n);i++)
#define rep2(i,a,b) for (int i=(a);i<(b);i++)
#define rrep(i,n) for (int i=(n);i>0;i--)
#define rrep2(i,a,b) for (int i=(a);i>b;i--)
#define pb push_back
#define fi first
#define se second
#define all(a) (a).begin(),(a).end()

const ll mod = 1000000000 + 7;
const ll hmod1 = 999999937;
const ll hmod2 = 1000000000 + 9;
const ll INF = 1<<30;
const int dx4[4] = {1, 0, -1, 0};
const int dy4[4] = {0, 1, 0, -1};
const int dx8[8] = {1, 1, 1, 0, 0, -1, -1, -1};
const int dy8[8] = {0, 1, -1, 1, -1, 0, 1, -1};
const double pi = 3.141592653589793;

int n, ma, mb;
int dp[45][405][405];
int a[105], b[105], c[105];

signed main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> n >> ma >> mb;
    rep(i, n) cin >> a[i] >> b[i] >> c[i];
    rep(i, 41)rep(j, 401)rep(k, 401) dp[i][j][k] = INT_MAX / 10;
    dp[0][0][0] = 0;
    rep(i, n)rep(j, 401)rep(k, 401) {
        dp[i + 1][j][k] = dp[i][j][k];
        if (j - a[i] >= 0 && k - b[i] >= 0) {
            dp[i + 1][j][k] = min(dp[i + 1][j][k], dp[i][j - a[i]][k - b[i]] + c[i]);
        }
    }
    int ans = INT_MAX / 10;
    rep2(j, 1, 401)rep2(k, 1, 401) {
        if (j % ma == 0 && k % mb == 0) {
            if (j / ma == k / mb) {
                ans = min(ans, dp[n][j][k]);
            }
        }
    }
    if (ans == INT_MAX / 10) cout << -1 << endl;
    else cout << ans << endl;
}


Measured memory_bytes: 26880
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);

	int A= sc.nextInt();
	int B= sc.nextInt();
	int X= sc.nextInt();

	if(X<A ||A+B<X){
		System.out.println("NO");
	}else{
		System.out.println("YES");
	}


	}

}


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

int main() {

    int n, q;
    cin >> n >> q;
    vector<pair<pair<int, int>, int> > blocks;
    for (int i=0; i<n; i++) {
        int s, e, x;
        cin >> s >> e >> x;
        blocks.push_back(make_pair(make_pair(s-x, 0), x));
        blocks.push_back(make_pair(make_pair(e-x-1, 2), x));
    }
    for (int i=0; i<q; i++) {
        int t;
        cin >> t;
        blocks.push_back(make_pair(make_pair(t, 1), i));
    }
    int results[q];
    sort(blocks.begin(), blocks.end());

    set<int> active;

    for (int i=0; i<blocks.size(); i++) {

        if (blocks[i].first.second == 0) {
            active.insert(blocks[i].second);
        }
        else if (blocks[i].first.second == 1) {
            if (active.size() == 0) {
                results[blocks[i].second] = -1;
            }
            else {
                results[blocks[i].second] = *active.begin();
            }
        }
        else {
            active.erase(active.find(blocks[i].second));
        }

    }

    for (int i=0; i<q; i++) {
        cout << results[i] << endl;
    }


}

Measured memory_bytes: 19816
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
const ll mo = 1000000007;
const ll INF = 1LL << 60; //MAX 9223372036854775807
ll ans = 0;

int main()
{
ll n;
cin >> n;
ll t[n] = {};
rep(i, n){
    cin >> t[i];
}
sort(t,n+t);
ans=t[n/2]-t[n/2-1];

cout << ans << endl;
return 0;
}


Measured memory_bytes: 1024
h, w, d = list(map(int, input().split()))

a_dict = {}
for i in range(h):
  r = list(map(int, input().split()))
  for j in range(w):
    a_dict[r[j]] = [i+1, j+1]

q = int(input())

need_power = {}

for i in range(1, h*w+1):
  if i <= d:
    need_power[i] = 0
    continue

  need_power[i] = need_power[i-d] + abs(a_dict[i][0] - a_dict[i-d][0]) + abs(a_dict[i][1] - a_dict[i-d][1])

test = [list(map(int, input().split())) for i in range(q)]

for t in test:                                                                                                             
  print(need_power[t[1]] - need_power[t[0]])

Measured memory_bytes: 58468
#include <iostream>
#include <fstream>
#include <typeinfo>
#include <vector>
#include <cmath>
#include <set>
#include <map>
#include <string>
#include <algorithm>
#include <cstdio>
#include <queue>
#include <iomanip>
#include <cctype>
#define syosu(x) fixed<<setprecision(x)
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<double,double> pdd;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<char> vc;
typedef vector<vc> vvc;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef vector<P> vp;
typedef vector<vp> vvp;
typedef pair<int,P> pip;
typedef vector<pip> vip;
const int inf=1<<25;
const ll INF=1ll<<50;
const double pi=acos(-1);
const double eps=1e-8;
const vi emp;

const int mod=10000;

int Plus(P p){
	return (p.first+p.second)%mod;
}

int n,k;
vi a;
vvp dp;

int main(){
	cin>>n>>k;
	a=vi(n);
	dp=vvp(n,vp(3));
	for(int i=0;i<k;i++){
		int A,B;
		cin>>A>>B;
		a[A-1]=B;
	}
	if(!a[0]){
		dp[0][0].first++;
		dp[0][1].first++;
		dp[0][2].first++;
	}
	else dp[0][a[0]-1].first++;
	for(int i=1;i<n;i++){
		vp p(3);
		for(int j=0;j<3;j++) p[j]=dp[i-1][j];
		if(!a[i]){
			dp[i][0].first=(Plus(p[1])+Plus(p[2]))%mod;
			dp[i][1].first=(Plus(p[2])+Plus(p[0]))%mod;
			dp[i][2].first=(Plus(p[0])+Plus(p[1]))%mod;
			dp[i][0].second=p[0].first;
			dp[i][1].second=p[1].first;
			dp[i][2].second=p[2].first;
		}
		else{
			int I=a[i]-1;
			dp[i][I].first=(Plus(p[0])+Plus(p[1])+Plus(p[2])-Plus(p[I]))%mod;
			dp[i][I].second=p[I].first;
		}
	}
	int ans=0;
	for(int i=0;i<3;i++) ans=(ans+Plus(dp[n-1][i]))%mod;
	cout<<ans<<endl;
}

Measured memory_bytes: 3160
#include"bits/stdc++.h"
using namespace std;
typedef long long int ll;
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);

int main(){

    fast
    long double a,b;
    cin>>a>>b;
    long long int c = a*b;
    cout<<c;
}



Measured memory_bytes: 3760
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
/*unionfindかな
同じグループに属してる箇所はいくらでも交換可能
*/
vector<bool> seen;
vector<vector<ll>> G;
struct UnionFind{
  vector<ll> par,siz;
  
  UnionFind(ll N):par(N+1),siz(N+1,1){
    for(int i=0; i<=N; i++)
      par[i]=i;
  }
  
  void mkpar1(ll parent, ll n){//親は最上位
    for(auto next_n: G[n]){
      if(seen[next_n]) continue;
      seen[next_n]=true;
      par[next_n]=parent;
      mkpar1(parent, next_n);
    }
  }
  
  void mkpar2(ll n){//親は1個うえ
    for(auto next_n: G[n]){
      if(seen[next_n]) continue;
      seen[next_n]=true;
      par[next_n]=n;
      mkpar2(next_n);
    }
  }
  
  ll root(ll x){
    if(par[x]==x)
      return x;
    return par[x]=root(par[x]);
  }
  
  void unite(ll x, ll y){
    ll rx=root(x), ry=root(y);
    if(rx==ry)
      return;
    par[ry]=rx;
    siz[rx]+=siz[ry];    
  }
  
  bool issame(ll x, ll y){
    return root(x)==root(y);
  }
  
  ll size(ll x){
    return siz[root(x)];
  }
};
int main(){
  ll N,M; cin>>N>>M;
  vector<ll> Z(N+1,0);
  seen.assign(N+1,false);
  vector<vector<ll>> posnum(N+1, vector<ll>(0,0));
  for(int i=1; i<=N; i++){
    ll a; cin>>a;
    Z[i]=a;
  }
  G.assign(N+1, vector<ll>(0,0));
  for(int i=0; i<M; i++){
    ll a,b; cin>>a>>b;
    G[a].emplace_back(b);
    G[b].emplace_back(a);
  }
  UnionFind tree(N);
  for(int i=1; i<=N; i++){
    seen[i]=true;
    tree.mkpar1(i,i);
  }
  //親は作れた。けど、どの数字がペアなのか、何番目がペアなのか管理しにくい
  //親の数字と、何番目かを1つの配列にほおりこんで、重複してたらプラスポイントでいいか
  for(int i=1; i<=N; i++){
    ll parent=tree.par[Z[i]];
    posnum[parent].emplace_back(i);
    posnum[parent].emplace_back(Z[i]);
  }
  ll ans=0;
  for(int i=1; i<=N; i++){
    sort(posnum[i].begin(), posnum[i].end());
//    cout<<"i:"<<i<<" size:"<<posnum[i].size()<<endl;
    auto IT=unique(posnum[i].begin(), posnum[i].end());
    ans+=posnum[i].end()-IT;
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 13940