akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

long long N, K, A[509][509], B1[509], B2[509], cnt; vector<long long>vec, vec2, vec3;

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

int main() {
	cin >> K; N = 500;
	for (int i = 1; i <= N; i++) vec.push_back(i);
	for (int i = N + 1; i <= 200000; i++) {
		bool prime = true;
		for (int j = 2; j*j <= i; j++) {
			if (i%j == 0) prime = false;
		}
		if (prime == true) { cnt++; vec2.push_back(i); }
		if (cnt * 2 >= N) break;
	}
	int L1 = 0, R1 = N - 1;
	for (int i = 1; i <= N; i++) {
		if (i % 2 == 0) { B1[i] = vec[L1]; L1++; }
		if (i % 2 == 1) { B1[i] = vec[R1]; R1--; }
	}
	int L2 = 0, R2 = vec2.size() - 1;
	for (int i = 0; i < (N + 1) / 2; i++) {
		if (i % 2 == 0) {
			B2[i * 2 + 1] = vec2[L2];
			B2[i * 2 + 2] = vec2[L2];
			L2++;
		}
		if (i % 2 == 1) {
			B2[i * 2 + 1] = vec2[R2];
			B2[i * 2 + 2] = vec2[R2];
			R2--;
		}
	}

	for (int i = 1; i <= N; i++) {
		for (int j = 1; j <= N; j++) {
			if ((i + j) % 2 == 1) continue;
			A[i][j] = B1[i] * B2[j];
		}
	}
	long long maxn = 0;
	for (int i = 1; i <= N; i++) {
		for (int j = 1; j <= N; j++) {
			if (A[i][j] >= 1) continue;
			long long ret = 1; int dx[4] = { 0,-1,0,1 }, dy[4] = { 1,0,-1,0 };
			for (int k = 0; k < 4; k++) {
				int fx = i + dx[k], fy = j + dy[k];
				if (fx <= 0 || fy <= 0 || fx > N || fy > N) continue;
				ret = ret / gcd(ret, A[fx][fy])*A[fx][fy];
			}
			A[i][j] = ret + 1; maxn = max(maxn, A[i][j]);
		}
	}
	for (int i = 1; i <= K; i++) {
		for (int j = 1; j <= K; j++) {
			if (j >= 2) cout << " "; 
			cout << A[i][j];
		}
		cout << endl;
	}
	return 0;
}

Measured memory_bytes: 4736
import math
def main():
    h,w = map(int,input().split())
    Map = []
    ans = []
    for i in range(h):
        tmp = [int(i) for i in input().split()]
        Map.append(tmp)
    for i in range(h-1):
        for j in range(w):
            if Map[i][j]%2==1:
                Map[i][j]-=1
                Map[i+1][j] += 1
                ans.append([i+1,j+1,i+2,j+1])
    for j in range(w-1):
        if Map[h-1][j]%2==1:
            Map[h-1][j] -= 1
            Map[h-1][j+1] += 1
            ans.append([h,j+1,h,j+2])
    ans_l = len(ans)
    print(ans_l)
    for i in range(ans_l):
        print(*ans[i])
main()


Measured memory_bytes: 32424
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n); i++)
#define int long long
#define double long double
#define mod 1000000007
#define F first
#define S second
#define P pair<long long,long long>
#define all(a) a.begin(),a.end()
#define INF 10000000000000000
#define endl '\n'
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
using namespace std;

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

    int n; cin>>n;
    vector<int> a(n),b(n);
    vector<P> vec(n);
    vector<bool> eat(n,false);
    rep(i,n){
        cin>>a.at(i)>>b.at(i);
        vec.at(i).F=a.at(i)+b.at(i);
        vec.at(i).S=i;
    }
    sort(all(vec),greater<P>());
    int ans=0;
    rep(i,n){
        if(i%2==0)ans+=a.at(vec.at(i).S);
        else ans-=b.at(vec.at(i).S);
    }
    cout<<ans<<endl;
    
}

Measured memory_bytes: 3456
#include<stdio.h>
#include<iostream>
#include<string>
#include<math.h>
#include<cmath>
#include<algorithm>
#include<map>
#include<queue>
#include<stack>
#include<vector>
#include<time.h>
#include<ctime>
#include<functional>
#define int long long
#define INF (1<<29)
#define f(i,n) for(int i=0;i<(n);i++)
typedef long long ll;
using namespace std;

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

ll LCM(ll a, ll b) {
	return a / GCD(a, b)*b;
}

ll mypow(ll a, ll b, ll c) {
	if (b == 0)return 1;
	if (b % 2)return mypow(a, b - 1, c)*a%c;
	else return mypow(a, b / 2, c)*mypow(a, b / 2, c) % c;
}

signed main() {
	string s;
	cin >> s;
	map<char, int> m;
	f(i, s.size()) {
		m[s[i]]++;
	}
	f(i, s.size()) {
		if (m[s[i]] % 2) {
			cout << "No" << endl;
			return 0;
		}
	}
	cout << "Yes" << endl;
	return 0;
}


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

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll n,m;
    cin>>n>>m;
    vector<int>wa(n,0);
    vector<bool>c(n,false);
    for(int i=0;i<m;i++)
    {
        string s;
        ll x;
        cin>>x>>s;
        x--;
        if(s=="AC")
            c[x]=true;
        if(s=="WA"&&c[x]==false)
            wa[x]++;
    }
    ll c1=0,p1=0;
    for(int i=0;i<n;i++)
    {
        if(c[i])
        {
            c1++;
            p1+=wa[i];
        }
    }
    cout<<c1<<" "<<p1<<endl;
    return 0;
}


Measured memory_bytes: 3724
#include <bits/stdc++.h>
#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;

int main(){
  char a[3] ;
  for(int i=0;i<3;i++){
    cin >> a[i] ;
  }
  if(a[1] == 'B'){
    cout << "ARC" ;
  }
  else cout << "ABC" ;
  return 0 ;
}

Measured memory_bytes: 3636
import java.io.*;
import java.math.*;
import java.text.*;
import java.util.*;
import java.util.regex.*;

public class Main {

    public static long knapsack(int N, int W, int[] w, int[] v) {
        long[][] dp = new long[N + 1][W + 1];

        for(int i = 0; i <= N; i++) {
            for(int j = 0; j <= W; j++) {
                if(i == 0 || j == 0) {
                    dp[i][j] = 0;
                } else if(w[i - 1] <= j){
                    dp[i][j] = Math.max(dp[i - 1][j], dp[i - 1][j - w[i - 1]] + v[i - 1]);
                } else {
                    dp[i][j] = dp[i - 1][j];
                }
            }
        }
        return dp[N][W];
    }

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int W = sc.nextInt();
        
