akhauriyash/Code-Regression huggingface dataset:
#define rep(i, n) for (int i = 0; i < (n); i++)
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
const int MOD = 1000000007;
// MAX int 2,147,483,647
// MAX O(n) 10^18

int main() {
    int N;
    cin >> N;
    vector<int> A(N), B(N);
    vector<int> C(N - 1);
    rep(i, N) cin >> A.at(i);
    rep(i, N) cin >> B.at(i);
    rep(i, N - 1) cin >> C.at(i);

    int prevIndex = MOD;
    int ans = 0;
    rep(i, N) {
        ans += B.at(A.at(i) - 1);
        if (A.at(i) - 1 == prevIndex + 1) ans += C.at(prevIndex);
        prevIndex = A.at(i) - 1;
    }

    cout << ans << endl;

    return 0;
}


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

int main(){
  
  int a,b,c,k;
  cin>>a>>b>>c>>k;
  while(k--){
    if(a>=b) b*=2;
    else if(b>=c) c*=2;
    else break;
  }
  if(a<b&&b<c)cout <<"Yes"<<endl;
  else cout<<"No"<<endl;
  
}


Measured memory_bytes: 3636
#include <stdio.h>

int main(void)
{
	int a;
	int b;
	int c;

	scanf("%d%d%d", &a, &b, &c);

	if(a<0 || a>100 || b<0 || b>100 || c<0 || c>100)
	{
		return 1;
	}

	if( c - b > 0 )
	{
		if( b - a > 0)
		{
			printf("Yes\n");
		}
		else
		{
			printf("No\n");
		}

	}
	else
	{
		printf("No\n");
	}

	return 0;
}

Measured memory_bytes: 580
package main

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

type Node struct {
	id    int
	left  *Node
	right *Node
}

func main() {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	n, err := nextInt(sc)
	if err != nil {
		panic(err)
	}
	pre, err := nextInts(n, sc)
	in, err := nextInts(n, sc)
	result := f(pre, in, pre[0])
	printResult(result)
}

func find(x int, arr []int) int {
	for i := 0; i < len(arr); i++ {
		if arr[i] == x {
			return i
		}
	}
	panic(fmt.Errorf("not found: %d", x))
}

func f(pre []int, in []int, target int) []int {
	if len(in) == 1 {
		return in
	}

	targetIn := find(target, in)

	left := in[0:targetIn]
	shortestLeft := len(pre)
	for i := 0; i < targetIn; i++ {
		for j := 0; j < len(pre); j++ {
			if pre[j] == left[i] && j < shortestLeft {
				shortestLeft = j
			}
		}
	}
	var processedLeft []int
	if shortestLeft < len(pre) {
		processedLeft = f(pre, left, pre[shortestLeft])
	} else {
		processedLeft = make([]int, 0)
	}

	right := in[targetIn+1:]
	shortestRight := len(pre)
	for i := 0; i < len(right); i++ {
		for j := targetIn + 1; j < len(pre); j++ {
			if pre[j] == right[i] && j < shortestRight {
				shortestRight = j
			}
		}
	}
	var processedRight []int
	if shortestRight < len(pre) {
		processedRight = f(pre, right, pre[shortestRight])
	} else {
		processedRight = make([]int, 0)
	}

	return append(processedLeft, append(processedRight, target)...)
}

func nextInt(sc *bufio.Scanner) (int, error) {
	sc.Scan()
	return strconv.Atoi(sc.Text())
}

func nextInts(n int, sc *bufio.Scanner) ([]int, error) {
	rs := make([]int, n)
	for i, _ := range rs {
		x, err := nextInt(sc)
		if err != nil {
			return nil, err
		}
		rs[i] = x
	}
	return rs, nil
}

func printResult(result []int) {
	resultStr := make([]string, len(result))
	for i := 0; i < len(resultStr); i++ {
		resultStr[i] = strconv.Itoa(result[i])
	}
	fmt.Println(strings.Join(resultStr, " "))
}



Measured memory_bytes: 1120
#include <iostream>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <algorithm>
#include <bitset>
#include<iomanip>//小数点以下を精度良く表示
#include <map>
#include<set>

#include <stdio.h>
#include <math.h>
#include <stdlib.h>
#include <numeric>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
#define INF 2000000000
#define INF2 1000000000000000000
#define PI 3.1415926535
#define rep(i,n) for(int i=0;i<(n);i++)
typedef pair<int, int> P;
const ll MOD = 1000000007;
using Graph = vector<vector<int>>;

#define MAX_N 50005//ここにNの最大値を入れる
#define MAX_K 100005




int main() {
    int n;
    cin >> n;
    string s;
    cin >> s;
    int ma = 0;
    int x = 0;
    for (int i = 0; i < n; i++) {
        if (s[i] == 'I') x++;
        else x--;
        ma = max(ma, x);
    }
    cout << ma << endl;
    return 0;
}

Measured memory_bytes: 3632
#include <iostream>
#include <vector>
#include <stdio.h>
using namespace std;
const int N=0;
const int E=1;
const int S=2;
const int W=3;
const int Z=4;
int rs[5][4]={{0,1,5,4},{0,3,5,2},{0,4,5,1},{0,2,5,3},{3,1,2,4}};
struct xai{
int ds[6];
void round(int n){
int t=ds[rs[n][0]];
for(int i=0;i<3;i++){
	ds[rs[n][i]]=ds[rs[n][i+1]];
}
ds[rs[n][3]]=t;
}
xai rounds(int n){
xai e;
for(int i=0;i<6;i++)e.ds[i]=ds[i];

if(0<n){
	e.round(S);
}
if(1<n){
	e.round(E);
}
if(2<n){
	e.round(E);
}
if(3<n){
	e.round(E);
}
if(4<n){
	e.round(S);
}
return e;
}
void roundZ(){
int cs[4];
std::vector<int> vec;
for(int i=0;i<4;i++){
	vec.push_back(ds[rs[Z][i]]);
}
for(int i=0;i<4;i++){
	round(Z);
	std::vector<int> vec2;
	for(int i=0;i<4;i++){
		vec2.push_back(ds[rs[Z][i]]);
	}
	if(vec<vec2)vec=vec2;
}
for(int i=0;i<4;i++){
	ds[rs[Z][i]]=vec[i];
}
}
bool eq(xai e){
for(int i=0;i<6;i++){
	if(ds[i]!=e.ds[i])return false;
}
return true;
} 
};

int main() {
// your code goes here
xai e,e2,e3;
for(int i=0;i<6;i++){
	scanf("%d",&e.ds[i]);
}
for(int i=0;i<6;i++){
scanf("%d",&e2.ds[i]);
}
e.roundZ();
bool hit=false;
for(int i=0;i<6;i++){
e3=e2.rounds(i);
e3.roundZ();
if(e3.eq(e)==true){
	hit=true;
	break;
}
}
printf("%s\n",hit?"Yes":"No");
return 0;
}

Measured memory_bytes: 3228
#include <stdio.h>

