akhauriyash/Code-Regression huggingface dataset:
import sys
input = sys.stdin.readline

n, m = map(int, input().split())
hn = list(map(int, input().split()))

height = [0]*n
for _ in range(m):
    a, b = map(int, input().split())
    height[a-1] = max(height[a-1], hn[b-1])
    height[b-1] = max(height[b-1], hn[a-1])

ans = 0
for i in range(n):
    if hn[i] > height[i]:
        ans += 1

print(ans)



Measured memory_bytes: 20336
a,b,c,k=gets.split.map(&:to_i)
ans=0
if k>0 && a>0
  ans+=[a,k].min
  k-=[a,k].min
end
if k>0 && b>0
  k-=[b,k].min
end
if k>0 && c>0
  ans-=[c,k].min
end
puts ans


Measured memory_bytes: 14316
/// Bismillahir Rahmanir Rahim
/// S. M. Shakir Ahsan Romeo

#include <bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
//using namespace __gnu_pbds;

const double PI = acos(-1.0);

typedef long long lng;
typedef unsigned long long ulng;
typedef double db;
typedef pair < int, int >  pii;
typedef vector < pii >  vpii;
//typedef tree < int, null_type, less < int >, rb_tree_tag, tree_order_statistics_node_update > ordered_set;

inline int getint()
{
    int x;
    scanf("%d", &x);
    return x;
}
#define II getint()

inline long long getlng()
{
    long long x;
    scanf("%lld", &x);
    return x;
}
#define LL getlng()

int dx4[] = {-1, 0, 1, 0};
int dy4[] = {0, 1, 0, -1};
int dx8[] = {-1, -1, -1, 0, 0, 1, 1, 1};
int dy8[] = {-1, 0, 1, -1, 1, -1, 0, 1};


void solve();
#define theromeo421 main()
#define segtree int lft = node << 1, rgt = lft | 1, mid = (b + e) >> 1;
#define mem(x, y) memset((x), (y), sizeof (x));
#define sz(x) ((int)x.size())
#define max3(a,b,c) max(a, max(b,c))
#define min3(a,b,c) min(a, min(b,c))
#define pr1(x) cout << x << endl
#define pr2(x,y) cout << x << ' ' << y << endl
#define rep(i, n) for(int i = 0; i < n; ++i)
#define rep1(i, n) for(int i = 1; i <= n; ++i)
#define repstl(it, x) for(auto it = x.begin(); it != x.end(); it++)
#define forcon(pp , qq) for(const auto& pp : qq)
#define all(x) (x).begin(), (x).end()
#define Unique(x) sort(all(x)); x.erase(unique(all(x)), x.end()); /// x needs to be sorted first
#define pb push_back
#define wait system("pause")
#define xx first
#define yy second
#define dbg(x) cerr << #x << "=" << x << endl;
#define dbg2(x, y) cerr << #x << "=" << x << ", " << #y << "=" << y << endl;
#define read(a) freopen(a, "r", stdin);
#define write(a) freopen(a, "w", stdout);
#define prv(v) rep(i, sz(v)) cout << v[i] << " \n"[i + 1 == v.size()];
#define Case int T; scanf("%d", &T); for(int cas = 1; cas <= T; ++cas)
#define pf printf
#define sf scanf
#define MP make_pair
#define endl '\n'
const double eps = (double)1e-9;


int theromeo421
{
    /// PLEASE HACK my code, I am error prone.
    /// Your hack can save me from the cruel hand of system testing. :) :P ;)
    solve();
#ifdef romeo
    cerr << "\nElapsed time: " << 1.0 * clock() / CLOCKS_PER_SEC << '\n';
#endif // romeo
    return 0;
}


void solve()
{
    int n = II;
    int cx = 0, cy = 0, tt = 0;
    bool ok = true;
    rep(i, n)
    {
        int nt = II, x = II, y = II;
        int t = nt - tt;
        int d = abs(x - cx) + abs(y - cy);
        bool can = true;
        if(t < d)
            can = false;
        else if(t == d)
            can = true;
        else
        {
            int e = t - d;
            if(e % 2 == 1)
                can = false;
        }
        ok &= can;
        cx = x, cy = y, tt = nt;
        //dbg(can);
    }
    puts(ok ? "Yes" : "No");
}


Measured memory_bytes: 256
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

import array
import collections
import itertools


class DepthFirstSearchWithStack(object):

    def __init__(self, width, height, tiles):
        self.width = width
        self.height = height
        self.tiles = tiles
        self.reached = [array.array(
            "B", (False for y in range(height))) for x in range(width)]
        for x, y in itertools.product(range(width), range(height)):
            if tiles[x][y] == "@":
                self.start_tile = (x, y)
                break

    def search(self, x0, y0):
        stack = collections.deque()
        self.reached[x0][y0] = True
        stack.append((x0, y0))
        while stack:
            (x, y) = stack.pop()
            for i, j in [(x + 1, y), (x - 1, y), (x, y + 1), (x, y - 1)]:
                if i < 0 or self.width <= i or j < 0 or self.height <= j:
                    pass
                elif self.tiles[i][j] == "#":
                    pass
                elif not self.reached[i][j]:
                    self.reached[i][j] = True
                    stack.append((i, j))

    def count_reachable_tiles(self):
        self.search(*self.start_tile)
        reachable_tiles = sum([self.reached[x][y] for x, y in itertools.product(
            range(self.width), range(self.height))])
        return reachable_tiles


if __name__ == "__main__":
    while True:
        width, height = map(int, input().split())
        if width == 0 and height == 0:
            break
        else:
            tiles = [x for x in zip(*[input() for y in range(height)])]
            dfs = DepthFirstSearchWithStack(width, height, tiles)
            print(dfs.count_reachable_tiles())