        int[] w = new int[N];
        int[] v = new int[N]; 

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

        System.out.println(knapsack(N, W, w, v));
  }
}


Measured memory_bytes: 125520
#include <iostream>
#include <map>
#include <algorithm>
#include <string>
#include <vector> 
#include <numeric>
#include <cmath>
#include <queue>
#include <iomanip>
#include <functional>


#define CHMAX(a,b) a = std::max(a,b)
#define CHMIN(a,b) a = std::min(a,b)
#define MAXMIN(a,b,c) std::max(a,min(b,c))
#define CHABS(a) a = std::abs(a) 
#define COUT(a) std::cout << a << std::endl
#define CERR(a) std::cerr << a << std::endl
#define FOR(n) for(lli i = 0; i < n; i++)

using namespace std;
using lli = long long int;
using pll = pair<lli, lli>;
using tlll = tuple<lli, lli, lli>;
using vll = vector<lli>;

lli mod197 = 1000000007LL;
lli INF = 10000000000000;

// ax + by = gcd(a,b) 最大公約数
template< typename T >
T extgcd(T a, T b, T& x, T& y) {
	T d = a;
	if (b != 0) {
		d = extgcd(b, a % b, y, x);
		y -= (a / b) * x;
	}
	else {
		x = 1;
		y = 0;
	}

	return d;
}

lli a[200000] = {};

int main(void) {

	lli n, l = 0, r = 0, answer = 0, sum = 0;
	cin >> n;

	for (lli i = 0; i < n; i++) {
		cin >> a[i];
	}

	for (r = 0; r < n; r++) {

		while (sum & a[r]) {

			sum = sum ^ a[l];
			l++;
		}
		sum |= a[r];
		answer += r - l + 1;
	}

	cout << answer << endl;

	return 0;
}

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

public class Main {
    static MyReader in = new MyReader();

    public static void main(String[] args) {
        int N = in.i();
        int[] a = in.ii(N);

        int ans = -1;
        for (int i = 0, j = 0; i < N; i++) {
            if ((j = a[j] - 1) == 1) {
                ans = i + 1;
                break;
            }
        }
        
        System.out.println(ans);
    }
}

class MyReader extends BufferedReader {
    char[] cbuf = new char[1024];
    int head = 0;
    int tail = 0;

    MyReader() {
        super(new InputStreamReader(System.in));
    }

    char next() {
        if (head == tail) {
            try {
                tail = super.read(cbuf, 0, cbuf.length);
            } catch (IOException e) {
                e.printStackTrace();
            }
            head = 0;
        }
        return cbuf[head++];
    }

    int i() {
        int k = next() - '0';
        boolean minus = k == -3;
        int n = minus ? 0 : k;
        while (0 <= (k = next() - '0') && k <= 9) n = 10 * n + k;
        return minus ? -n : n;
    }

    int[] ii(final int N) {
        int[] a = new int[N];
        for (int j = 0; j < a.length; j++) a[j] = i();
        return a;
    }

    long l() {
        int k = next() - '0';
        boolean minus = k == -3;
        long n = minus ? 0 : k;
        while (0 <= (k = next() - '0') && k <= 9) n = 10 * n + k;
        return minus ? -n : n;
    }

    char[] s(final int N) {
        char[] s = new char[N];
        for (int i = 0; i < N; i++) {
            s[i] = next();
        }
        next();
        return s;
    }

    public int read(char[] cbuf) {
        int i;
        char c;
        for (i = 0; (c = next()) != ' ' && c != '\n'; i++) cbuf[i] = c;
        return i;
    }

    public String readLine() {
        try {
            return super.readLine();
        } catch (IOException e) {
            return null;
        }
    }
}


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

int main() {
    string s;
    cin >> s;
    int count = 0;
    for (int i = 0; i < s.size(); i++) {
        if (s[i] == '1') {
            count++;
        }
    }
    cout << count << endl;
}

Measured memory_bytes: 256
# B
import sys
x, y = map(int, input().split())
for i in range(x + 1):  # 鶴
    for j in range(x + 1):  # 亀
        if i + j == x and (i * 2 + j * 4) == y:
            print('Yes')
            sys.exit()
print('No')


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

typedef long long ll;
typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;
typedef vector<vector<vector<ll>>> vvvll;
typedef vector<bool> vb;
typedef vector<vector<bool>> vvb;
typedef vector<vector<vector<bool>>> vvvb;
typedef pair<ll, ll> pll;
typedef vector<pll> vpll;
typedef vector<vpll> vvpll;
typedef vector<double> vd;
typedef vector<vd> vdd;

#define FOR(i,x,y) for(ll i=(ll)x; i<(ll)y; ++i)
#define REP(i,y) FOR(i, 0, y)
#define RFOR(i,x,y) for(ll i=(ll)x; i>=(ll)y; --i)
#define RREP(i,x) RFOR(i, x, 0)
#define ALL(a) a.begin(), a.end()
#define pb push_back
#define debug_print(x...) cerr << "line " << __LINE__ << " : "; debug_print_in(x);

template <typename First>
void debug_print_in(First first){
  cerr << first << endl;
  return;
}

template <typename First, typename... Rest>
void debug_print_in(First first, Rest... rest){
  cerr << first << " ";
  debug_print_in(rest...);
  return;
}

void IN(void){
  return;
}

template <typename First, typename... Rest>
void IN(First& first, Rest&... rest){
  cin >> first;
  IN(rest...);
  return;
}

template <typename First>
void OUT(First first){
  cout << first << endl;
  return;
}

template <typename First, typename... Rest>
void OUT(First first, Rest... rest){
  cout << first << " ";
  OUT(rest...);
  return;
}

template<class t, class u> void chmax(t&a,u b){if(a<b)a=b;};
template<class t, class u> void chmin(t&a,u b){if(a>b)a=b;};
int popcount(int t){return __builtin_popcount(t);} //GCC
int popcount(ll t){return __builtin_popcountll(t);} //GCC

template <typename T>
void vec_print(vector<T> VEC){
  REP(i, VEC.size()){
    cerr << VEC[i] << " ";
  }
  cerr << endl;
};

template <typename T>
void mat_print(vector<vector<T> > MAT){
  REP(i,MAT.size()){
    REP(j,MAT[i].size()){
      cerr << MAT[i][j] << " ";
    }
    cerr << endl;
  }
};

constexpr int INF = (1<<30);
constexpr ll INFLL = 1LL<<62;
constexpr long double EPS = 1e-12;
constexpr ll MOD = (ll)((1E+9)+7);