int main(void) {
  int a, b;
  scanf("%d %d", &a, &b);
  if (a == 1) a = 14;
  if (b == 1) b = 14;
  if (a > b)
    printf("Alice\n");
  else if (b > a)
    printf("Bob\n");
  else
    printf("Draw\n");
  return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
const int maxn = 300300, mod = 1'000'000'007;
int dp[1<<3][3][maxn], n;
char s[maxn];
int solve(int msk, int gp, int p){
	if(p == n){
		return (msk>>1) == 3;
	}
	int &v = dp[msk][gp][p];
	if(v != -1) return v;
	int fr = 0, to = 1;
	if(s[p] != '?'){
		fr = to = s[p] - '0';
	}
	int ans = 0;
	for(int d = fr; d <= to; d++){
		int nmsk, ngp, np = p + 1;
		if(d == 1){
			int inv = gp % 2;
			ngp = 0;
			if(gp == 0){
				int mv = (2<<(msk&1));
				if(mv == 4){
					if(msk&2) nmsk = msk | 4;
					else nmsk = msk;
				} else {
					nmsk = msk | 2;
				}
				nmsk ^= 1;
			} else {
				nmsk = msk ^ 1;
			}
			nmsk ^= inv;
		} else {
			ngp = gp + 1;
			while(ngp >= 3) ngp -= 2;
			nmsk = msk;
		}
		ans += solve(nmsk, ngp, np);
		if(ans >= mod) ans -= mod;
	}
	return v = ans;
}
int main(){
	scanf("%s", s);
	n = strlen(s);
	s[n] = '1';
	n++;
	memset(dp, -1, sizeof(dp));
	cout << solve(0, 0, 0) << endl;
	return 0;
}




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

using namespace std;
typedef long long ll;
typedef pair<ll, ll> p_ll;

template<class T>
void debug(T itr1, T itr2) { auto now = itr1; while(now<itr2) { cout << *now << " "; now++; } cout << endl; }
#define repr(i,from,to) for (int i=(int)from; i<(int)to; i++)
#define all(vec) vec.begin(), vec.end()
#define rep(i,N) repr(i,0,N)
#define per(i,N) for (int i=(int)N-1; i>=0; i--)

const ll MOD = pow(10,9)+7;
const ll LLINF = pow(2,61)-1;
const int INF = pow(2,30)-1;

vector<ll> fac;
void c_fac(int x=pow(10,6)+10) { fac.resize(x,true); rep(i,x) fac[i] = i ? (fac[i-1]*i)%MOD : 1; }
ll inv(ll a, ll m=MOD) { ll b = m, x = 1, y = 0; while (b!=0) { int d = a/b; a -= b*d; swap(a,b); x -= y*d; swap(x,y); } return (x+m)%m; }
ll nck(ll n, ll k) { return fac[n]*inv(fac[k]*fac[n-k]%MOD)%MOD; }
ll gcd(ll a, ll b) { if (a<b) swap(a,b); return b==0 ? a : gcd(b, a%b); }
ll lcm(ll a, ll b) { return a/gcd(a,b)*b; }

struct goods { ll w, v; };

int main() {
  int N, W; cin >> N >> W;
  goods g[N]; rep(i,N) { ll w, v; cin >> w >> v; g[i] = {w,v}; }
  ll dp[N+1][W+1] = {};
  rep(i,N) rep(j,W+1) {
    if (j<g[i].w) dp[i+1][j] = dp[i][j];
    else dp[i+1][j] = max(dp[i][j], dp[i][j-g[i].w]+g[i].v);
  }
  ll result = dp[N][W];
  cout << result << endl;
  return 0;
}

Measured memory_bytes: 79104
#include <iostream>
using namespace std;
int main() {
  int A,B,sum,sub;
  char op;
  cin>>A>>op>>B;
  if(op=='+'){
    sum=A+B;
    cout<<sum;
  }
  else{
    sub=A-B;
    cout<<sub;
  }
return 0 ;
}

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

using namespace std;

const int md = (int) 1e9 + 7;
const int N = 5555;

char s[N];
int dp[N][N];

inline void add(int& a, int b) {
  a += b;
  if (a >= md) {
    a -= md;
  }
}

inline void sub(int& a, int b) {
  a -= b;
  if (a < 0) {
    a += md;
  }
}

inline int mul(int a, int b) {
  return a * 1LL * b % md;
}

inline int power(int a, int b) {
  int ret = 1;
  while (b > 0) {
    if (b & 1) {
      ret = mul(ret, a);
    }
    a = mul(a, a);
    b >>= 1;
  }
  return ret;
}

inline int inv(int a) {
  return power(a, md - 2);
}

int main() {
  int n;
  scanf("%d %s", &n, s);
  int m = strlen(s);
  dp[0][0] = 1;
  for (int i = 1; i <= n; ++i) {
    for (int j = 0; j <= i; ++j) {
      dp[i][j] = (j == 0 ? dp[i - 1][j] : mul(dp[i - 1][j - 1], 2));
      add(dp[i][j], dp[i - 1][j + 1]);
    }
  }
  int ans = mul(dp[n][m], inv(power(2, m)));
  printf("%d\n", ans);
  return 0;
}

Measured memory_bytes: 107136
package main

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

var sc *bufio.Scanner

const BufferSize = 1024

func nextInt() int {
	if !sc.Scan() {
		panic(nil)
	}
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

var production bool

func debugf(format string, v ...interface{}) {
	if !production {
		fmt.Printf(format, v...)
	}
}

func answer(reader io.Reader, writer io.Writer) {
	sc = bufio.NewScanner(reader)
	buf := make([]byte, BufferSize)
	sc.Buffer(buf, 1e+6)
	sc.Split(bufio.ScanWords)
	w := nextInt()
	h := nextInt()
	x := nextInt()
	y := nextInt()

	ans := float64(w*h) / float64(2)
	flag := 0
	if x*2 == w && y*2 == h {
		flag = 1
	}

	_, _ = fmt.Fprintf(writer, "%f %d", ans, flag)
}

func main() {
	production = true
	answer(os.Stdin, os.Stdout)
}


Measured memory_bytes: 640
a,b,c = [int(x) for x in input().split()]
import math
si = math.sin(math.radians(c))
co = math.cos(math.radians(c))
s = a*b*si/2
l = a + b + (a**2 + b**2 - 2*a*b*co)**(1/2)
h = 2*s/a 
print("{:.6f}".format(s))
print("{:.6f}".format(l))
print("{:.6f}".format(h))



Measured memory_bytes: 5728
n = int(input())
heights = [int(ch) for ch in input().split()]
ans = 0
dict = {}
for i in range(len(heights)):
    key = i+heights[i]
    if key in dict.keys():
        dict[key] += 1
    else:
        dict[key] = 1
for i in range(len(heights)):
    key = i-heights[i]
    if key in dict.keys():
        ans+=dict[key]
print(ans)



Measured memory_bytes: 111808
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {
	static StringBuilder builder = new StringBuilder();

	public static void main(String[] args) throws NumberFormatException,
			IOException {
		BufferedReader reader = new BufferedReader(new InputStreamReader(
				System.in));
		int n = Integer.parseInt(reader.readLine());
		int[] a = new int[n];
		for (int i = 0; i < n; i++) {
			a[i] = Integer.parseInt(reader.readLine());
		}
		shellSort(a, n);
		for (int i = 0; i < n; i++) {
			builder.append(a[i]).append("\n");
		}
		System.out.print(builder);
	}

	private static void shellSort(int[] a, int n) {
		int[] g = new int[20];
		int m = 0;
		/*
		 * for (int i = 0; i < n; i = i * 3 + 1) { for (int j = m; 0 < j; j--) {
		 * g[j] = g[j - 1]; } g[0] = i; m++; } if (m == 0) { g[0] = 1; m = 1; }
		 */
		for (int i = 1; i <= n; i = i * 2 + 1) {
			g[m] = i;
			m++;
		}

		builder.append(m).append("\n");

		m--;
		int cnt = 0;
		for (int i = m; i >= 0; i--) {
			if (i != m)
				builder.append(" ");
			builder.append(g[i]);
			cnt += insertionSort(a, n, g[i]);
		}
		builder.append("\n").append(cnt).append("\n");
	}

	private static int insertionSort(int[] a, int n, int g) {
		int cnt = 0;
		for (int i = g; i < n; i++) {
			int key = a[i];
			int j = i - g;
			while (j >= 0 && a[j] > key) {
				a[j + g] = a[j];
				j = j - g;
				cnt++;
			}
			a[j + g] = key;
		}
		return cnt;
	}
}

Measured memory_bytes: 116256
#include<stdio.h>

int main(){

  int flag,a[100],i,num,swap,count=0;
  
  scanf("%d",&num);
  for(i = 0; i < num; i++){
    scanf("%d",&a[i]);
  }

  flag=1;
  while(flag){
    flag=0;

    for(i = num-1; i >= 1; i--){
      if(a[i]<a[i-1]){
	swap  =  a[i];
	a[i]  =  a[i-1];
	a[i-1] = swap;
	count ++;
	flag = 1;
      }
    }

  }
  for(i = 0; i < num-1; i++){
    printf("%d ",a[i]);
  }
  printf("%d\n",a[i]);
  printf("%d\n",count);
  return 0;
}

Measured memory_bytes: 1028
#include <cstdio>
#include <iostream>

using namespace std;

int main(){
	int N,V[20],C,ans=0;

	scanf("%d",&N);
	for(int i=0;i<N;i++){
		scanf("%d",&V[i]);
	}
	for(int i=0;i<N;i++){
		scanf("%d",&C);
		if(V[i]>C){
			ans+=V[i]-C;
		}
	}
	cout<<ans;
	
	return 0;	

}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <cmath>
using namespace std;

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

void printvector(vector<int> v) {
    REP(i,v.size()-1) {
        cout << v[i] << " ";
    }
    cout << v[v.size()-1] << endl;
}

void insertsort(vector<int> &v) {
    for (int i = 1; i < v.size(); i++) {
        printvector(v);
        int w = v[i];
        int j = i - 1;
        while (j >= 0 && v[j] > w) {
            v[j+1] = v[j];
            j--;
        }
        v[j+1] = w;
    }
    printvector(v);
}

int main() {
    int N;
    cin >> N;
    vector<int> v;
    REP(i,N) {
        int j;
        cin >> j;
        v.push_back(j);
    }
    insertsort(v);
    return 0;
}

Measured memory_bytes: 1220
(defun main ()
  (let* ((x (read))
         (n (read))
         (pos (make-array `(101) :initial-element nil))
         (neg (make-array `(101) :initial-element nil))
         (just nil))
    ;; read
    (when (= n 0)
      (format t "~A~%" x)
      (return-from main))
    (loop :for i :from 1 :to n
          :do (let ((p (read)))
                (cond ((= p x)
                       (setf just t))
                      ((> p x)
                       (setf (aref pos (- p x)) t))
                      ((< p x)
                       (setf (aref neg (- x p)) t)))))
    ;;
    (unless just
      (format t "~A~%" x)
      (return-from main))
    ;;    
    (loop :for i :from 1 :to 100
          :do (cond ((null (aref neg i))
                     (format t "~A~%" (- x i))
                     (return-from main))
                    ((null (aref pos i))
                     (format t "~A~%" (+ x i))
                     (return-from main))))))
(main)


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

lli n;

int main(void){
	cin >> n;
	vector<lli> a(n), b(n);
	lli suma, sumb;
	suma = sumb = 0;
	rep(i, n){
		cin >> a[i];
		suma += a[i];
	}
	rep(i, n){
		cin >> b[i];
		sumb += b[i];
	}
	lli ans = 0;
	if(sumb > suma) ans = -1;
	else{
		vector<lli> sub;
		lli comp = 0;
		rep(i, n){
			if(a[i] < b[i]){
				ans++;
				comp+=b[i]-a[i];
			}
			if(a[i] > b[i]){
				sub.push_back(a[i]-b[i]);
			}
		}
		sort(sub.begin(), sub.end(), greater<lli>());
		lli ssub = 0;
		rep(i, sub.size()){
			if(ssub >= comp) break;
			ssub += sub[i];
			ans++;
		}
	}
	cout << ans << endl;
	return 0;
}


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

using namespace std;

#define loop(i, n) for(int i = 0;i < int(n);i++)
#define rloop(i, n) for(int i = int(n);i >= 0;i--)
#define range(i, a, b) for(int i = int(a);i <= int(b);i++)
#define SZ(c) int(c.size())
#define ALL(c) c.begin(), c.end()
#define RALL(c) c.rbegin(), c.rend()
#define PI acos(-1)
#define pb push_back
#define mp make_pair
#define fr first
#define sc second
#define sfi1(v) scanf("%d",&v)
#define sfi2(v1, v2) scanf("%d %d",&v1,&v2)
#define sfi3(v1, v2, v3) scanf("%d %d %d",&v1,&v2,&v3)
#define sfll1(v) scanf("%I64d",&v);
#define sfll2(v1, v2) scanf("%I64d %I64d",&v1,&v2)
#define sfll3(v1, v2, v3) scanf("%I64d %I64d %I64d",&v1,&v2,&v3)
#define endl '\n'

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

ll val;
ll A, B;
pair<int, long long> dp[66][2][2];

int get(ll x, int bit) {
    return (x >> bit) & 1;
}

pair<int, ll> better(pair<int, ll> x, pair<int, ll> y) {
    if (x.first && !y.first)return x;
    if (!x.first && y.first)return y;
    return x.second < y.second ? x : y;
}

pair<int, ll> solve(int bit, int b, int g) {
    if (bit == 61)return {b == false && g == false, 0};
    pair<int, ll> &ret = dp[bit][b][g];
    if (~ret.fr)return ret;
    ret = {0, 0};
    int curA = get(A, bit), curB = get(B, bit), curVal = get(val, bit);
    int nxtB = 0, nxtG = 0;
    if (b) {
        if (curA) {
            curA = 0;
            nxtB = 0;
        } else {
            curA = 1;
            nxtB = 1;
        }
    }

    if (g) {
        if (curB) {
            curB = 0;
            nxtG = 1;
        } else {
            curB = 1;
            nxtG = 0;
        }
    }

    // X is zero
    if ((curA ^ curB) == curVal) {
        ret = better(ret, solve(bit + 1, nxtB, nxtG));
    }

    //X is one
    if (curA) {
        curA = 0;
        //    } else if (nxtB) {
        //check here
    } else {
        curA = 1;
        nxtB = 1;
    }

    if (curB) {
        curB = 0;
        // what if nxtB is true
        nxtG = 1;
    } else {
        curB = 1;
    }

    if ((curA ^ curB) == curVal) {
        ret = better(ret, {solve(bit + 1, nxtB, nxtG).fr, solve(bit + 1, nxtB, nxtG).sc | (1LL << bit)});
    }

    return ret;
}

int main() {

#ifndef ONLINE_JUDGE
    //freopen("in.in", "r", stdin);
    //freopen("out.in", "w", stdout);
#endif
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);


    int n;
    cin >> n;
    cin >> A >> B;
    ll tmp;
    range(i, 3, n) {
        cin >> tmp;
        val ^= tmp;
    }

    memset(dp, -1, sizeof dp);
    if (solve(0, 0, 0).fr && solve(0, 0, 0).sc != A) {
        cout << solve(0, 0, 0).sc << endl;
    } else {
        cout << -1 << endl;
    }


    return 0;
}


Measured memory_bytes: 3640
#include<bits/stdc++.h>
#define pb push_back
#define rep(a,b,c) for(int a=(int)b;a<(int)c;a++)
#define repk(a,b,c,k) for(int a=(int)b;a<(int)c;a+=(int)k)
#define comeback std::ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define mod 1000000007
#define int long long int
#define pii pair<int,int>
#define ful(a) a.begin(),a.end()
#define ub upper_bound
#define lb lower_bound
#define ff first
#define ss second
using namespace std;
int em(int x,int n)
{
    if(n==0)
    return 1;
    else if(n%2==0)
    return em((x%mod*x%mod)%mod,n/2);
    else
    return (x%mod*em((x%mod*x%mod)%mod,(n-1)/2))%mod;
}
signed main()
{
	comeback
	/*#ifndef ONLINE_JUDGE
		freopen("input.txt","r",stdin);
		freopen("output1.txt","w",stdout);
	#endif*/
         int i,j,k;
         int t;
         cin>>t>>k;
         int a[t+1];
         int dp[t+1];
         for(i=0;i<=t;i++)
         	dp[i]=1e18;
         dp[1]=0;
         for(i=1;i<=t;i++)
         	cin>>a[i];
         for(i=2;i<=t;i++){
         	for(j=1;j<=k&&j<i;j++){
         		dp[i]=min(dp[i],dp[i-j]+abs(a[i-j]-a[i]));
         	}
         }
         cout<<dp[t];
     
}

Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define mod 1e9+7
int main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int n;
	cin >> n;
	int a[n], b[n], c[n];
	for(int i = 0; i< n; i++)
		cin >> a[i] >> b[i] >> c[i];
	int dp[n][3];
	dp[0][0] = a[0];
	dp[0][1] = b[0];
	dp[0][2] = c[0];
	for(int i = 1; i < n; i++){
		dp[i][0] = a[i] +  max(dp[i - 1][1], dp[i - 1][2]);
		dp[i][1] = b[i] + max(dp[i - 1][0], dp[i - 1][2]);
		dp[i][2] = c[i] + max(dp[i - 1][0], dp[i - 1][1]);
	}
	cout<<max(dp[n - 1][0] , max(dp[n - 1][1], dp[n - 1][2]));
}

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