Measured memory_bytes: 8184
def main():
    N = int(input())
    d = [int(a) for a in input().split()]
    d_sort = sorted(d)
    if (d_sort[N//2-1] == d_sort[N//2]):
        print(0)
    else:
        print(d_sort[N//2]-d_sort[N//2-1])

main()


Measured memory_bytes: 52780
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Scanner;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        C solver = new C();
        solver.solve(1, in, out);
        out.close();
    }

    static class C {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            // 入力
            String S = in.next();
            int ans = 0;
            int red = 0;
            int blue = 0;
            for (int i = 0; i < S.length(); i++) {
                if (S.charAt(i) == '0') {
                    red++;
                } else {
                    blue++;
                }
            }

            ans = 2 * Math.min(red, blue);

            // 出力
            out.println(ans);

        }

    }
}



Measured memory_bytes: 26200
s=input()
ss = s[::-1]
ok=True
if s != ss:
    ok =False
n=len(s)
a = s[:(n-1)//2]
aa = a[::-1]
if a!=a:
    ok=False
b=s[(n+3)//2-1:]
bb=b[::-1]
if b!=bb:
    ok=False
print('Yes' if ok else 'No')

Measured memory_bytes: 38384
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(v) v.begin(), v.end()
int main(){
  long long int X, Y; cin >> X >> Y;
  int ans = 0;
  while(X <= Y){
    ans++;
    X *= 2;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
S = input()

def func(i, x, op):
    if i == 4:
        if x == 7:
            return op
        else:
            return ''
    opP = func(i + 1, x + int(S[i]), op+'+'+str(S[i]))
    if opP != '':
        return opP
    opM = func(i + 1, x - int(S[i]), op+'-'+str(S[i]))
    if opM != '':
        return opM
    return ''

print(func(1, int(S[0]), str(S[0])) + '=7')

Measured memory_bytes: 3064
n=int(input())
xy=[list(map(int,input().split())) for _ in range(n)]
sgm=pow(10,-7)
def func(c):
    allp=[]
    for i in range(n-1):
        for j in range(i+1,n):
            xi,yi=xy[i]
            xj,yj=xy[j]
            dx=xi-xj
            dy=yi-yj
            d=((xi-xj)**2+(yi-yj)**2)**0.5
            if c**2-(d/2)**2<0:return False
            h=(c**2-(d/2)**2)**0.5
            mx,my=(xi+xj)/2,(yi+yj)/2
            if dx==0:
                allp.append([mx-h,my])
                allp.append([mx+h,my])
            elif dy==0:
                allp.append([mx,my-h])
                allp.append([mx,my+h])
            else:
                dx,dy=dy,-dx
                dh=(dy**2+dx**2)**0.5
                dx*=h/dh
                dy*=h/dh
                allp.append([mx+dx,my+dy])
                allp.append([mx-dx,my-dy])
    for px,py in allp:
        flg=True
        for x,y in xy:
            if ((px-x)**2+(py-y)**2)**0.5>c+sgm:
                flg=False
                break
        if flg:
            return True
    return False

r=2*max([abs(x) for x,y in xy])+max([abs(y) for x,y in xy])
l,r=0,r
for i in range(400):
    c=(l+r)/2
    if func(c):
        l,r=l,c
    else:
        l,r=c,r
print(c)
#print(c**2)

Measured memory_bytes: 9992
#include <bits/stdc++.h>
#define pb push_back
#define SZ(x) ((int)(x.size()))
#define FOR(i,s,n) for (ll i = (s); (i) < (n); ++i)
#define FORD(i,s,l) for (ll i = (s); (i) >= l; --i)
#define F first
#define S second
#define TC int __tc; cin >> __tc; FOR(case_num,1,__tc+1)
#define TEST(x,i) ((x)&(1ll<<(i)))
#define SET(x,i) ((x)|(1ll<<(i)))
#define FLIP(x,i) ((x)^(1ll<<(i)))
#define CLEAR(x,i) ((x)&~(1ll<<(i)))

const double pi = 4 * atan(1);
using namespace std;
typedef long long ll;

const ll MOD = 1000000007;
const int MAXN = 200005;

int m[105][105];
int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	
	int w,h,n;
	cin >> w >> h >> n;
	
	FOR(i,0,n){
		int x, y, a;
		cin >> x >> y >> a;
		FOR(i,0,w) {
			FOR(j,0,h) {
				if (a == 1 && i < x) {
					m[i][j]=1;
				}
				if (a == 2 && i >= x) {
					m[i][j]=1;
				}
				if (a == 3 && j < y) {
					m[i][j]=1;
				}
				if (a == 4 && j >= y) {
					m[i][j]=1;
				}
			}
		}
	}
	int t = 0;
	FOR(i,0,w) {
		FOR(j,0,h) {
			t+=m[i][j]==0;
		}
	}
	cout << t << "\n";

}


Measured memory_bytes: 3660
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>

#define vec vector
#define rep(i, n) for (int i = 0; i < (int)n; i++)

using namespace std;

int main(void)
{
    int n, l;
    cin >> n >> l;
    vec<string> s(n);
    rep(i, n) cin >> s[i];
    sort(s.begin(), s.end());
    rep(i, n) cout << s[i];
    cout << endl;
    return 0;
}

Measured memory_bytes: 256
#include"stdio.h"
#include"string.h"
#include"stack"
#include"map"
#include"math.h"
#include"iostream"
#include"vector"
#include"queue"
#include"algorithm"
using namespace std;
#define OK printf("\n");
#define Debug printf("this_ok\n");
#define INF 1e18
typedef long long ll;
#define scanll(a,b) scanf("%lld%lld",&a,&b);
#define scanl(a) scanf("%lld",&a);
#define printl(a,b) if(b == 0) printf("%lld ",a); else printf("%lld\n",a);
#define print_int(a,b) if(b == 0) printf("%d ",a); else printf("%d\n",a);
typedef pair<int,int> PII;

inline int read(){
    int s = 0, w = 1; char ch = getchar();
    while(ch < '0' || ch > '9')   { if(ch == '-') w = -1; ch = getchar(); }
    while(ch >= '0' && ch <= '9') { s = (s << 3) + (s << 1) + (ch ^ 48); ch = getchar(); }
    return s * w;
}
const ll mod = 998244353;
const int N = 50010,M = 300010;
const  double pi = acos(-1);
const int inf = 1 << 29;
const int dirx[4] = {-1,0,1,0};

char str[N],t[N];
int main(){
   scanf("%s%s",str + 1,t + 1);
   int lens = strlen(str + 1);
   int lent = strlen(t + 1);
   int ans = lens;
   for(int i = 1; i <= lens - lent + 1; i ++){
     int maxx = 0,t1 = i;
     for(int j = 1; j <= lent; j ++,t1 ++){
        if(str[t1] == t[j]) {
            continue;
        }
        maxx ++;
     }
     ans = min(maxx,ans);
   }
   printf("%d\n",ans);
}
/*
3
1 2 3
2
2 6
*/



Measured memory_bytes: 3828
#include <bits/stdc++.h>
#define int long long
#define pb push_back
#define mp make_pair
using namespace std;
const int inf = 1e18 + 7;
const int N = 1e6 + 7;
const int md = 1e9 + 7;
int tz(int n) 
{ 
    int cnt = 0; 
    for (int i = 5; n / (2*i) >= 1; i *= 5) 
        cnt += n / (2*i); 
  
    return cnt; 
} 
void sol() {
    int n;
    cin >> n;
  	if(n % 2) {
      cout << 0; return;
    }
    cout << tz(n);
    
    //cout << (n % 2 == 0) ? tz(n) : 0;
}

int32_t main() 
{
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int T = 1;
  //cin >> T; while(T--) 
  sol();
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define x first
#define y second

using namespace std;

const double eps = 1e-9;
const int N = 1e5 + 10;
typedef long long ll;

vector<int> g[N];
int dist[N], pred[N];
const int INF = 0x3f3f3f3f;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n, m;
  memset(dist, INF, sizeof dist);
  memset(pred, INF, sizeof pred);
  pred[0] = 0;
  cin >> n >> m;
  for (int i = 0; i < m; i++) {
    int u, v;
    cin >> v >> u;
    --u, --v;
    g[u].push_back(v);
    g[v].push_back(u);
  }
  vector<int> q;
  q.emplace_back(0);
  dist[0] = 0;
  int head = 0;
  while (head < q.size()) {
    int u = q[head++];
    //cerr << "{" << head << ", " << u << "}" << endl;
    for (auto v : g[u]) {
      //cerr << v << ':' << dist[v] << ' ';
      if (dist[v] > dist[u] + 1) {
	//cerr << "[" << dist[u] << ", " << dist[v] << endl;
	dist[v] = dist[u] + 1;
	q.push_back(v);
	pred[v] = u;
      }
    }
  }

  for (int i = 0; i < n; i++) {
    //cerr << pred[i] << ' ';
    if (pred[i] == INF) {
      cout << "No\n";
      return 0;
    }
  }
  cout << "Yes\n";
  for (int i = 1; i < n; i++) cout << pred[i] + 1 << endl;
  return 0;
}


Measured memory_bytes: 10880
import sys
input = sys.stdin.readline
N,Q = map(int,input().split())
AB = [tuple(map(int,input().split())) for i in range(N-1)]
PX = [tuple(map(int,input().split())) for i in range(Q)]

es = [[] for i in range(N)]
for a,b in AB:
    a,b = a-1,b-1
    es[a].append(b)
    es[b].append(a)

xs = [0] * N
for p,x in PX:
    xs[p-1] += x

ans = [0] * N
ans[0] = xs[0]
visited = [0] * N
stack = [0]
while stack:
    v = stack.pop()
    visited[v] = 1
    for to in es[v]:
        if visited[to]: continue
        stack.append(to)
        ans[to] = ans[v] + xs[to]

print(*ans)

Measured memory_bytes: 125608
// -*- coding:utf-8-unix -*-

use proconio::{fastout, input};

#[fastout]
fn main() {
    input! {
        n: usize,
        a: [usize; n],
    }
    let mut asum = ModP(0);
    let mut nijousum = ModP(0);
    for &ai in &a {
        asum = asum + ModP(ai);
        nijousum = nijousum + ModP(ai) * ModP(ai);
    }
    let ans = (asum * asum - nijousum) / ModP(2);
    println!("{}", ans.0);
}

use num_traits::{pow, One};
use std::ops::{Add, Div, Mul, Sub};

const MODULUS: usize = 1000000007;

#[derive(Clone, Copy, PartialEq, Debug)]
struct ModP(usize);

impl One for ModP {
    fn one() -> Self {
        return ModP(1);
    }
}
impl Add for ModP {
    type Output = Self;
    fn add(self, rhs: Self) -> Self {
        return ModP((self.0 + rhs.0) % MODULUS);
    }
}
impl Sub for ModP {
    type Output = Self;
    fn sub(self, rhs: Self) -> Self {
        return ModP((self.0 + MODULUS - rhs.0) % MODULUS);
    }
}
impl Mul for ModP {
    type Output = Self;
    fn mul(self, rhs: Self) -> Self {
        return ModP((self.0 * rhs.0) % MODULUS);
    }
}
impl Div for ModP {
    type Output = Self;
    fn div(self, rhs: Self) -> Self {
        if rhs.0 == 0 {
            panic!("Tried to divide by ModP(0)!");
        }
        let rhs_inv = pow(rhs, MODULUS - 2);
        return self * rhs_inv;
    }
}


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

int main() {
	int d;
	string message;
	cin >> d;

	switch (d)
	{
	case 25: message = "Christmas";
		break;
	case 24: message = "Christmas Eve";
		break;
	case 23: message = "Christmas Eve Eve";
		break;
	case 22: message = "Christmas Eve Eve Eve";
		break;
	}

	cout << message << endl;
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
using namespace std;
                   
int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.precision(10);
  cout<<fixed;
#ifdef LOCAL_DEFINE
    freopen("in", "r", stdin); 
    freopen("out","w",stdout);
#endif
  string s,t;
  cin>>s;
  t="";
  int n=(int)s.length();
  for(int i=0;i<n;i++){
    if((i+1)&1)t+=s[i];
  }
  cout<<t<<endl;
#ifdef LOCAL_DEFINE
    cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
#endif
  return 0;
}

Measured memory_bytes: 592
#include<stdio.h>
int main(void)
{
	int t[101],n,s,f,i,x[101],j;
	j=0;
	while(1){
		x[j]=0;
		scanf("%d",&t[j]);
		if(t[j]==0) break;
		scanf("%d",&n);
		for(i=0;i<n;i++){
			scanf("%d  %d",&s,&f);
			x[j]+=f-s;
		}
		j++;
	}
	for(i=0;i<j;i++){
		if(x[i]>=t[i])	printf("OK\n");
		else{
			x[i]=t[i]-x[i];
			printf("%d\n",x[i]);
		}
	}
	return 0;
}
		


Measured memory_bytes: 2036
x,y,r,l,s=[],[],[],[],[]
while 1:
    try:
        a,b=map(float,raw_input().split(','))
        x.append(a)
        y.append(b)
    except:
        break
for i in range(len(x)-1):
    r.append(((x[i+1]-x[0])**2+(y[i+1]-y[0])**2)**0.5)
for i in range(1,len(x)-1):
    l.append(((x[i+1]-x[i])**2+(y[i+1]-y[i])**2)**0.5)
for i in range(len(x)-2):
    s.append((r[i]+r[i+1]+l[i])/2)
sum=0.0
for i in range(len(x)-2):
    sum+=(s[i]*(s[i]-r[i])*(s[i]-r[i+1])*(s[i]-l[i]))**0.5
print sum

Measured memory_bytes: 6660
#include <stdio.h>

int main(void)
{ 
	int a[3];
	int i,j,m;
	for(i=0;i<3;i++) scanf("%d",&a[i]);
	for(i=0;i<3;i++){
		for(j=i+1;j<3;j++){
			if(a[i]>a[j]){
				m=a[i];
				a[i]=a[j];
				a[j]=m;
			}
		}
	}
	printf("%d %d %d\n",a[0],a[1],a[2]);
	return 0;
}


Measured memory_bytes: 2000
//JOI2018 1 Pencils
//20181208
//F_Naru
#include<iostream>
#include<algorithm>
using namespace std;
int main(){
  int N,A,B,C,D;
  cin >> N >> A >> B >> C >> D;
  cout << min(((N+A-1)/A)*B,((N+C-1)/C)*D) << endl;
}



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

int main()
{
    double r;
    cin>>r;
    double pi=3.14159265359;
    cout<<fixed;
    cout<<setprecision(6)<<pi*r*r<<" "<<2*pi*r;
    cout<<"\n";
    return 0;
}



Measured memory_bytes: 3244
/////////////////////////////////////////Info/////////////////////////////////////////////////
//Problem:
//Date:
//Skill:
//Bug:
/////////////////////////////////////////Definations/////////////////////////////////////////////////
//循环控制
#define CLR(a) memset((a),0,sizeof(a))
#define F(i,a,b) for(int i=a;i<=int(b);++i)
#define F2(i,a,b) for(int i=a;i>=int(b);--i)
#define RE(i,n)  for(int i=0;i<int(n);i++)
#define RE2(i,n) for(int i=1;i<=int(n);i++)
//简化敲击
#define PII pair<int,int>
#define PLL pari<long long ,long long>
#define PB push_back
#define ENDL '\n'
#define x first
#define y second
using namespace std;
typedef long long ll;
const int inf = 0x3f3f3f3f;
const long long llinf = 0x3f3f3f3f3f3f3f3f;
////////////////////////////////////////Options//////////////////////////////////////////////////////
#define stdcpph
#define CPP_IO

#ifdef stdcpph
#include<bits/stdc++.h>
#else
#include<ctype.h>
#include<string.h>
#include<math.h>
#include<vector>
#include<map>
#include<algorithm>
#include<functional>
#ifdef CPP_IO
#include<iostream>
#include<iomanip>
#include<string>
#else
#include<stdio.h>
#endif
#endif
////////////////////////////////////////Basic Functions//////////////////////////////////////////////
template<typename INint> inline void IN(INint &x)
{
	x = 0; int f = 1; char c; cin.get(c);
	while (c<'0' || c>'9') { if (c == '-')f = -1; cin.get(c); }
	while (c >= '0'&&c <= '9') { x = x * 10 + c - '0'; cin.get(c); }
	x *= f;
}
template<typename INint> inline void OUT(INint x)
{
	if (x > 9)OUT(x / 10); cout.put(x % 10 + '0');
}
////////////////////////////////////////Added Functions//////////////////////////////////////////////
const int maxn = int(20);

////////////////////////////////////////////Code/////////////////////////////////////////////////////
int main()
{
	//freopen("C:\\Users\\VULCAN\\Desktop\\data.in", "r", stdin);
	int T(1), times(0);
#ifdef CPP_IO// CPP_IO
	ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
	//cin >> T;
#else
	//IN(T);
#endif 
	/////////////////////////////////////////////////////////////////////////////////////////////////
	while (++times, T--)
	{
		int n, k;
		cin >> n >> k;
		RE2(i, n)
		{
			char c; cin >> c;
			if (i == k)cout << char(c - 'A' + 'a');
			else cout << c;
		}
	}
	///////////////////////////////////////////////////////////////////////////////////////////////////
	return 0;
}

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

 
int solve(int n, int h[]){
  int dp[n];
  dp[0] = 0;
  dp[1] = abs(h[1] - h[0]);
  for(int i = 2; i < n; ++i){
    dp[i] = min(dp[i-1] + abs(h[i] - h[i-1]), dp[i-2] + abs(h[i] - h[i-2]));
  }
  return dp[n-1];
}


int main(){
  int n;
  cin >> n;
  int hs[n];
  for(int i = 0; i < n; ++i){
    cin >> hs[i];
  }
  cout << solve(n, hs) << endl;
  return 0;
}


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

int main(){
	int a,b; cin >> a >> b;
	int k=50;
	char grid[2*k][2*k];
	char c='#';
	for(int i=0;i<2*k;i++){
		for(int j=0;j<2*k;j++) grid[i][j]=c;
		if(i==k-1) c='.';
	}
	int count=0;
	bool flag=false;
	bool flag1=false;
	bool flag2=false;
	int check=a-1;
	for(int i=0;i<2*k;i+=2){
		for(int j=0;j<2*k;j+=2){
			if(count==check){
				if(flag1) flag2=true;
				flag=true;
				break;
			}
			grid[i][j]=c;
			count++;
		}
		if(flag && flag2) break;
		if(flag && !flag2){
			i=k-1;
			c='#';
			count=0;
			check=b-1;
			flag=false;
			flag1=true;
		}	
	}
	cout << 2*k << ' ' << 2*k << endl;
	for(int i=0;i<2*k;i++){
		for(int j=0;j<2*k;j++) cout << grid[i][j];
		cout << endl;
	}
}


Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cmath>
#include <cstdint>
#include <cstdio>
#include <cstring>
#include <deque>
#include <fstream>
#include <functional>
#include <iostream>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <vector>
using namespace std;
using ll = long long;
#define fst first
#define snd second

/* clang-format off */
template <class T, size_t D> struct _vec { using type = vector<typename _vec<T, D - 1>::type>; };
template <class T> struct _vec<T, 0> { using type = T; };
template <class T, size_t D> using vec = typename _vec<T, D>::type;
template <class T> vector<T> make_v(size_t size, const T& init) { return vector<T>(size, init); }
template <class... Ts> auto make_v(size_t size, Ts... rest) { return vector<decltype(make_v(rest...))>(size, make_v(rest...)); }
template <class T> inline void chmin(T &a, const T& b) { if (b < a) a = b; }
template <class T> inline void chmax(T &a, const T& b) { if (b > a) a = b; }
/* clang-format on */

const int BITS = 30000;
const int GETA = 15000;

using N = bitset<BITS>;

int main() {
#ifdef DEBUG
  ifstream ifs("in.txt");
  cin.rdbuf(ifs.rdbuf());
#endif
  int H, W;
  while (cin >> H >> W) {
    vec<int, 2> A = make_v(H, W, 0), B = make_v(H, W, 0);
    for (int y = 0; y < H; y++) {
      for (int x = 0; x < W; x++) cin >> A[y][x];
    }
    for (int y = 0; y < H; y++) {
      for (int x = 0; x < W; x++) cin >> B[y][x];
    }
    vec<N, 2> dp = make_v(H, W, N());
    dp[0][0].set(GETA);
    for (int y = 0; y < H; y++) {
      for (int x = 0; x < W; x++) {
        int a = A[y][x], b = B[y][x];
        for (int d : {a - b, b - a}) {
          auto nval = dp[y][x];
          if (d > 0) {
            nval <<= d;
          } else {
            nval >>= -d;
          }
          if (y + 1 < H) dp[y + 1][x] |= nval;
          if (x + 1 < W) dp[y][x + 1] |= nval;
        }
      }
    }
    int res = 1 << 25;
    for (int k = 0; k < BITS; k++) {
      if (dp[H - 1][W - 1][k]) {
        int d = k - GETA;
        int a = A[H - 1][W - 1], b = B[H - 1][W - 1];
        chmin(res, abs(d + a - b));
        chmin(res, abs(d + b - a));
      }
    }
    cout << res << endl;
  }
  return 0;
}


Measured memory_bytes: 24320
use std::io;
use std::io::Write;
use io_ext::Reader;
use parse::ParseNext;

fn main() {
    let stdin = io::stdin();
    let mut r = Reader::new(io::BufReader::new(stdin.lock()));
    let (n, k, q): (usize, isize, isize) = {
        let s = r.read_line();
        let mut split = s.split_whitespace();
        (split.parse_next(), split.parse_next(), split.parse_next())
    };

    let mut points = vec![0; n];
    for _ in 0..q {
        let ans = r.read_line().parse::<usize>().unwrap() - 1;
        points[ans] += 1;
    }

    let stdout = io::stdout();
    let mut w = io::BufWriter::new(stdout.lock());
    for pt in points {
        if k + pt - q > 0 {
            writeln!(w, "Yes");
        } else {
            writeln!(w, "No");
        }
    }
}

/// Extension of io module.
pub mod io_ext {
    use std::io::BufRead;

    pub struct Reader<R> {
        buf: String,
        inner: R,
    }

    impl<R> Reader<R> {
        #[inline]
        pub fn new(inner: R) -> Self {
            Reader { buf: String::new(), inner: inner }
        }

        #[inline]
        pub fn into_inner(self) -> R {
            self.inner
        }
    }

    impl<R: BufRead> Reader<R> {
        #[allow(deprecated)]
        #[inline]
        pub fn read_line(&mut self) -> &str {
            self.buf.clear();
            self.inner.read_line(&mut self.buf).unwrap_or_else(|e| panic!("{}", e));
            self.buf.trim_right()
        }
    }
}

/// Module supporting to parse strings.
pub mod parse {
    use std::str::FromStr;
    use std::borrow::Borrow;

    pub trait ParseNext: Iterator {
        fn parse_next<F: FromStr>(&mut self) -> F;
    }

    impl<'a, S: Borrow<str>, I: Iterator<Item=S>> ParseNext for I {
        fn parse_next<F: FromStr>(&mut self) -> F {
            if let Some(s) = self.next() {
                match s.borrow().parse() {
                    Ok(x) => x,
                    Err(_) => panic!("provided string cannot be parsed")
                }
            } else {
                panic!("iterator has no next element")
            }
        }
    }
}


Measured memory_bytes: 4732
#include<iostream>
using namespace std;
#define MAX 100005
#define NIL -1

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

Node T[MAX];
int n, D[MAX];

void print(int u){
    int i, c;
    cout << "node " << u << ": ";
    cout << "parent = " << T[u].p << ", ";
    cout << "depth = " << D[u] << ", ";
    
    if(T[u].p  == NIL) cout << "root, ";
    else if(T[u].l == NIL) cout << "leaf, ";
    else cout << "internal node, ";
    
    cout << "[";
    
    for(i = 0, c = T[u].l; c != NIL; i++, c = T[c].r){
        if(i) cout << ", ";
        cout << c;
    }
    cout << "]" << endl;
}

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

int main(){
    int i, j, d, v, c, l, r;
    cin >> n;
    for(i = 0; i < n; i++) T[i].p = T[i].l = T[i].r = NIL;
    
    for(i = 0; i < n; i++){
        cin >> v >> d;
        for(j = 0; j < d; j++){
            cin >> c;
            if(j == 0) T[v].l = c;
            else T[l].r = c;
            l = c;
            T[c].p = v;
        }
    }
    for(i = 0; i < n; i++){
        if(T[i].p == NIL) r = i;
    }
    
    rec(r,0);
    
    for(i = 0; i < n; i++) print(i);
    
    return 0;
}


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

using namespace std;

#define int long long
#define ll long long
typedef pair<int, int> P;
#define mod 1000000007
#define INF (1LL<<60)

#define rep(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define YES puts("YES\n")
#define Yes puts("Yes\n")
#define NO  puts("NO\n")
#define No  puts("No\n")
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }




signed main() {

	int N;
	cin >> N;
	vector<int> H(N);
	rep(i, N) cin >> H[i];

	int ans = 0;
	int left = 0;
	int right = 0;
	for (;left<N;) {
		right = left + 1;
		while (right < N && H[right-1] >= H[right]) {
			right++;
		}
		ans = max(ans, right - left-1);
//		cerr << left << " " << right << " " << ans << endl;
		left = right;
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<ll,ll>;
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep2(i,m,n) for(int (i)=(m);(i)<(n);(i)++)
#define ALL(obj) (obj).begin(), (obj).end()
#define rALL(obj) (obj).rbegin(), (obj).rend()
const ll INF = 1LL<<60;
const ll MOD = 1e9+7;


int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    ll n; cin>>n;
    vector<ll> a(n), b(n);
    rep(i,n){cin>>a[i]>>b[i];}
    sort(ALL(a));sort(ALL(b));
    ll c1 = (n-1)/2, c2=n-1-(n-1)/2;
    ll low = a[c1]+a[c2];
    ll high = b[c1]+b[c2];

    if(n%2==0){
        cout<<high-low+1;

    } else{
        cout<<(high-low)/2+1;
    }
    return 0;
}

Measured memory_bytes: 6368
K = int(input())
AB = input()
l = AB.split()
A = int(l[0])
B = int(l[1])
li = []
for i in range(A, B+1) : 
  if i % K == 0 :
    li.append(i)
  else :
    continue
if len(li) >=1 :
  print("OK")
else : 
  print("NG")

Measured memory_bytes: 9188
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);++i)
#define rrep(i,n) for(int i=1;i<(n);++i)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define maxs(a, b) a = max(a, b)
#define mins(a, b) a = min(a, b)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const ll linf = (1ll << 61);
const int inf = 1001001001;
const int mod = 1000000007;

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n, q;
	cin >> n >> q;
	string s;
	cin >> s;
	vector<int> sum1(n + 1), sum2(n + 1);
	for (int i = 0; i < n - 1; ++i) {
		if (s.substr(i, 2) == "AC") {
			sum1[i + 1]++;
		}
		sum1[i + 1] += sum1[i];
	}
	while (q--) {
		int l, r;
		cin >> l >> r;
		l--; r--;
		int ans = sum1[r] - sum1[l];
		printf("%d\n", ans);
	}
	return 0;
}


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