int main(){
  cin.tie(0); // cut the cin and cout (default, std::flush is performed after std::cin)
  ios::sync_with_stdio(false); // cut the iostream and stdio (DON'T endl; BUT "\n";)

  ll N;
  IN(N);
  vll A(N);
  REP(i,N) IN(A[i]);

  /*
  ll ans2 = 0;
  REP(i,N){
    FOR(j,i+1,N){
      ans2 += (A[i]^A[j]);
    }
  }
  debug_print(ans2%MOD);
  */

  ll ans = 0;
  ll tmp2 = 1;
  REP(i,61){
    ll count = 0;
    REP(j,N){
      count += A[j]%2;
      A[j]>>=1;
    }
    ll tmp = (count*(N-count))%MOD;
    ans += (tmp*tmp2)%MOD;
    tmp2 *= 2;
    tmp2 %= MOD;
    ans %= MOD;
    debug_print(i, count);
  }


  OUT(ans%MOD);

  return 0;
}


Measured memory_bytes: 2560
#include <iostream>
#include <vector>
#include <algorithm>
#include <cstdlib>

using namespace std;

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

  int N;
  cin >> N;
  vector<int> h(N);
  for (auto &x: h) cin >> x;

  vector<int> dp(N+2);
  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]));
  }

  cout << dp[N-1] << endl;
  return 0;
}


Measured memory_bytes: 1024
import core.bitop, std.algorithm, std.ascii, std.bigint, std.conv,
    std.functional, std.math, std.numeric, std.range, std.stdio, std.string,
    std.random, std.typecons, std.container;

ulong MAX = 1_000_100, MOD = 1_000_000_007, INF = 1_000_000_000_000;
alias sread = () => readln.chomp();
alias lread(T = long) = () => readln.chomp.to!(T);
alias aryread(T = long) = () => readln.split.to!(T[]);
alias Pair = Tuple!(long, "begin", long, "end");
alias PQueue(T, alias less = "a<b") = BinaryHeap!(Array!T, less);

void main()
{
    long n = lread();
    auto x = aryread();
    long ans = INF;
    foreach (i; iota(100))
    {
        ans = min(x.calc(i), ans);
    }
    ans.writeln();
}

long calc(T)(T a, long t)
{
    long ret;
    foreach (e; a)
    {
        ret += (e - t) ^^ 2;
    }
    return ret;
}

void scan(TList...)(ref TList Args)
{
    auto line = readln.split();
    foreach (i, T; TList)
    {
        T val = line[i].to!(T);
        Args[i] = val;
    }
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
using namespace std;
const double pi = 3.1415926;
int a;
int main()
{

    double a,b;
    double x;
    cin >> a >> b >> x ;
    if((int)(a*a*b)==(int)(x)){
        printf("0\n");
        return 0;
    }
    if(a*a*b/2<=x){
        x=a*a*b-x;
        x/=a;
        x/=a;
        x*=2;
        //cout << a*a*b/x << endl;
        double R=sqrt(x*x+a*a);
        printf("%.10f\n",acos(a/R)*180/pi);
    }
    else{
        x/=a;
        x/=b;
        x*=2;
        double R=sqrt(x*x+b*b);
        printf("%.10f",asin(b/R)*180/pi);
    }
    return 0;
}


Measured memory_bytes: 256
package main

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

var sc = bufio.NewScanner(os.Stdin)

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

var N, M int
var L, R []int

func main() {
	sc.Split(bufio.ScanWords)
	N, M = nextInt(), nextInt()
	L = make([]int, M)
	R = make([]int, M)
	for i := 0; i < M; i++ {
		L[i], R[i] = nextInt(), nextInt()
	}

	sort.Sort(sort.Reverse(sort.IntSlice(L)))
	sort.Ints(R)

	lmax := L[0]
	rmin := R[0]

	// fmt.Println(rmin - lmax + 1)

	ans := 0
	for i := 1; i <= N; i++ {
		if lmax <= i && i <= rmin {
			ans++
		}
	}

	fmt.Println(ans)

}


Measured memory_bytes: 3328
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vll;
typedef pair<ll, ll> pll;
typedef vector<pll> vpll;
typedef string str;
static const long long INF = INT64_MAX;
static const long long MOD = (ll)1e9+7;

#define endl "\n"
#define fast_io ios_base::sync_with_stdio(false);cin.tie(NULL)
#define REP(i, n) for(ll i=0;i<n;i++)
#define SZ(v) (ll)((v).size())
#define WHOLE(v) (v).begin(), (v).end()
#define ASC(v) sort((v).begin(), (v).end())
#define DESC(v) sort((v).rbegin(), (v).rend())
#define INV(v) reverse((v).begin(), (v).end())
#define FOLDL(src, dst, lambda) partial_sum((src).begin(), (src).end(), (dst).begin(), lambda)
#define FOLDR(src, dst, lambda) INV(src);partial_sum((src).begin(), (src).end(), (dst).begin(), lambda);INV(dst)
#define CUMSUML(src, dst) FOLDL(src, dst, [](auto a, auto b) {return a+b;})
#define CUMSUMR(src, dst) FOLDR(src, dst, [](auto a, auto b) {return a+b;})
#define ACCUM(v, d0, lambda) accumulate((v).begin(), (v).end(), d0, lambda)
#define SUM(v, d0) ACCUM(v, d0, [](auto a, auto b) {return a+b;})
#define ERASE(v, i) v.erase(v.begin() + i)
#define UNIQ(v) ASC(v);v.erase(unique(v.begin(), v.end()), v.end())

template <typename T>void debug(T t) {cerr << t << endl;}
template <typename T, typename ...Args>void debug(T t, Args ...args) {cerr << t << " ";debug(args...);}
template <typename T>void out(T t) {cout << t << endl;}
template <typename T, typename ...Args>void out(T t, Args ...args) {cout << t << " ";out(args...);}

void solve() {
    ll n,m;
    cin >> n >> m;
    out((n-1) * (m-1));
}

int main() {
    fast_io;
    solve();
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)   FOR(i,0,n)
#define pb push_back
#define mp make_pair
typedef long long ll;
typedef pair<int,int> pint;

int main(){
    ll x,i;
    cin>>x;
    for(i=1;i*(i+1)/2<x;++i);
    cout<<i<<endl;
    return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<algorithm>
#include<vector>
#include<queue>
#include<cstring>
#include<set>
#include<map>
using namespace std;

int main(){
    int a,b;
    scanf("%d%d",&a,&b);
    printf("%d\n",max(0,a-2*b));
}

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

using namespace std;

set<string> st;
string s;
int cnt;
int k;

int main() {
    cin>>s;cin>>k;
    for (int i = 0; i < s.length(); i++) {
        string ss="";
        for (int j = 0; j < 5; j++) {
            if (i+j<s.length()) {
                ss=ss+s[i+j];
                st.insert(ss);
            }
        }
    }
    for (auto it = st.begin(); it!=st.end(); it++) {
        cnt++;
        if (cnt == k) {
            cout << *it;
            return 0;
        }
    }
    return 0;
}


Measured memory_bytes: 1664
# Rotationによる解。
from collections import Counter

N = int(input())
As = list(map(int, input().split()))
Bs = list(map(int, input().split()))

elem_max_count = max((Counter(As) + Counter(Bs)).values())
if elem_max_count > N:
    print("No")
    exit()

# Bs[-index:] > As[:index] を満たすようなindexを二分探索
# 参考: https://twitter.com/catupper/status/1305163805802917889?s=20

ok = 0
ng = N + 1
while ng - ok > 1:
    mid = (ok + ng) // 2
    isok = True
    for b, a in zip(Bs[-mid:], As[:mid]):
        if b <= a:
            isok = False
            break
    
    if isok:
        ok = mid
    else:
        ng = mid

print("Yes")
print(*(Bs[-ok:] + Bs[:-ok]))

Measured memory_bytes: 219212
#include <stdio.h>
#include <algorithm>
using namespace std;

const int mod = 1000000007;
long long inv[100100]={0,1},fact[100100]={1,1},ifact[100100]={1,1};
int N,M,U[16]; long long prv[1<<16];

int main()
{
	for (int i=2;i<100100;i++){
		inv[i] = (mod - mod / i) * inv[mod % i] % mod;
		fact[i] = fact[i-1] * i % mod;
		ifact[i] = ifact[i-1] * inv[i] % mod;
	}

	scanf ("%d %d",&N,&M);
	for (int i=0;i<M;i++) scanf ("%d",&U[i]);
	sort(U,U+M);
	reverse(U,U+M);

	prv[0] = 1;
	for (int i=0;i<M;i++){
		for (int j=(1<<N)-1;j>=0;j--) if (prv[j]){
			int rem = (1<<N) - U[i] - j;
			if (rem < 0) continue;
			for (int k=0;k<N;k++) if (~j & (1 << k)){
				if (rem < (1<<k)-1) break;
				long long coeff = (1<<k) * prv[j] % mod * fact[rem] % mod * ifact[rem-(1<<k)+1] % mod;
				prv[j+(1<<k)] = (prv[j+(1<<k)] + mod - coeff) % mod;
			}
		}
	}

	long long ans = 0;
	for (int j=0;j<(1<<N);j++){
		ans = (ans + prv[j] * fact[(1<<N)-1-j]) % mod;
	}

	for (int i=0;i<N;i++) ans = ans * 2 % mod;

	printf ("%lld\n",ans);

	return 0;
}

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

int main() {
	int a, b;
	char op;
	bool flag = 1;
	while (flag) {
		cin >> a >> op >> b;
		if (op == '+') {
			cout << a + b << endl;
		}
		else if (op == '-') {
			cout << a - b << endl;
		}
		else if (op == '*') {
			cout << a*b << endl;
		}
		else if (op == '/') {
			cout << a / b << endl;
		}
		else {
			flag = 0;
		}
	}
}


Measured memory_bytes: 3084
/**
 * @author karayuu
 */

fun main(args: Array<String>) {
    readLine()!!
    val a = readLine()!!.split(" ").map { it.toInt() }

    val ave = a.average()
    val thumb = a.minBy { Math.abs(it - ave) }!!

    var flame = 0
    for (i in a) {
        if (i == thumb) {
            println(flame)
            return
        } else {
            flame++
        }
    }
}

Measured memory_bytes: 36132
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[] a = new int[n];
		for(int i = 0 ; i  < n ; i++) {
			a[i] = sc.nextInt();
		}
		int ans = 0;
		for(int i = 0 ;; i++) {
			boolean ok = true;
			for(int j = 0 ; j < n ; j++) {
				if(a[j] % 2 != 0) {
					ok = false;
				}
			}
			if(ok) {
				ans++;
				for(int k = 0 ; k < n ;  k++) {
					a[k] /= 2;
				}
			} else {
				break;
			}
		}
		System.out.println(ans);
	}
}