int main(){
    string S;
    int K;
    cin >> S >> K;
    for(int i=0;i<S.size();i++){
        if(S[i]=='a')continue;
        if(S[i]+K>'z'){
            K -= 'z' - S[i] + 1;
            S[i]='a';
        }
    }
    int n = S.size();
    if(K>0){
        K%=26;
        while(K>0){
            if(S[n-1]=='z'){
                S[n-1]='a';
            }else{
                S[n-1] = S[n-1]+1;
            }
            K--;
        }
    }
    cout << S << endl;
    return 0;
}

Measured memory_bytes: 3748
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;

namespace D
{
    public class Program
    {
        static void Main(string[] args)
        {
            var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
            Console.SetOut(sw);
            Solve();
            Console.Out.Flush();
        }

        public static void Solve()
        {
            var HW = Console.ReadLine().Trim().Split(' ').Select(int.Parse).ToArray();
            var H = HW[0];
            var W = HW[1];
            var answer = H * W;
            var grid = new bool[H][];
            for (var i = 0; i < H; i++)
            {
                grid[i] = new bool[W];
                var s = Console.ReadLine();
                for (var j = 0; j < s.Length; j++)
                {
                    grid[i][j] = s[j] == '.';
                    if (!grid[i][j]) answer--;
                }
            }

            var queue = new Queue<Tuple<int, int>>();
            queue.Enqueue(new Tuple<int, int>(0, 0));
            var depths = new int[H][].Select(x => x = Enumerable.Repeat(-1, W).ToArray()).ToArray();
            depths[0][0] = 0;
            while (queue.Any())
            {
                var current = queue.Dequeue();
                var x = current.Item1;
                var y = current.Item2;
                var nextDir = new List<Tuple<int, int>>();
                if (x > 0 && grid[y][x - 1]) nextDir.Add(new Tuple<int, int>(x - 1, y));
                if (x < W - 1 && grid[y][x + 1]) nextDir.Add(new Tuple<int, int>(x + 1, y));
                if (y > 0 && grid[y - 1][x]) nextDir.Add(new Tuple<int, int>(x, y - 1));
                if (y < H - 1 && grid[y + 1][x]) nextDir.Add(new Tuple<int, int>(x, y + 1));

                foreach (var next in nextDir)
                {

                    var nx = next.Item1;
                    var ny = next.Item2;

                    if (depths[ny][nx] != -1) continue;
                    depths[ny][nx] = depths[y][x] + 1;
                    queue.Enqueue(next);
                }
            }
            if (depths[H - 1][W - 1] == -1)
            {
                Console.WriteLine(-1);
                return;
            }
            answer -= depths[H - 1][W - 1] + 1;
            Console.WriteLine(answer);
        }
    }
}