int main(){

int a;
int b;
int c;

int x;

cin >> a >> b >> c;

if(a > b){
x=b;
b=a;
a=x;
}
if(b > c){
x=c;
c=b;
b=x;
}
if(a > b){
x=b;
b=a;
a=x;
}

cout << a << " " << b << " " << c << endl;
}

Measured memory_bytes: 3060
//#include "stdafx.h"
#include <stdio.h>
#include <iostream>
#include <set>
#include <queue>
#include <vector>
#include <algorithm>
#include <math.h>
#include <cmath>
#include <string>
#include <cstring>
#include <climits>
#include <sstream>
#include <iomanip>
#include <map>
#include <stack>
#include <tuple>
#include <numeric>
#include <assert.h>
#include <functional>
#include <unordered_map>
#include <cstdint>

using namespace std;

/*-----------------------------------------------------------------------------
　定義
 -------------------------------------------------------------------------------*/
#define REP(i, n)				for (int (i) = 0 ; (i) < (int)(n) ; ++(i))
#define REPN(i, m, n)			for (int (i) = m ; (i) < (int)(n) ; ++(i))
#define ALL(a)					(a).begin(),(a).end()
#define INF						2e9
#define MOD						(1000 * 1000 * 1000 + 7)
#define Ceil(x, n)				(((((x))+((n)-1))/n))		/* Nの倍数に切り上げ割り算 */
#define CeilN(x, n)				(((((x))+((n)-1))/n)*n)		/* Nの倍数に切り上げ */
#define FloorN(x, n)			((x)-(x)%(n))				/* Nの倍数に切り下げ */
#define IsOdd(x)				(((x)&0x01UL) == 0x01UL)			
#define IsEven(x)				(!IsOdd((x)))						
#define ArrayLength(x)			(sizeof( x ) / sizeof( x[ 0 ]))
#define	MAX_QWORD				((QWORD)0xFFFFFFFFFFFFFFFF)
#define M_PI					3.14159265358979323846
typedef long long				ll;
typedef unsigned long long int	QWORD;
typedef unsigned long long		SQWORD;
typedef pair<ll, ll>			P;