Measured memory_bytes: 21716
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;

class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        Task solver = new Task();
        solver.solve(in, out);
        out.close();
    }

    static class Task {
        void solve(InputReader in, PrintWriter out) {
            int N = in.nextInt();
            out.println(N / 3);
        }
    }

    static class InputReader {
        BufferedReader reader;
        StringTokenizer tokenizer;

        InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream));
            tokenizer = null;
        }

        String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

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

Measured memory_bytes: 21588
#include<stdio.h>
#include<string.h>
#include<ctype.h>

char W[10],T[1000];

main()
{
	int c=0,i;
	
	scanf("%s",W);
		
	for(i=0;i<10;i++){W[i]=tolower(W[i]);}
	
	while(1){
		scanf("%s",T);
		if(strcmp(T,"END_OF_TEXT")==0){break;}
		
		for(i=0;i<1000;i++){T[i]=tolower(T[i]);}
		
		if(strcmp(T,W)==0) {c++;}
		
	}
	printf("%d\n",c);
	
	return 0;
}

Measured memory_bytes: 552
#ifdef loc
    #include "codes/loc_debug.h"
#else
    #include <bits/stdc++.h>
    #define pr(...)
    #define pra(a,n)
    #define praa(a,n,m)
    #define prl()
#endif
using namespace std;
 
typedef long long ll;
#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
#define sz(a) int(a.size())
const int N = 100005;
 
vector<int> g[N];
vector<int> h[N];
int vis[N];
 
void go(int x, int p) {
    vis[x] = 1;
    for(auto v : g[x]) {
        if(!vis[v]) {
            go(v, x);
        } else if(v != p && vis[v] == 1) {
            h[x].emplace_back(v);
        }
    }
    vis[x] = 2;
}
 
void go2(int x) {
    vis[x] = 1;
    for(auto v : g[x]) {
        if(!vis[v]) {
            go2(v);
            if(sz(h[v]) & 1) {
                h[v].emplace_back(x);
            } else {
                h[x].emplace_back(v);
            }
        }
    }
}
 
int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int n, m;
    cin >> n >> m;
    if(m & 1) {
        cout << -1 << endl;
        return 0;
    }
    rep(i, 0, m) {
        int u, v;
        cin >> u >> v;
        g[u].emplace_back(v);
        g[v].emplace_back(u);
    }
    go(1, 0);
    memset(vis, 0, sizeof(vis));
    go2(1);
    rep(i, 1, n + 1) {
        for(auto v : h[i]) {
            cout << i << ' ' << v << endl;
        }
    }
}

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