Measured memory_bytes: 13652
#include<stdio.h>
#include<string.h>
#include<math.h>
int n;
int count = 0;
int answer = 0;
int main() {
	scanf("%d",&n);
	for (int i = 1; i <= n; i+=2) {
		count = 0;
		for (int j = 1; j <= i; j++) {
			if (i%j == 0) {
				count++;
			}
		}
		if (count == 8) {
			answer++;
		}
		count = 0;
	}
	printf("%d", answer);
}

Measured memory_bytes: 128
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.StringTokenizer;

public class Main {
    public static void main(String args[]) {
        FastReader sc = new FastReader();
        int n = sc.nextInt();
        int[] as = new int[n];
        for (int i = 0; i < n; i++) {
            as[i] = sc.nextInt();
        }
        List<Integer> xs = new ArrayList<>();
        for (int i = 0; i < n; i++) xs.add(i);
        xs.sort((x, y) -> as[x] - as[y]);

        int central = n / 2 - 1;
        for (int i = 0; i < n; i++) {
            if (as[i] <= as[xs.get(central)]) {
                System.out.println(as[xs.get(central + 1)]);
            }
            else {
                System.out.println(as[xs.get(central)]);
            }

        }
    }

    static class FastReader
    {
        BufferedReader br;
        StringTokenizer st;