/*-----------------------------------------------------------------------------
　処理
 -------------------------------------------------------------------------------*/
int main()
{
	string S;
	cin >> S;

	int ans = 0;
	REP(i, 4) {
		if (S[i] == '+') ans++;
		else ans--;
	}
	cout << ans << endl;
	return 0;
}



Measured memory_bytes: 256
import sys
N = int(input())
a = []
for i in range(N):
    a.append(int(input()))
a.sort()
if sum(a)%10 != 0:
  print(sum(a))
else:
  j = 0
  while j < len(a):
    if a[j]%10 != 0:
      print(sum(a)-a[j])
      sys.exit()
    else:
      j += 1
  print(0)

Measured memory_bytes: 3064
#include <iostream>
using namespace std;
int findsum(int n) {
  int sum = 0;
  while (n > 0) {
    sum += n % 10;
    n /= 10;
  }
  return sum;
}
int main() {
  int n, a, b;
  cin >> n >> a >> b;
  int total = 0;
  for (int i = 0; i <= n; i++) {
    int sum = findsum(i);
    if (sum >= a && sum <= b) {
      total += i;
    }
  }
  cout << total << endl;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
  public static void main (String[] args) {
    Scanner in = new Scanner(System.in);

    while (in.hasNext()) {
      int N = in.nextInt();
      int M = in.nextInt();
      int X = in.nextInt();
      int Y = in.nextInt();
      int maxX = Integer.MIN_VALUE;
      int minY = Integer.MAX_VALUE;

      for (int i = 0; i < N; ++i) {
        maxX = Math.max(maxX, in.nextInt());
      }

      for (int i = 0; i < M; ++i) {
        minY = Math.min(minY, in.nextInt());
      }

      if (Y < X + 1) {
        System.out.println("War");
      } else {
        if (minY < maxX + 1) {
          System.out.println("War");
        } else if (minY < X + 1 || Y < maxX + 1) {
          System.out.println("War");
        } else {
          System.out.println("No War");
        }
      }
    }
  }
}

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