struct UnionFind {
    vector<int> v;
    vector<int> size;
    int a; // 木の数
    UnionFind(int n) {
        v.resize(n);
        size.resize(n);
        rep(i,n) {
            v[i] = i;
            size[i] = 1;
        }
        a = n;
    }

    int root(int x) {
        if (x == v[x]) return x;
        return v[x] = root(v[x]);
    }

    bool unite(int x, int y) {
        if (root(x) == root(y)) return false;
        size[root(y)] += size[root(x)]; 
        v[root(x)] = v[root(y)];
        return true;
    }

    int cnt(int x) {
        return size[root(x)];
    }

};


int main() {
    lint n,m; cin >> n >> m;
    vector<lint> a(m);
    vector<lint> b(m);
    UnionFind uf(n);
    rep(i,m) {
        cin >> a[i] >> b[i];
        a[i]--;
        b[i]--;
        uf.unite(a[i],b[i]);
    }
    lint cnt = 0;
    set<int> mita;
    rep(i,n) {
        int x = i;
        int root = uf.root(x);
        if (mita.find(root) != mita.end()) continue;
        mita.insert(root);
        cnt ++;
    }
    lint ans = 0;
    rep(i,n) ans = max(ans, (lint)uf.cnt(i) );
    cout << ans << endl;
}

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

public class Main {

	public static void main(String[] args) {
		FastScanner sc = new FastScanner();
		PrintWriter out = new PrintWriter(System.out);
		int n = sc.nextInt();
		List<Integer> score = new ArrayList<>();
		int sum = 0;
		for(int i = 0; i < n; i++) {
			int num = sc.nextInt();
			sum += num;
			if (num % 10 != 0)
				score.add(num);
		}
		Collections.sort(score);
		boolean flag = false;
		for(int i = 0; i < score.size(); i++) {
			if (sum % 10 != 0) { 
				flag = true;
				break;}
			else {
				sum -= score.get(i);
			}
		}
		if (!flag) sum = 0;
		out.println(sum);

		out.close();
	}

static class FastScanner {
    private final InputStream in = System.in;
    private final byte[] buffer = new byte[1024];
    private int ptr = 0;
    private int buflen = 0;
    private boolean hasNextByte() {
        if (ptr < buflen) {
            return true;
        }else{
            ptr = 0;
            try {
                buflen = in.read(buffer);
            } catch (IOException e) {
                e.printStackTrace();
            }
            if (buflen <= 0) {
                return false;
            }
        }
        return true;
    }
    private int readByte() { if (hasNextByte()) return buffer[ptr++]; else return -1;}
    private static boolean isPrintableChar(int c) { return 33 <= c && c <= 126;}
    public boolean hasNext() { while(hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++; return hasNextByte();}
    public String next() {
        if (!hasNext()) throw new NoSuchElementException();
        StringBuilder sb = new StringBuilder();
        int b = readByte();
        while(isPrintableChar(b)) {
            sb.appendCodePoint(b);
            b = readByte();
        }
        return sb.toString();
    }
    public long nextLong() {
        if (!hasNext()) throw new NoSuchElementException();
        long n = 0;
        boolean minus = false;
        int b = readByte();
        if (b == '-') {
            minus = true;
            b = readByte();
        }
        if (b < '0' || '9' < b) {
            throw new NumberFormatException();
        }
        while(true){
            if ('0' <= b && b <= '9') {
                n *= 10;
                n += b - '0';
            }else if(b == -1 || !isPrintableChar(b)){
                return minus ? -n : n;
            }else{
                throw new NumberFormatException();
            }
            b = readByte();
        }
    }
    public int nextInt() {
        long nl = nextLong();
        if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE) throw new NumberFormatException();
        return (int) nl;
    }
    public double nextDouble() { return Double.parseDouble(next());}
}
}

Measured memory_bytes: 22100
#include<bits/stdc++.h>
using namespace std;
int main (){
    int N,count=0;
    cin>>N;
    vector<int>a(N);
    for(int i=0;i<N;i++){
        cin>>a[i];
    }
    for(int i=1;i<N-1;i++){
        if((a[i-1]<a[i]&&a[i]<a[i+1])||(a[i-1]>a[i]&&a[i]>a[i+1])){
            count++;
        }    
        }
        cout<<count<<endl;
}

Measured memory_bytes: 256
# /usr/bin/python
# -*- coding: utf-8 -*-
import sys
import math



def main(x,y,z):
	ret = 0
	while(1):
		if ret*(y+z)+z > x:
			return ret-1
		else:
			ret += 1


if __name__ == "__main__":
	X,Y,Z = map(int, input().split())
	print(main(X,Y,Z))

Measured memory_bytes: 3060
#include "iostream"
#include "climits"
#include "list"
#include "queue"
#include "stack"
#include "set"
#include "functional"
#include "algorithm"
#include "string"
#include "map"
#include "iomanip"
#include "random"

using namespace std;

const long long int MOD = 1000000007;
const long double EPS = 0.00000001;
const long double PI = 3.1415926535897932384626433;

long long int N, M, K, H, W, L, R;


int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	
	cin >> N;
	map<int, int>a;
	map<int, int>b;
	for (int i = 0; i < N; i++) {
		cin >> K;
		a[K]++;
	}
	cin >> M;
	for (int i = 0; i < M; i++) {
		cin >> K;
		b[K]++;
	}
	for (auto i : b) {
		if (i.second > a[i.first]) {
			cout << "NO\n";
			return 0;
		}
	}
	cout << "YES\n";
	return 0;
}