        public FastReader()
        {
            br = new BufferedReader(new
                    InputStreamReader(System.in));
        }

        String next()
        {
            while (st == null || !st.hasMoreElements())
            {
                try
                {
                    st = new StringTokenizer(br.readLine());
                }
                catch (IOException e)
                {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

        int nextInt()
        {
            return Integer.parseInt(next());
        }

        long nextLong()
        {
            return Long.parseLong(next());
        }

        double nextDouble()
        {
            return Double.parseDouble(next());
        }

        String nextLine()
        {
            String str = "";
            try
            {
                str = br.readLine();
            }
            catch (IOException e)
            {
                e.printStackTrace();
            }
            return str;
        }
    }
}


Measured memory_bytes: 98836
import java.util.*;
import java.util.function.*;
import java.lang.*;
import java.io.*;


public class Main {

    static int magic(int A, int B, int C){
        if(B>=C) return 1 + magic(A, B, 2*C);
        if(A>=B) return 1 + magic(A, 2*B, C) ;
        return 0;
    }
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int A = sc.nextInt();
        int B = sc.nextInt();
        int C = sc.nextInt();
        int K = sc.nextInt();
        System.out.println(magic(A,B,C)<=K ? "Yes" : "No");
    }
}


Measured memory_bytes: 35620
n,k = map(int,input().split())
r,s,p = map(int,input().split())
t = input()
ans = 0
dict = {"r":p,"s":r,"p":s}

dp = [[0,0] for i in range(n+1)]

for i in range(n):
    if i >= k and t[i] == t[i-k] and dp[i+1-k][1] == 1:
        dp[i+1][0] = dp[i][0]
        dp[i+1][1] = 0
    elif i >= k and t[i] == t[i-k]:
        dp[i+1][0] = dp[i][0] + dict[t[i]]
        dp[i+1][1] = 1
    else:
        dp[i+1][0] = dp[i][0] + dict[t[i]]
        dp[i+1][1] = 1

print(dp[n][0])

Measured memory_bytes: 16532
#include<stdio.h>
#include<iostream>
#include<math.h>
#include<algorithm>
#include<string.h>
#define ll long long
using namespace std;
ll N;
int main(){
	ll xxx=0;
	scanf("%lld",&N);
	ll S=N;
	while(S){
		xxx+=S%10;
		S/=10;
	}
	if(N%xxx==0)printf("Yes");
	else printf("No");
	return 0;
}

Measured memory_bytes: 256
/*
  AOJ 2272
  Title:Cicada
  @kankichi573
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <float.h>
#include <stdlib.h>
#include <limits.h>
#define min(x,y) (((x)<(y))?(x):(y))

int H,W;
char ban[50][51];
int acc[50][50];

main()
{
  int i,j,s;
  
  scanf("%d %d",&H,&W);
  for(i=0;i<H;i++)
    {
      scanf("%s",&ban[i][0]);
      for(j=0;j<W;j++)
       ban[i][j] -= '0';
    }
  
  for(j=W-1,s=0;j>=0;j--)
    {
      s += ban[H-1][j];
      acc[H-1][j]=s;
    }
  for(i=H-2,s=acc[H-1][W-1];i>=0;i--)
    {
      s += ban[i][W-1];
      acc[i][W-1]=s;
      for(j=W-2;j>=0;j--)
	acc[i][j]=ban[i][j]+min(acc[i+1][j],acc[i][j+1]);
    }
  printf("%d\n",acc[0][0]);

  return(0);
}

Measured memory_bytes: 608
#include <iostream>
#include <vector>

using namespace std;

typedef long long ll;

void m_max(ll& a, ll b)
{
    if (a < b) a = b;
}

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

    vector< vector<int> > a(n, vector<int>(3));
    for (int i = 0; i < n; ++i)
        for (int j = 0; j < 3; ++j)
            cin >> a[i][j];

    vector< vector<ll> > dp(n+1, vector<ll>(3, 0));
    for (int i = 0; i < n; ++i) {
        for (int j = 0; j < 3; ++j) {
            for (int k = 0; k < 3; ++k) {
                if (j != k)
                    m_max(dp[i+1][k], dp[i][j] + a[i][k]);
            }
        }
    }
    
    ll ans = 0;
    for (int i = 0; i < 3; ++i) m_max(ans, dp[n][i]);
    cout << ans << endl;

    return 0;
}



Measured memory_bytes: 11136
#include <iostream>
    #include <string>
    #include <algorithm>
    #include <math.h>
    using namespace std;
     
    int main() {
    	string s[100], res="";
    	int n,l;
    	cin >> n >> l;
    	for (int i = 0; i < n; ++i) {
    		cin >> s[i];
    	}
    	sort(s, s + n);
     
    	for (int i = 0; i < n; ++i) {
    		res += s[i];
    	}
    	cout << res << endl;
     
    	return 0;
    }

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main()
{
  int n;
  cin>>n;
  int arr[n];
  for(int i=0;i<n;i++)
    arr[i]=0;
  for(int i=0;i<n-1;i++)
  {
    int a;
    cin>>a;
    a--;
    arr[a]++;
  }
  for(int i=0;i<n;i++)
    cout<<arr[i]<<"\n";
  
}


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


int main() {
  cout << fixed << setprecision(10);
  int N;cin>>N;
  vector<double> A(N);
  for(int i=0;i<N;i++) cin>>A.at(i);
  double ans=0;
  double X;
  for(int i=0;i<N;i++){
    X=1/A.at(i);
    ans +=X;
  }
  double Ans=1/ans;
  cout<<Ans<<endl;
}




Measured memory_bytes: 3804
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int,int>;
#define rep(i,n) for(ll i = 0; i < (ll)(n); i++)
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
const ll INF = 1LL << 60;
int main(){
    ll x; cin >> x;
    ll ans = 0;
    ans += x / 500 * 1000;
    ans += x % 500 / 5 * 5;
    cout << ans << endl;
    return 0;
}

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

int main()
{
    long long int h,w,ans;
    cin>>h>>w;
    ans=(h*w);
    if(h==1||w==1)
        cout<<1;
    else if(ans%2)
        cout<<(ans/2)+1;
    else
        cout<<ans/2;
    return 0;
}



Measured memory_bytes: 3608
fun main(args: Array<String>) {
    val N = readInputLine().toInt()
    val S = Array(N) { readInputLine().toCharArray() }

    val charCnt = IntArray('z' - 'a' + 1)

    for (i in 0 until N) {
        for (j in 0 until N) {
            charCnt[S[i][j] - 'a']++
        }
    }

    var oddCnt = 0

    for (i in 0 until ('z' - 'a' + 1)) {
        if (charCnt[i] % 2 != 0) {
            oddCnt++
        }
    }

    if (oddCnt > N) {
        println(0)
        return
    }

    var ans = 0

    for (A in 0..0) {
        for (B in 0 until N) {
            var ok = true
            for (i in 0 until N) {
                for (j in 0..i) {
                    if (S[(i + A) % N][(j + B) % N] != S[(j + A) % N][(i + B) % N]) {
                        ok = false
                        break
                    }
                }
                if (!ok) {
                    break
                }
            }
            if (ok) {
                ans += N
            }
        }
    }

    println(ans)
}

fun readInputLine(): String {
    return readLine()!!
}


Measured memory_bytes: 34624
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds;
using namespace std;
typedef tree<pair<int,int>,null_type,less<pair<int,int>>,rb_tree_tag,tree_order_statistics_node_update> oset;
#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
	*this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
using ll = long long;

void test_case(){
	int n; cin >> n;
	cout<<(n+1)/2<<"\n";
	
}
 
int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	int T=1;
	//~ cin >> T;
	while(T--){
		test_case();
	}
	return 0;
}


Measured memory_bytes: 3648
#include<iostream>
#include<string>
#include<algorithm>	
#include<cmath>
using namespace std;
int main() {
	long long n, a, b = 0, ans = 0; cin >> n;
	int test[223456] = { 0 };
	for (int h = 0; h < n; h++) {
		cin >> a; test[h] = a;
		if (h == 0 && a != 0) {
			cout << -1 << endl; cin >> n; return 0;
		}
		if (test[h] > test[h - 1] + 1 && h != 0) {
			cout << -1 << endl; cin >> n; return 0;
		}
		if (b == 0) {
			b = test[h];
		}
		else if (test[h - 1] + 1 == test[h]) {
			b = test[h];
		}
		else {
			ans += b; b = test[h];
		}
	}
	ans += b;
	cout << ans << endl;
	cin >> n;
}

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

#define ll long long
#define vecll vector<long long>
#define vec2ll vector<vector<long long>>
#define vecpairll vector<pair<long long,long long>>
#define forll(s,a,b) for(long long s = a;s < b;s++)
#define forllde(s,a) for(long long s = a;s > 0;s--)


int main()
{
  ll n, m, k;
  cin >> n >> m >> k;
  forll(i, 0, n + 1){
	forll(j, 0, m + 1){
	  if (i * m + j * n - 2 * i * j == k){
		cout << "Yes" << endl;
		return 0;
	  }
	}
  }
  cout << "No" << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define FAST_IO   ios::sync_with_stdio(0),cin.tie(0),cout.tie(0)
#define Relocate freopen("./in.txt","r",stdin),freopen("./out.txt","w",stdout)
#define up(mi,a,b) for(mi=a;mi<=b;++mi)
#define down(mi,b,a) for(mi=b;mi>=a;--mi)
#define mfill(a,v) memset(a,v,sizeof(a))
#define INF 0x3f3f3f3f
#define MAX 200005
#define v_n 5005
#define LL long long
#define ULL unsigned long long 
#define e_n 50005
#define eps 0.000000001
#define Blen 32
const LL MOD = 998244353;
using namespace std;
int H, W,N;
int sx, sy;
string a;
string b;
int sum[MAX][4];
int sum2[MAX][4];
bool inR(int x, int y)
{
	return x >= 1 && x <= H && y >= 1 && y <= W;
}
void Get(int sum[][4])
{
	int i;
	down(i, N, 1)
	{
		sum[i][0] = sum[i + 1][0] + (a[i] == 'L');
		sum[i][1] = sum[i + 1][1] + (a[i] == 'R');
		sum[i][2] = sum[i + 1][2] + (a[i] == 'U');
		sum[i][3] = sum[i + 1][3] + (a[i] == 'D');
	}
}
int main(void)
{
	int i, j, k;
	FAST_IO;
	//Relocate;
	cin >> H >> W >>N>> sx >> sy;

	cin >> a >> b;
	a = " " + a;
	b = " " + b;
	Get(sum);
	Get(sum2);
	i = 1;
	while (N--)
	{
		if (a[i] == 'L' || a[i] == 'R')
		{
			if (sum[i][0]-sum2[i][1] - (sy - 1) > sum[i][1]-sum2[i][0] - (W - sy))
			{
				if (a[i] == 'L')
				{
					sy--;
				}
			}
			else
			{
				if (a[i] == 'R')
				{
					sy++;
				}
			}
		}
		else 
		{
			if (sum[i][2]- sum2[i][3] - (sx - 1) > sum[i][3]- sum2[i][2] - (H - sx))
			{
				if (a[i] == 'U')
				{
					sx--;
				}
			}
			else
			{
				if (a[i] == 'D')
				{
					sx++;
				}
			}
		}
		if (!inR(sx, sy))
		{
			cout << "NO\n";
			return 0;
		}
		if (b[i] == 'L' || b[i] == 'R')
		{
			if (sum[i+1][0]-sum2[i][1] - (sy - 1) > sum[i+1][1]-sum2[i][0] - (W - sy))
			{
				if (b[i] == 'R')
				{
					sy++;
				}
			}
			else
			{
				if (b[i] == 'L')
				{
					sy--;
				}
			}
		}
		else
		{
			if (sum[i+1][2]-sum2[i][3] - (sx - 1) > sum[i+1][3]-sum2[i][2] - (H - sx))
			{
				if (b[i] == 'D')
				{
					sx++;
				}
			}
			else
			{
				if (b[i] == 'U')
				{
					sx--;
				}
			}
		}
		if (!inR(sx, sy))
		{
			cout << "NO\n";
			return 0;
		}
			i++;

	}
	cout << "YES\n";
}

Measured memory_bytes: 6928
#define _USE_MATH_DEFINES
#include  <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
#include <string>
#include<math.h>
#include<iomanip>
#include<stdio.h>
#include <stdlib.h>
#include<stdio.h>
#include <queue>
#include<map>
#include <sstream>
#include<set>
#include<stack>
#include<time.h>
typedef long long int ll;
//#include<bits/stdc++.h>


using namespace std;



int main()
{

   
    int n, m;
    cin >> n >> m;

    int ans = 0;
    ans += n * (n - 1)/2 + m * (m - 1)/2;
    cout << ans << endl;


    return 0;

}

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

int main(){
  string S;
  cin >> S;
  int cnt = 0;
  for(int i = 0;i < S.size();i++){
    if(S[i] == 'o'){
      cnt++;
    }
  }

  if(cnt + 15 - S.size() >= 8){
    cout << "YES" << endl;
  }
  else cout << "NO" << endl;

  return 0;
}


Measured memory_bytes: 256
while 1:
    n,p=map(int,input().split())
    if n==p==0:break
    p2=p
    stone=[0]*n
    pos=0
    while 1:
        if p==0:
            p+=stone[pos]
            stone[pos]=0
        else:
            p-=1
            stone[pos]+=1
        if stone[pos]==p2:break
        pos=[pos+1,0][pos+1==n]
    print(pos)


Measured memory_bytes: 5596
#include<iostream>
#include<algorithm>
using namespace std;
int main() {
	long long int a, b;
	int n,m;
int x=1;
int zz=2;
x=max(x,zz);
	cin >> n;
	a = 0;
	for (int i = 1; i <= n; i++) {
		cin >> m;
		a = a + m;
	}
	cout << a / n << endl;
}


Measured memory_bytes: 3076
#include <bits/stdc++.h>
#define dum(x) cout<<#x<<'='<<x<<endl
#define ll long long
using namespace std;

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

  int NMdiff = abs(n - m);
  if (NMdiff != 0 && NMdiff != 1) {
    cout << 0 << endl;
    return 0;
  }

  ll np = 1, mp = 1;
  ll mod = 1000000007;

  for (int i = 1; i <= n; i++) {
    np = np * i % mod;
  }
  for (int i = 1; i <= m; i++) {
    mp = mp * i % mod;
  }

  if (NMdiff == 1) {
    cout << np * mp % mod << endl;
    return 0;
  }
  if (NMdiff == 0) {
    cout << np * mp % mod * 2 % mod << endl;
    return 0;
  }

}

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

using namespace std;

#define fst(t) std::get<0>(t)
#define snd(t) std::get<1>(t)
#define thd(t) std::get<2>(t)
#define unless(p) if(!(p))
#define until(p) while(!(p))

using ll = long long;
using P = std::tuple<int,int>;

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

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

    int A[3];

    for(int i=0;i<3;++i){
        std::cin >> A[i];
    }

    sort(A, A+3);
    
    if(A[0] != A[1]){
        std::cout << A[0] << std::endl;
    }else{
        std::cout << A[2] << std::endl;
    }
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
#include<cstdio>
using namespace std;
typedef long long ll;
int main()
{
    ll n,q;
    scanf("%lld%lld",&n,&q);
    while(q--)
    {
        ll v1,v2;
        scanf("%lld%lld",&v1,&v2);
        if(n == 1)
        {
            printf("%lld\n",min(v1,v2));
            continue;
        }
        if(v1 == 1)
            v2 = v1;
        else if(v2 == 1)
            v1 = v2;
        while(v1 != v2)
        {
            if(v1 > v2)
                v1 = (v1+n-2)/n;
            else
                v2 = (v2+n-2)/n;
        }
        printf("%lld\n",v1);
    }
    return 0;
}


Measured memory_bytes: 1280
def f(n):
  D={}
  A=[]
  for _ in range(n):
    a,b,c=map(int,raw_input().split(' '))
    if D.has_key(a): D[a]+=b*c
    else:
      D[a]=b*c
      A.append(a)
  B=[i for i in A if D[i]>=1e6]
  if B==[]: B=["NA"]
  return B

while 1:
  n=input()
  if n==0:break
  for e in f(n): print e

Measured memory_bytes: 4352
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
using namespace std;
typedef long long int ll;
typedef pair<int,int> P;
#define yn {puts("Yes");}else{puts("No");}
#define MAX_N 200005

vector<int> G[MAX_N];

int main() {
    int n, m;
    cin >> n >> m;
    int h[n];
    rep(i,n)cin >> h[i];

    rep(i,m){
        int a, b;
        cin >> a >> b;
        a--; b--;
        G[a].push_back(b);
        G[b].push_back(a);
    }

    int ans = 0;
    rep(i,n){
        int ma = -1;
        rep(j,G[i].size())ma = max(ma, h[G[i][j]]);
        if(h[i] > ma)ans++;
    }

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




Measured memory_bytes: 11440
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int N, A, B;
    cin >> N >> A >> B;
    for(A; A <= B; A++) {
        if(A % N == 0) {
            cout << "OK";
            return 0;
        }
    }
    cout << "NG";
}


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

int main(){
    int N,M;
  long long suma,sumb,sumc,sum,ans;
  suma=0;
  sumb=0;
  sumc=0;
  sum=0;
  ans=0;
    cin>>N>>M;
  vector<long long>a(N),b(N),c(N),s(N);
    for(int i = 0; i < N; i++){
        cin>>a[i]>>b[i]>>c[i];
    }
  for(int i=0;i<N;i++){
     s[i]=a[i]+b[i]+c[i];
  }
  sort(s.begin(),s.end());
  for(int i=0;i<M;i++){
    sum+=s[N-1-i];
  }
  ans=max(ans,sum);
    sum=0;
    for(int i=0;i<N;i++){
    s[i]=a[i]-b[i]+c[i];
  }
   sort(s.begin(),s.end());
  for(int i=0;i<M;i++){
    sum+=s[N-1-i];
  }
  ans=max(ans,sum);
    sum=0;
        for(int i=0;i<N;i++){
    s[i]=a[i]+b[i]-c[i];
  }
   sort(s.begin(),s.end());
  for(int i=0;i<M;i++){
    sum+=s[N-1-i];
  }
  ans=max(ans,sum);
    sum=0;

    for(int i=0;i<N;i++){
   s[i]=-1*a[i]+b[i]+c[i];
  }
   sort(s.begin(),s.end());
  for(int i=0;i<M;i++){
    sum+=s[N-1-i];
  }
  ans=max(ans,sum);
    sum=0;
    for(int i=0;i<N;i++){
    s[i]=-1*a[i]-b[i]-c[i];
  }
    sort(s.begin(),s.end());
  for(int i=0;i<M;i++){
    sum+=s[N-1-i];
  }
  ans=max(ans,sum);
    sum=0;
    for(int i=0;i<N;i++){
    s[i]=-1*a[i]-b[i]+c[i];
  }
  sum=abs(suma)+abs(sumb)+abs(sumc);
  ans=max(ans,sum);
    sum=0;
  suma=0;
  sumb=0;
  sumc=0;
    for(int i=0;i<N;i++){
    s[i]=-1*a[i]+b[i]-c[i];
  }
   sort(s.begin(),s.end());
  for(int i=0;i<M;i++){
    sum+=s[N-1-i];
  }
  ans=max(ans,sum);
    sum=0;
    for(int i=0;i<N;i++){
    s[i]=a[i]-b[i]-c[i];
  }
  sort(s.begin(),s.end());
  for(int i=0;i<M;i++){
    sum+=s[N-1-i];
  }
  ans=max(ans,sum);
    cout << ans << endl;
}


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

namespace atcoder1234
{
    class Program
    {
        static void Main(string[] args)
        {
            string a = Console.ReadLine();
            int[] vs = new int[a.Length];
            for (int i = 0; i < a.Length; i++)
            {
                string a1 = a[i].ToString();
                int a2 = int.Parse(a1);
                vs[i] = a2;
            }
            int vs2 = vs.Sum();
            if (vs2 % 9 == 0)
            {
                Console.WriteLine("Yes");
            }
            else { Console.WriteLine("No"); }
        }
    }
}

Measured memory_bytes: 34008
a = list(map(int, input().split()))

ans = 10**9

ans = min(ans, abs(a[1]-a[2]) + abs(a[0]-a[1]))
ans = min(ans, abs(a[0]-a[2]) + abs(a[0]-a[1]))
ans = min(ans, abs(a[0]-a[1]) + abs(a[0]-a[2]))
ans = min(ans, abs(a[2]-a[1]) + abs(a[0]-a[2]))
ans = min(ans, abs(a[1]-a[0]) + abs(a[1]-a[2]))
ans = min(ans, abs(a[2]-a[0]) + abs(a[1]-a[2]))
print(ans)

Measured memory_bytes: 3064
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <climits>
#include <string>
#include <vector>
#include <utility>
#include <functional>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <cassert>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;

const ll MOD = ll(1e9 + 7);
const ll INF = LLONG_MAX;
const ll MAX_N = ll(1e3) + 5;
const double EPS = 10e-8;
const double PI = 3.14159265359;
int dx[] = {1, 0, -1, 0}, dy[] = {0, 1, 0, -1};
#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++)

int main() {
    int n, k = 1;
    vector<int> ls;
    cin >> n;
    while (k <= n) {
        ls.push_back(k);
        k *= 9;
    }
    k = 6;
    while (k <= n) {
        ls.push_back(k);
        k *= 6;
    }
    sort(ls.begin(), ls.end());
    int dp[100005];
    fill(dp, dp + n + 1, 999999);
    dp[0] = 0;
    REP(i, n+1) {
        int j = 0;
        while (i - ls[j] >= 0 && j < ls.size()) {
            dp[i] = min(dp[i], dp[i - ls[j]] + 1);
            j++;
        }
    }
    cout << dp[n] << endl;
    return 0;
}


Measured memory_bytes: 640
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;

public class Main {
	final int _intMax = Integer.MAX_VALUE; // =2147483647>10^9
	final int _intMin = Integer.MIN_VALUE;
	final long _longMax = Long.MAX_VALUE; // =9223372036854775807L>10^18
	final long _longMin = Long.MIN_VALUE;

	void solve() {
		String s = readLine();
		String t = s.substring(0, s.length() - 1);
		if (t.length() % 2 == 1)
			t = t.substring(0, t.length() - 1);
		while (true) {
			int l = t.length() / 2;
			String a = t.substring(0, l);
			String b = t.substring(l);
			if (a.equals(b))
				break;
			t = t.substring(0, t.length() - 1);
		}
		long ans = t.length();
		pln(ans);
	}

	// -----------------------------------------------------
	// 2018/04/25 r1
	// -----------------------------------------------------
	int abs(int a) {
		return (a >= 0) ? a : -a;
	}

	long abs(long a) {
		return (a >= 0) ? a : -a;
	}

	int max(int a, int b) {
		return (a > b) ? a : b;
	}

	long max(long a, long b) {
		return (a > b) ? a : b;
	}

	int min(int a, int b) {
		return (a < b) ? a : b;
	}

	long min(long a, long b) {
		return (a < b) ? a : b;
	}

	int pint(String s) {
		return Integer.parseInt(s);
	}

	long plong(String s) {
		return Long.parseLong(s);
	}

	String readLine() {
		try {
			return _in.readLine();
		} catch (IOException e) {
			throw new RuntimeException(e);
		}
	}

	int readNum() {
		String line = readLine();
		return pint(line);
	}

	long readLong() {
		String line = readLine();
		return plong(line);
	}

	String[] readFlds() {
		String line = readLine();
		return line.split(" ");
	}

	int[] readNums() {
		String[] flds = readFlds();
		int[] nums = new int[flds.length];
		for (int i = 0; i < flds.length; i++)
			nums[i] = pint(flds[i]);
		return nums;
	}

	long[] readLongs() {
		String[] flds = readFlds();
		long[] nums = new long[flds.length];
		for (int i = 0; i < flds.length; i++)
			nums[i] = plong(flds[i]);
		return nums;
	}

	void p(char c) {
		_out.print(c);
	}

	void pln(char c) {
		_out.println(c);
	}

	void p(double d) {
		_out.print(d);
	}

	void pln(double d) {
		_out.println(d);
	}

	void p(long l) {
		_out.print(l);
	}

	void pln(long l) {
		_out.println(l);
	}

	void p(String s) {
		_out.print(s);
	}

	void pln(String s) {
		_out.println(s);
	}

	static BufferedReader _in;
	static PrintWriter _out;
	static boolean _bElapsed = false;

	public static void main(String[] args) {
		long start = System.currentTimeMillis();
		_in = new BufferedReader(new InputStreamReader(System.in));
		_out = new PrintWriter(System.out);
		new Main().solve();
		_out.flush();
		long end = System.currentTimeMillis();
		if (_bElapsed)
			System.err.println((end - start) + "ms");
	}
}


Measured memory_bytes: 23252
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MAX = 1e5+5;
ll N,A[MAX],i;
vector<ll> vt;

bool f(ll x){
    map<ll, ll> mp;
    ll piv=0,sum=1,ret=0;
    mp[0]=1;
    for(i=0;i<N;i++){
        if(A[i] >= x) piv++, sum += mp[piv];
        else sum -= mp[piv], piv--;
        ret += sum,mp[piv]++,sum++;
    }
    return (2*ret<N*(N+1)/2);
}
main(){
    scanf("%lld",&N);
    for(;i<N;i++){
        scanf("%lld",A+i);
        vt.push_back(A[i]);
    }
    sort(vt.begin(),vt.end());
    vt.erase(unique(vt.begin(),vt.end()),vt.end());
    ll l=0,r=vt.size()-1;
    while(l<r){
        int mid=(l+r+1)/2;
        if(f(vt[mid]))  r=mid-1;
        else l=mid;
    }
    printf("%lld",vt[l]);
}


Measured memory_bytes: 6516
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <climits>
#include <cstdlib>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <vector>
#define DEBUG 1
using namespace std;
constexpr int kMod = 1000000007;
typedef long long LL;
typedef pair<LL, LL> P;

int main() {
  LL N; cin >> N;
  vector<LL> z(N), w(N);
  for (int i = 0; i < N; ++i) {
    int x, y; cin >> x >> y;
    z[i] = x + y;
    w[i] = x - y;
  }
  sort(z.begin(), z.end());
  sort(w.begin(), w.end());
  cout << max(z[N-1] - z[0], w[N-1] - w[0]) << endl;
}


Measured memory_bytes: 6416