class SegmentTree:
    def __init__(self, num, ide_ele=0):
        tmp = 1
        while tmp < num:
            tmp *= 2
        self.n = tmp
        self.ide_ele = ide_ele
        self.l = [ide_ele] * (2 * self.n - 1)
    
    def func(self, x, y):
        return x + y
        # return min(x, y)

    def update(self, i, val):
        i = self.n - 1 + i
        self.l[i] += val
        while i > 0:
            i = (i-1)//2
            self.l[i] = self.func(self.l[i*2+1], self.l[i*2+2])
    
    def query(self, a, b, k, l, r):
        # print(a, b, k, l, r)
        if r <= a or b <= l:
            return self.ide_ele
        if a <= l and r <= b:
            return self.l[k]
        vl = self.query(a, b, k*2+1, l, (l+r)//2)
        vr = self.query(a, b, k*2+2, (l+r)//2, r)
        return self.func(vl, vr)

def main():
    N, Q = map(int, input().split())

    segt = SegmentTree(N)

    for _ in range(Q):
        c, x, y = map(int, input().split())
        if c == 0:
            segt.update(x-1, y)
        else:
            print(segt.query(x-1, y, 0, 0, segt.n))
        # print(segt.l)



if __name__ == "__main__":
    main()


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

using namespace std;

typedef long long int64;
#define int long long
const int64 INF = 1LL << 58;

struct SegmentTree
{
  vector< int64 > small, add;
  int sz;


  inline void Merge(int k)
  {
    small[k] = min(small[2 * k + 1] + add[2 * k + 1], small[2 * k + 2] + add[2 * k + 2]);
  }

  SegmentTree(int n)
  {
    sz = 1;
    while(sz < n) sz <<= 1;
    small.assign(2 * sz - 1, INF);
    add.assign(2 * sz - 1, 0);
  }

  int64 rmq(int a, int b, int k, int l, int r)
  {
    if(a >= r || b <= l) return (INF);
    if(a <= l && r <= b) return (small[k] + add[k]);
    int64 L = rmq(a, b, 2 * k + 1, l, (l + r) >> 1);
    int64 R = rmq(a, b, 2 * k + 2, (l + r) >> 1, r);
    return (min(L, R) + add[k]);
  }


  int64 addd(int a, int b, int k, int l, int r)
  {
    if(a >= r || b <= l) return (0);
    if(a <= l && r <= b) return (add[k]);
    int64 L = addd(a, b, 2 * k + 1, l, (l + r) >> 1);
    int64 R = addd(a, b, 2 * k + 2, (l + r) >> 1, r);
    return (L + R + add[k]);
  }

  void rangeadd(int a, int b, int64 x, int k, int l, int r, bool f)
  {
    if(a >= r || b <= l) return;
    if(a <= l && r <= b) {
      if(f) small[k] = x;
      else add[k] += x;
      return;
    }
    rangeadd(a, b, x, 2 * k + 1, l, (l + r) >> 1, f);
    rangeadd(a, b, x, 2 * k + 2, (l + r) >> 1, r, f);
    Merge(k);
  }

  int64 rmq(int a, int b)
  {
    return (rmq(a, b, 0, 0, sz));
  }

  void rangeadd(int a, int b, int64 x, bool f)
  {
    return (rangeadd(a, b, x, 0, 0, sz, f));
  }


  void update(int a, int b, int64 x)
  {
    int64 q = addd(a, a + 1, 0, 0, sz);
    rangeadd(a, b, x - q, 1);
  }
};


signed main()
{
  int N, Q, A, B, X[200000];
  cin >> N >> Q >> A >> B;
  --A, --B;

  SegmentTree tree1(N), tree2(N);
  for(int i = 0; i < N; i++) tree1.rangeadd(i, i + 1, i, 0);
  for(int i = 0; i < N; i++) tree2.rangeadd(i, i + 1, -i, 0);
  for(int i = 0; i < Q; i++) cin >> X[i], --X[i];

  tree1.update(B, B + 1, abs(A - X[0]) + B);
  tree2.update(B, B + 1, abs(A - X[0]) - B);
  tree1.update(A, A + 1, abs(B - X[0]) + A);
  tree2.update(A, A + 1, abs(B - X[0]) - A);


  for(int i = 1; i < Q; i++) {
    int64 latte = tree1.rmq(X[i], N) - X[i];
    int64 malta = tree2.rmq(0, X[i]) + X[i];
    latte -= abs(X[i - 1] - X[i]);
    malta -= abs(X[i - 1] - X[i]);

    tree1.update(X[i - 1], X[i - 1] + 1, min(latte, malta) + X[i - 1]);
    tree2.update(X[i - 1], X[i - 1] + 1, min(latte, malta) - X[i - 1]);

    tree1.rangeadd(0, N, abs(X[i - 1] - X[i]), 0);
    tree2.rangeadd(0, N, abs(X[i - 1] - X[i]), 0);
  }

  int64 ret = INF;
  for(int i = 0; i < N; i++) ret = min(ret, tree1.rmq(i, i + 1) - i);
  for(int i = 0; i < N; i++) ret = min(ret, tree2.rmq(i, i + 1) + i);
  cout << ret << endl;
}

Measured memory_bytes: 20224
# include <bits/stdc++.h>
# define INF 1e9
using namespace std;

int main(){

  int A, B, C, K;
  cin >> A >> B >> C >> K;

  int maxABC = max({A, B, C});
  int ans = A+B+C;
  ans += pow(2, K)*maxABC- maxABC;
  cout << ans << endl;

}


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

// output
#define SPBR(w, n) std::cout<<(w + 1 == n ? '\n' : ' ');
#define YES cout << "YES" << endl
#define Yes cout << "Yes" << endl
#define NO cout << "NO" << endl
#define No cout << "No" << endl
// utility
#define ALL(i) (i).begin(), (i).end()
#define FOR(i, a, n) for(int i=(a);i<(n);++i)
#define RFOR(i, a, n) for(int i=(n)-1;i>=(a);--i)
#define REP(i, n) for(int i=0;i<int(n);++i)
#define RREP(i, n) for(int i=int(n)-1;i>=0;--i)
#define IN(a, x, b) (a<=x && x<b)
#define OUT(a, x, b) (x<a || b<=x)
template<class T> inline T chmax(T & a, const T b) { return a = (a < b) ? b : a; }
template<class T> inline T chmin(T& a, const T b) { return a = (a > b) ? b : a; }

// type/const
#define int ll
using ll = long long;
using ull = unsigned long long;
using ld = long double;
const int MOD = 1000000007;
/* const int MOD = 998244353; */
const int INF = 1e18;
const double PI = acos(-1);

using namespace std;

int ans = INF;
int N, M, R; 
vector<int> r(10);
vector<bool> visited(10, false);
vector<vector<int>> dist(300, vector<int>(300, INF));

void dfs(int c, int p, int d){
  if(c == R){
    chmin(ans, d);
    return;
  }
  REP(i, R){
    if(visited[i]) continue;
    visited[i] = true;
    if(p != -1) dfs(c+1, i, d+dist[r[i]][r[p]]);
    else dfs(c+1, i, 0);
    visited[i] = false;
  }
}

signed main() {
  cin >> N >> M >> R;

  REP(i, R){
    cin >> r[i];
    r[i]--;
  }

  REP(i, N) dist[i][i] = 0;
  REP(i, M){
    int u, v, d;
    cin >> u >> v >> d;
    u--; v--;
    dist[u][v] = d;
    dist[v][u] = d;
  }

  REP(k, N) REP(i, N) REP(j, N){
    chmin(dist[i][j], dist[i][k]+dist[k][j]);
  }

  dfs(0, -1, 0);
  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <map>
#include <vector>

using namespace std;

int main() {
  int height, width;
  int left_sharp_num;

  cin >> height >> width >> left_sharp_num;
  vector<vector<char>> grid(height, vector<char>(width, -1));

  for(int i = 0; i < height; i++)  {
    for(int j = 0; j < width; j++) {
      cin >> grid[i][j];
    }
  }


  int pattern_num = width + height;
  int combination_count = 0;
  for(int i = 0; i < 1 << pattern_num; i++) {
    vector<vector<char>> tmp_grid(height, vector<char>(width, -1));
    for(int i = 0; i < height; i++)  {
      for(int j = 0; j < width; j++) {
        tmp_grid[i][j] = grid[i][j];
      }
    }

    // 塗る
    for(int j = 0; j < pattern_num; j++) {
      if(i & (1 << j)) {
        // width
        if(j >= 0 && j < width) {
          for(int k = 0; k < height; k++) {
            tmp_grid[k][j] = '-';
          }
        } else {
          // height
          for(int k = 0; k < width; k++) {
            tmp_grid[j - width][k] = '-';
          }
        }
      }
    }

    // Check
    int sharp_count = 0;

    for(int j = 0; j < height; j++)  {
      for(int k = 0; k < width; k++) {
        if(tmp_grid[j][k] == '#') {
          sharp_count++;
        };
      }
    }

    if(sharp_count == left_sharp_num) {
      combination_count++;
    }
  }

  cout << combination_count << endl;
}

Measured memory_bytes: 3616
import java.util.Scanner;

public class Main {

  public static void main(String[] args) {

    Scanner sc = new Scanner(System.in);

    String s = sc.next();
    int m = Integer.parseInt(s.substring(5, 7));
    int d = Integer.parseInt(s.substring(8, 10));

    if (m <= 4) {
      System.out.println("Heisei");
    } else {
      System.out.println("TBD");
    }

  }
}

Measured memory_bytes: 35660
s=input()
n=len(s)
s=s+"0000000"
c=0
check=0
while c<n:
    if s[c:c+5]=="dream":
        if s[c+5:c+7]=="er":
            if s[c+7]=="a":
                c+=5
            else:
                c+=7
        else:
            c+=5
    elif s[c:c+5]=="erase":
        if s[c+5]=="r":
            c+=6
        else:
            c+=5
    else:
        check+=1
        break
if check==0:
    print("YES")
else:
    print("NO")

Measured memory_bytes: 3188
from collections import deque

N, M = map(int, input().split())
d = [set() for _ in range(N+1)]
for _ in range(M):
    a, b = map(int, input().split())
    d[a].add(b)
    d[b].add(a)

queue=deque([1])
vs = set([1])
parents = [0] * (N+1)
dist = [0] * (N+1)
while queue:
    v = queue.popleft()
    for u in d[v]:
        if u in vs:
            continue
        parents[u] = v
        vs.add(u)
        queue.append(u)
        dist[u] = dist[v] + 1
print("Yes")
for x in parents[2:]:
    print(x)


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

int main(){
    int A, B;
    cin >> A >> B;
    int a = (A + B) / 2;
    int b = (A + B) % 2;

    if (b == 1){
        cout << "IMPOSSIBLE" << endl;
    }
    else {
        cout << a << endl;
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define int long long
using namespace std;
const int INF = 1e10;
const int MOD = 1e9 + 7;
#define dump(x) cout << #x << " = " << (x) << endl;
#define YES(n) cout << ((n) ? "YES" : "NO") << endl
#define Yes(n) cout << ((n) ? "Yes" : "No") << endl
#define SANKOU(n, a, b) cout << ((n) ? (#a) : (#b)) << endl
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define P pair<int, int>
#define V vector<int>
#define M map<int, int>
#define S set<int>
int n, v[100010];
int c1[100010];
int c2[100010];
int m1, m2, n1, n2, v1, v2;

signed main()
{
    cin >> n;
    FOR(i, 0, n)
    {
        cin >> v[i];
        if (i % 2) {
            c1[v[i]]++;
        } else {
            c2[v[i]]++;
        }
    }
    FOR(i, 0, 100010)
    {
        if (m2 < c2[i]) {
            n2 = m2;
            m2 = c2[i];
            v2 = i;
        } else {
            n2 = max(n2, c2[i]);
        }
        if (m1 < c1[i]) {
            n1 = m1;
            m1 = c1[i];
            v1 = i;
        } else {
            n1 = max(n1, c1[i]);
        }
    }
    if (v1 != v2)
        cout << n - m1 - m2 << endl;
    else {
        cout << n - max(m1 + n2, m2 + n1) << endl;
    }
    return 0;
}


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

using namespace std;

int compare(const void* a, const void* b)
{
    return *(int*)a > *(int*)b;
}

int TrianglesCount(int array[], int n)
{
    qsort(array,n,sizeof(array[0]),compare);
    int count = 0;
    for (int i = 0; i < n-2; ++i)
    {
        for (int j = i+1; j < n; ++j)
        {
            int k = j+1;
            while (k < n && array[i] + array[j] > array[k])
            {
               k = k + 1;
            }
            count = count + k - j - 1;
        }
    }
    return count;
}

//Main function
int main()
{
    int n,i;
    cin>>n;
    int arr[n+10];
    for(i=0; i<n; i++)
    {
        cin>>arr[i];
    }
    int size = n;
    cout<<TrianglesCount(arr,size)<<endl;
    return 0;
}


Measured memory_bytes: 256
S = [0]*4
N = int(input())
for i in range(N):
  a = input()
  if(a=="AC"):
    S[0] +=1
  elif (a=="WA"):
    S[1] +=1
  elif(a=="TLE"):
    S[2] +=1
  else:
    S[3] +=1
print("AC x" , S[0])
print("WA x",S[1])
print("TLE x",S[2])
print("RE x",S[3])

Measured memory_bytes: 9208
#![allow(non_snake_case)]
#![allow(unused_imports)]
 
use proconio::{input, fastout};
use proconio::marker::*;
use whiteread::parse_line;
use std::collections::*;

#[fastout]
fn main() {
    input!{
        K: usize,
    }

    let mut cnt: usize = 1;
    let mut queue: VecDeque<usize> = (1..10).collect();
    let mut ans: usize = 1;

    loop {
        let x = queue.pop_front().unwrap();
        if cnt == K {
            ans = x;
            break;
        }
        if x % 10 != 0 {
            queue.push_back(10 * x + x % 10 - 1);
        }
        queue.push_back(10 * x + x % 10);
        if x % 10 != 9 {
            queue.push_back(10 * x + x % 10 + 1);
        }
        
        cnt += 1;
    }

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


Measured memory_bytes: 4008
N = int(input())

tab = [[0] * 9 for _ in range(9)]

for head in range(1, 10):
    for tail in range(1, 10):
        val = 0
        if head == tail and head <= N: val += 1
        # if head * 10 + tail <= N: val += 1
        N_tmp = head * 10 + tail
        for level in range(100):
            N_nxt = (N_tmp - tail) * 10 + tail
            if N_nxt > N:
                val += min(max(0, (N - N_tmp) // 10 + 1), 10 ** level)
            else:
                val += 10 ** level
            #
            N_tmp = N_nxt
        #
        tab[head - 1][tail - 1] = val
        
# for i in range(9):
#     print("#", '\t'.join(map(str, tab[i])))

ans = 0
for head in range(1, 10):
    for tail in range(1, 10):
        ans += (tab[head - 1][tail - 1] * tab[tail - 1][head - 1])

print(ans)

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


int main(){
  int n;
  cin >> n;
  int ans = 0;
  for(int i = 1;i<=n;i++){
    int cnt = 0;
    int j = i; 
    while(j){
      j /= 10;
      cnt++;
    }
    if(cnt%2!=0) ans++;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
int main() {
	int a, b, c, d, x, n;
	while (scanf("%d", &n) != EOF) {
		x = 0;
		for (a = 0;a < 10;a++) {
			for (b = 0;b < 10;b++) {
				for (c = 0;c < 10;c++) {
					for (d = 0;d < 10;d++) {
						if (a + b + c + d == n) {
							x=x+1;
						}
					}
				}
			}
		}
		printf("%d\n", x);
	}
	return 0;
}

Measured memory_bytes: 596
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <stdlib.h>
#include <ctype.h>
#define MOD 998244353
#define MAX(a,b) (a>b?a:b)
#define MAX3(a,b,c) MAX(a,MAX(b,c))
#define MIN(a,b) (a<b?a:b)
#define MIN3(a,b,c) MIN(a, MIN(b,c))
typedef long long lli;
int cmp(const void *a, const void *b) {
    return *(int*)a - *(int*)b;
}

int main()
{
    int i;
    char s[4];
    scanf("%s",s);
    int ii = (s[0]-'0')*10 + (s[1]-'0');
    int jj = (s[2]-'0')*10 + (s[3]-'0');
    // printf("%d %d\n",ii,jj);
    if(ii==0 || 12 < ii) {
        if(0 < jj && jj <= 12) {
            puts("YYMM");
        } else {
            puts("NA");
        }
    } else {
        if(0 < jj && jj <= 12) {
            puts("AMBIGUOUS");
        } else {
            puts("MMYY");
        }
    }
    return 0;
}


Measured memory_bytes: 128
class Distance
  def initialize(d, axy)
    @d = d
    @axy = axy
  end

  def solve
    @axy.reduce(0) {|ct, xy| if @d * @d >= xy[0] * xy[0] + xy[1] * xy[1] then ct + 1 else ct end}
  end
end

def run
  n, d = gets.split(/\s+/).map(&:to_i)
  axy = (0...n).map{|_| gets.split(/\s+/).map(&:to_i)}
  
  puts Distance.new(d, axy).solve
end

run


Measured memory_bytes: 28944