Measured memory_bytes: 19072
#include <iostream>
using namespace std;
typedef long long ll;
int main() {
	int n; cin >> n;
	ll ans = 0;
	for (int i = 1; i < n; i++) {
		int x = n / i;
		if (n % i == 0) { x--; }
		ans += x;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 3188
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pairSS
int main(){
  double w,h,x,y;
  cin >> w >> h >> x >> y;
  double menseki = w*h/2;
  cout << menseki << " ";
  if (w/2==x&&h/2==y){
    cout << 1 << endl;
  } else {
    cout << 0 << endl;
  }
}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(){
	int n;
	string str;
	cin >> n;
	while(n--){
		int out=0,base[5]={},score=0;
		while(1){
			cin >> str;
			base[0] = 1;
			if(str=="OUT"){
				out++;
				if(out==3)	break;
			}
			else if(str=="HIT"){
				for(int i=4;i>=1;i--)	base[i]=base[i-1];
				if(base[4]>0){
					score++;
					base[4]=0;
				}
			}
			else{
				for(int i=0;i<4;i++){
					if(base[i]>0){
						score++;
						base[i] = 0;
					}
				}
			}
			//cout << base[1] << ' ' << base[2] << ' ' << base[3] << endl;
		}
		cout << score << endl;
	}
	return 0;
}


Measured memory_bytes: 3024
package main

import (
	"fmt"
)

func main() {
	var n int
	fmt.Scan(&n)

	arr := make([]int, n)
	for i := range arr {
		fmt.Scan(&arr[i])
	}

	c := 0
	for {
		for i, v := range arr {
			if v%2 == 0 {
				arr[i] = v / 2
			} else {
				fmt.Println(c)
				return
			}
		}
		c++
	}
}


Measured memory_bytes: 512
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii =  pair<int, int>;
using pll =  pair<long long, long long>;
constexpr char ln =  '\n';
constexpr long long MOD = 1000000007LL;
constexpr long long INF = 1000000000LL;
#define all(x) (x).begin(),(x).end()
#define rep(i,n) for(int i=0;i<(n);i++)
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }


int main() {
  int n;
  cin >> n;
  double d = sqrt(n);
  int res = d;

  cout << res * res << ln;
}
  


Measured memory_bytes: 256
use proconio::input;

fn main() {
    input! {
        n: usize,
        mut a: [i64; n + 1],
        mut b: [i64; n],
    }

    let mut ans = 0;

    for i in 0..n {
        ans += b[i].min(a[i]);
        if b[i] > a[i] {
            b[i] -= b[i].min(a[i]);
            ans += a[i + 1].min(b[i]);
            a[i + 1] -= a[i + 1].min(b[i]);
        }
    }

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


Measured memory_bytes: 5648
n = gets.to_i
answer = ""
1.upto(1000000000).with_index do |num, index|
  break if n == 0
  if n % (2 ** num) != 0
    answer.insert(0, "1")
    n -= index.even? ? 2 ** index : (2 ** index) * -1
  else
    answer.insert(0, "0")
  end
end
answer.insert(0, "0") if answer.length == 0
puts answer

Measured memory_bytes: 1788
#include <bits/stdc++.h>
using namespace std;
int n,k;
int a[1000];
int main()
{
	scanf("%d%d",&n,&k);
	for(int i = 1;i <= n;i++) scanf("%d",&a[i]);
	sort(a + 1,a + n + 1);
	int ans = 0;
	for(int i = 1;i <= k;i++) ans += a[n - i + 1];
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
int main()
{
	int n,k,f,s,ans;
	scanf("%d",&n);
	scanf("%d",&k);
	scanf("%d",&f);
	scanf("%d",&s);
	if(k==n)
	{
		ans=n*f;
	}
	else if(n>k)
	{
		ans=((k*f)+(n-k)*s);
	}
	else if(n<k)
    {
        ans=n*f;
    }
printf("%d\n",ans);
			return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <cctype>
#include <string>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <algorithm>
#include <functional>
using namespace std; 
#define DEBUG(x) cout << '>' << #x << ':' << x << endl;
#define REP(i,n) for(int i=0;i<(n);i++)
#define FOR(i,a,b) for(int i=(a);i<=(b);i++)
#define FORD(i,a,b) for(int i=(a);i>=(b);i--)
inline bool EQ(double a, double b) { return fabs(a-b) < 1e-9; }
const int INF = 1<<29;
typedef long long int ll;
inline int two(int n) { return 1 << n; }
inline int test(int n, int b) { return (n>>b)&1; }
inline void set_bit(int & n, int b) { n |= two(b); }
inline void unset_bit(int & n, int b) { n &= ~two(b); }
inline int last_bit(int n) { return n & (-n); }
inline int ones(int n) { int res = 0; while(n && ++res) n-=n&(-n); return res; }
template<class T> void chmax(T & a, const T & b) { a = max(a, b); }
template<class T> void chmin(T & a, const T & b) { a = min(a, b); }
const int MOD=1000000007;

bool isPowerOfTwo (ll x)  
{  
    return x && (!(x&(x-1)));  
}
bool isPrime(int n) 
{ 
    if (n <= 1)  return false; 
    if (n <= 3)  return true; 
    if (n%2 == 0 || n%3 == 0) return false; 
  
    for (int i=5; i*i<=n; i=i+6) 
        if (n%i == 0 || n%(i+2) == 0) 
           return false; 
  
    return true; 
}
int highestPowerof2(unsigned int n) 
{ 
    // Invalid input 
    if (n < 1) 
        return 0; 
  
    int res = 1;
    for (int i=0; i<8*sizeof(unsigned int); i++) 
    { 
        int curr = 1 << i; 
        if (curr > n) 
           break; 
  
        res = curr; 
    } 
  
    return res; 
} 
long long binpow(long long a, long long b) {
    long long res = 1;
    while (b > 0) {
        if (b & 1)
            res = res * a;
        a = a * a;
        b >>= 1;
    }
    return res;
}
const int dx[] = {1,0,-1,0,1,1,-1,-1};
const int dy[] = {0,-1,0,1,1,-1,-1,1};
/*lcm(gcd(N1, M), gcd(N2, M), ..., gcd(Nk, M)) = gcd(lcm(N1, ..., Nk), M)
gcd(lcm(N1, M), lcm(N2, M), ..., lcm(Nk, M)) = lcm(gcd(N1, ..., Nk), M).

If gcd(N1, N2) = 1, then
gcd(N1·N2, M) = gcd(N1, M)·gcd(N2, M)
lcm(N1·N2, M) = lcm(N1, M)·lcm(N2, M)/M.

lcm(M, N, P) · gcd(M, N) · gcd(N, P) · gcd(P, M) = NMP · gcd(N, M, P).
*/
////////////////////////////////////////////////////////////////////

int main()
{
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);  
  cout.tie(NULL);
  ll t=1;
  while(t--)
  {
    ll n,c,k;
    cin>>n>>c>>k;
    ll a[n];
    REP(i,n)cin>>a[i];
    sort(a,a+n);
    ll ans=0;
    ll i=0;
    while(i<n)
    {
        ans++;
        int res=a[i]+k;
        int u=0;
        while(i<n && u<c && a[i] <= res)
        {
            i++;
            u++;
        }
    }
    cout<<ans;
  }  
  return 0;
}
/* Look for:
* the exact constraints (multiple sets are too slow for n=10^6 :( )
* special cases (n=1?)
* 1LL<<i and not 1<<i
* overflow (int vs ll?)
* array bounds
* if you have no idea just guess the appropriate well-known algo instead of doing nothing :/
*/

Measured memory_bytes: 4448
#include <iostream>
#include <stdio.h>
#include <string>
#include <vector>
#include <algorithm>
#include <limits.h>
using namespace std;

int main(int argc,char const* argv[])
{
  int ans,m;
  cin >> m;
  ans=48-m;
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <string.h>
#include <string>
#include <vector>
#include <deque>
#include <list>
#include <queue>
#include <math.h>
#include <assert.h>
#include <set>
#include <map>
#include <bitset>
#include <ctime>
#include <time.h>
#include <algorithm>
#include <cstdio>
#include <fstream>
#include <stack>
#include <ctype.h>
#include <numeric>
#include <sstream>
#include <unistd.h>
#include <unordered_map>
#include <unordered_set>
#include <limits>
#include <random>
#include <chrono>
#include <iomanip>
using namespace std;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
using ll = long long;
#define endl '\n'
#define debug(name) DEBUG(#name, (name))
template<typename T>
void DEBUG(string label, T value) {
    cerr << "[" << label << " = " << value << "]\n";
}

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

    ll a, b, c, d;
    cin >> a >> b >> c >> d;
    ll a1 = a * c;
    ll a2 = a * d;
    ll a3 = b * c;
    ll a4 = b * d;
    ll ans = max(max(a1,a2), max(a3,a4));
    if((a <= 0 && 0 <= b) || (c <= 0 && 0 <= d)){
        ans = max(0LL, ans);
    }
    cout << ans << endl;
}


Measured memory_bytes: 3652
#include <iostream>
#include <algorithm>
#include <string> 
#include <vector>
#include <iomanip>
#include <math.h>
#include <map>
using namespace std;
#define lol long long

int main()
{
	int N, Q;
	cin >> N >> Q;
	string S;
	cin >> S;
	vector<int> l(Q);
	vector<int> r(Q);
	vector<int> D(N + 1 , 0);
	vector<int> sum(N + 1, 0);
	vector<int> ans(Q, 0);
	int M = 0;
	for (int i = 0; i < Q; i++) {
		cin >> l[i] >> r[i];
	}
	for (int i = 0; i < N - 1; i++) {
		if (S[i] == 'A' && S[i + 1] == 'C') {
			D[i + 2]++;
		}
	}
	sum[2] = D[2];
	for (int i = 3; i < N + 1; i++) {
		sum[i] = D[i] + sum[i - 1];
	}
	for (int i = 0; i < Q; i++) {
		ans[i] = sum[r[i]] - sum[l[i]];
	}
	for (int i = 0; i < Q; i++) {
		cout << ans[i] << endl;
	}
}

Measured memory_bytes: 3072
#include<bits/stdc++.h>
using namespace std;
int a[1010410];
int main()
{
    int N;
    cin >> N;
    for(int i=1; i<=N; ++i) cin>>a[i];
    
    int y = 1;
    for(int x = 0; x<=200200; ++x)
    {
        if(y==2)
        {
            printf("%d\n", x);
            return 0;
        }
        y = a[y];
    }
    puts("-1");
}

Measured memory_bytes: 640
from sys import *
from collections import deque
H, W = map(int, stdin.readline().split())
personY, personX = map(int, stdin.readline().split())
gH, gW = map(int, stdin.readline().split())

grid = [list(stdin.readline().strip()) for x in range(H)]
visited = [ [10**10] * W for i in range(H)]
options = deque([[personY-1, personX-1]])

visited[personY-1][personX-1] = 0
while(options):
    y,x = options.popleft()
    if y+1 < H and  grid[y+1][x] == ".":
        if visited[y+1][x] > visited[y][x]:
            options.appendleft((y+1, x))
            visited[y+1][x] = visited[y][x]

    if  y-1 >= 0 and grid[y-1][x] == ".":
        if visited[y-1][x] > visited[y][x]:
            options.appendleft((y-1, x))
            visited[y-1][x] = visited[y][x]

    if x+1 < W and grid[y][x+1] == ".":
        if visited[y][x+1] > visited[y][x]:
            options.appendleft((y, x+1))
            visited[y][x+1] = visited[y][x]

    if x-1 >= 0 and grid[y][x-1] == ".":
        if visited[y][x-1] > visited[y][x]:
            options.appendleft((y, x-1))
            visited[y][x-1] = visited[y][x]
   #-------------------------------------------
    for Y,X in [(2,-2),(2,-1),(2,0),(2,1),(2,2), (1,-2),(1,-1),(1,1),(1,2), (0,-2),(0,2), (-1,-2),(-1,-1),(-1,1),(-1,2), (-2,-2),(-2,-1),(-2,0),(-2,1),(-2,2)]:
       if x+X >= 0 and x+X < W and y+Y >= 0 and y+Y < H and grid[y+Y][x+X] == ".":
           if visited[y+Y][x+X] > visited[y][x] +1:
               options.append((y+Y, x+X))
               visited[y+Y][x+X] = visited[y][x]+1

print(-1 if visited[gH-1][gW-1] == 10**10 else visited[gH-1][gW-1] )


Measured memory_bytes: 130864
//
//  main.cpp
//  B - Battle
//
//  Created by Hashizo on 2020/04/26.
//  Copyright © 2020 Hashizo. All rights reserved.
//

#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <regex>
#include <cmath>

using namespace std;
 
#undef LONG_MAX
#undef LONG_MIN
 
#define LONG_MAX    9223372036854775807
#define LONG_MIN    (-LONG_MAX  -1)
 
#define ll long long
 
#define FOR(i, a, b) for (ll i = (a); i < (b); i++)
#define REP(i, n) FOR(i, 0, n)
 
#define SORT(c) sort((c).begin(), (c).end())
#define REVERSE(v) reverse((v).begin(), (v).end())

int main(int argc, const char * argv[]) {
	ll a,b,c,d;
	cin >> a >> b >> c >> d;
	

	while(1) {
		c = c - b;
		if(c <= 0) {
			cout << "Yes" << endl;
			return 0;
		}
		a = a - d;
		if(a <= 0) {
			cout << "No" << endl;
			return 0;
		}
	}
	return 0;
}


Measured memory_bytes: 3512
#include <bits/stdc++.h>
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define sz(x) (int)((x).size())
#define debug(x) cout << #x << ":" << x << ' ';
#define debugg(x) cout << #x << ":" << x << ' ' << "\n";
#define endl "\n"
#define L(X) ((X)<<1)
#define R(X) (((X)<<1)|1)
#define M(X,Y) (((X)+(Y))>>1)

using namespace std;

typedef unsigned long long ull;
typedef long long int ll;
typedef long double ld;
typedef pair<int,int> pii;

const int MAXN = 1e5 + 5;
const int MOD = 1e9 + 7;
const ll INF = 0x3f3f3f3f3f3f3f3f;
const double EPS = 1e-9;
const double PI = acos(-1);

int add(int x, int y) { return ((x % MOD)  + (y % MOD)) % MOD;             }
int mul(int x, int y) { return ((x % MOD) * (long long)(y % MOD)) % MOD;   }
int sub(int x, int y) { return add(x, -y + MOD);                           }


ll n, h[MAXN], dp[MAXN];

ll solve(ll x) {
	if(dp[x] != -1) return dp[x];
	if(x > n) return INF;
	if(x == n) return 0;
	ll costA = abs(h[x + 1] - h[x]);
	ll costB = abs(h[x + 2] - h[x]);
	return dp[x] = min(costA + solve(x + 1), costB + solve(x + 2));
}

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

	cin >> n;

	memset(dp, -1, sizeof dp);

	for(int i = 1; i <= n ;  ++i) {
		cin >> h[i];
	}

	cout << solve(1) << endl;


	return 0;
}




Measured memory_bytes: 4224
import java.io.*;
import java.util.StringTokenizer;

public class Main {

    public static void main(String[] args) throws IOException {
        init();
        int min = Integer.MAX_VALUE;
        int n = nextInt();
        int ans = 0;
        for (int i = 0; i < n; i++) {
            int b = nextInt();
            if (b < min) ans++;
            min = Math.min(b, min);
        }
        System.out.println(ans);
    }

    //Input Reader
    private static BufferedReader reader;
    private static StringTokenizer tokenizer;

    private static void init() {
        reader = new BufferedReader(new InputStreamReader(System.in));
        tokenizer = new StringTokenizer("");
    }

    private static String next() throws IOException {
        String read;
        while (!tokenizer.hasMoreTokens()) {
            read = reader.readLine();
            if (read == null || read.equals(""))
                return "-1";
            tokenizer = new StringTokenizer(read);
        }

        return tokenizer.nextToken();
    }

    private static int nextInt() throws IOException {
        return Integer.parseInt(next());
    }

    private static long nextLong() throws IOException {
        return Long.parseLong(next());
    }
}

Measured memory_bytes: 44048
#include <bits/stdc++.h>
using namespace std;
using ll = int64_t;
#define rep(i, n) for (int i = 0; i < ((int)(n)); i++) // 0-indexed昇順

int main()
{
  int H, W;
  cin >> H >> W;
  vector<string> M(H);
  rep(i, H) cin >> M.at(i);
  rep(i, H)
  {
    rep(j, W)
    {
      if (M.at(i).at(j) == '#')
        continue;
      int i1 = i - 1;
      int i3 = i + 1;
      int j1 = j - 1;
      int j3 = j + 1;
      int bomb = 0;
      if (i1 >= 0 && j1 >= 0 && M.at(i1).at(j1) == '#')
        bomb++;
      if (i1 >= 0 && M.at(i1).at(j) == '#')
        bomb++;
      if (i1 >= 0 && j3 < W && M.at(i1).at(j3) == '#')
        bomb++;
      if (j1 >= 0 && M.at(i).at(j1) == '#')
        bomb++;
      if (j3 < W && M.at(i).at(j3) == '#')
        bomb++;
      if (i3 < H && j1 >= 0 && M.at(i3).at(j1) == '#')
        bomb++;
      if (i3 < H && M.at(i3).at(j) == '#')
        bomb++;
      if (i3 < H && j3 < W && M.at(i3).at(j3) == '#')
        bomb++;
      M.at(i).at(j) = '0' + bomb;
    }
    cout << M.at(i) << endl;
  }
}

Measured memory_bytes: 256
# -*- coding: utf-8 -*-

import sys

def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(N=None): return list(MAP()) if N is None else [INT() for i in range(N)]
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
INF = 10 ** 19
MOD = 10 ** 9 + 7

def dfs(N, nodes, src):
    """ DFS(木、スタック、重みなし) """

    stack = [(src, -1, 0)]
    dist = [INF] * N
    while stack:
        u, prev, c = stack.pop()
        dist[u] = c
        for v in nodes[u]:
            if v != prev:
                stack.append((v, u, c+1))
    return dist

N = INT()
nodes = [[] for i in range(N)]
for _ in range(N-1):
    a, b = MAP()
    a -= 1; b -= 1
    nodes[a].append(b)
    nodes[b].append(a)

# 木の直径
dist1 = dfs(N, nodes, 0)
u = dist1.index(max(dist1))
dist2 = dfs(N, nodes, u)
L = max(dist2)

if L % 3 != 1:
    print('First')
else:
    print('Second')


Measured memory_bytes: 119500
#include <bits/stdc++.h>
using namespace std;
// (setq-default c-basic-offset 2)

int main() {
  long long h;
  cin >> h;

  long long ret = 0;
  long long iter = 1;
  while (h >= 1) {
    ret += iter;
    iter *= 2;
    h /= 2;
  }
  cout << ret << endl;
  return 0;
}


Measured memory_bytes: 3592
f=0
while 1:
  n=input()
  if n==0: break
  C=[()]*n
  for i in range(n):
    s=raw_input().split(" ")
    C[i]=(i,int(s[1])*3+int(s[3]),s[0])
  C=sorted(C,key=lambda x:(-x[1]))
  if f>0: print
  for e in C: print e[2]+","+str(e[1])
  f=1

Measured memory_bytes: 4228
package main

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

var DY = []int{-1, -1, -1, 0, 0, 1, 1, 1}
var DX = []int{-1, 0, 1, -1, 1, -1, 0, 1}

var scanner = bufio.NewScanner(os.Stdin)

func readLine() string {
	scanner.Scan()
	return scanner.Text()
}

func readLineToInt() []int {
	nums := []int{}
	line := readLine()

	for _, n := range strings.Split(line, " ") {
		if v, err := strconv.Atoi(strings.TrimSpace(n)); err == nil {
			nums = append(nums, v)
		}
	}

	return nums
}

func main() {
	nums := readLineToInt()
	H := nums[0]
	W := nums[1]
	field := []string{}

	for i := 0; i < H; i++ {
		field = append(field, readLine())
	}

	bom_field := make([][]int, H)
	for i := 0; i < H; i++ {
		bom_field[i] = make([]int, W)
	}

	for y := 0; y < H; y++ {
		for x := 0; x < W; x++ {
			ch := field[y][x]

			if ch == '#' {
				for i := 0; i < 8; i++ {
					ny := y + DY[i]
					nx := x + DX[i]
					if (ny < 0 || ny >= H || nx < 0 || nx >= W) {
						continue
					}
					bom_field[ny][nx] += 1
				}
			}
		}
	}

	for y := 0; y < H; y++ {
		for x := 0; x < W; x++ {
			if field[y][x] == '#' {
				fmt.Print("#")
			} else {
				fmt.Print(bom_field[y][x])
			}
		}
		fmt.Println()
	}
}


Measured memory_bytes: 640