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

int solve(string s) {
    int n = s.size();
    queue<string> que;
    que.push("3");
    que.push("5");
    que.push("7");
    int count = 0;
    while (!que.empty()) {
        string top = que.front();
        que.pop();
        if (top.size() > n || (top.size() >= n && top > s)) {
            return count;
        }
        bool three = false, five = false, seven = false;
        for (char c: top) {
            three |= c == '3';
            five |= c == '5';
            seven |= c == '7';
        }
        if (three && five && seven)
            count++;
        que.push(top + "3");
        que.push(top + "5");
        que.push(top + "7");
    }
    return count;
}

int main() {
    string s;
    cin >> s;
    cout << solve(s) << endl;
    return 0;
}


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

int main() {
    int n,sum,a;
    cin>>n;
    a=n;
    for(int i=0;i<10;i++){
        sum+=n%10;
        n/=10;
        }
    if(a%sum==0)cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
}


Measured memory_bytes: 384
#include<bits/stdc++.h>
#define ll long long
#define R register
#define int long long
#define hash cnm
using namespace std;
const int N = 4e5+200;
const int base=1e9+7;
const int mod=998244353;
template <class Ruby> inline void read(Ruby &x)
{
	x=0;
	char ch=getchar(), w=0;
	while(!isdigit(ch))w=(ch=='-'), ch=getchar();
	while(isdigit(ch))x=(x<<1)+(x<<3)+(ch^48), ch=getchar();
	x=w?-x:x;
}

int n, a[N], b[N], ok[N];
int val[N], hash[N];
signed main()
{
	read(n);
	for(R int i=0; i<=n; i++)ok[i]=1;
	for(R int i=1; i<=n; i++)read(a[i]);
	for(R int i=1; i<=n; i++)read(b[i]), b[i+n]=b[i];
	for(R int i=0; i<=30; i++)
	{
		for(R int j=1; j<=n*2; j++)
		{
			hash[j]=(hash[j-1]*base+((b[j]>>i)&1))%mod;
		}
		int tmp0=0, tmp1=0, tmp2=1;
		for(R int j=1; j<=n; j++)
		{
			tmp0=((tmp0*base+((a[j]>>i)&1)))%mod;
			tmp1=((tmp1*base+((a[j]>>i)&1^1)))%mod;
			tmp2=tmp2*base%mod;
		}
		for(R int j=0; j<n; j++)
		{
			int v=((hash[n+j]-hash[j]*tmp2)%mod+mod)%mod;
//			cout<<i<<" "<<j<<" "<<v<<" "<<tmp0<<" "<<tmp1<<endl;
			if(tmp0 != v && tmp1 != v)
			{
				ok[n-j]=0;
			}
			else
			{
				if(tmp1==v)val[n-j]^=(1<<i);
			}
		}
	}
	if(ok[n])cout<<0<<" "<<val[n]<<endl;
	for(R int i=1; i<n; i++)
	{
		if(ok[i])
		{
			cout<<i<<" "<<val[i]<<"\n";
		}
	}
	return 0;
}

Measured memory_bytes: 17792
#pragma region header
#include <bits/stdc++.h>
using namespace std;

#define CPP_CAT(x,y) CPP_CAT_I(x,y)
#define CPP_CAT_I(x,y) x ## y
//#define CPP_STR(x) CPP_STR_I(x)
//#define CPP_STR_I(args...) #args
//#define ASSERT(expr...) assert((expr))

using i8 = int8_t;
using u8 = uint8_t;
using i16 = int16_t;
using u16 = uint16_t;
using i32 = int32_t;
using u32 = uint32_t;
using i64 = int64_t;
using u64 = uint64_t;
using f32 = float;
using f64 = double;
//using f80 = __float80;
#pragma endregion

#pragma region const
constexpr i64 INF = 1'010'000'000'000'000'017LL;
constexpr i64 MOD = 1'000'000'007LL;
constexpr f64 EPS = 1e-12;
constexpr f64 PI = 3.14159265358979323846;
#pragma endregion

#pragma region util
#define FOR(i, start, end) for(i64 i = (start), CPP_CAT(i,xxxx_end)=(end); i < CPP_CAT(i,xxxx_end); ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(f,c,...) (([&](decltype((c)) cccc) { return (f)(std::begin(cccc), std::end(cccc), ## __VA_ARGS__); })(c))

template<typename C>
i64 SIZE(const C& c) { return static_cast<i64>(c.size()); }
template<typename T, size_t N>
i64 SIZE(const T(&)[N]) { return static_cast<i64>(N); }

template<typename T, typename U, typename Comp = less<>>
bool chmax(T& xmax, const U& x, Comp comp = {}) {
	if (comp(xmax, x)) {
		xmax = x;
		return true;
	}
	return false;
}
template<typename T, typename U, typename Comp = less<>>
bool chmin(T& xmin, const U& x, Comp comp = {}) {
	if (comp(x, xmin)) {
		xmin = x;
		return true;
	}
	return false;
}
#pragma endregion

#pragma region init
struct ProconInit {
	static constexpr int IOS_PREC = 15;
	static constexpr bool AUTOFLUSH = false;

	ProconInit() {
		cin.tie(nullptr);
		ios::sync_with_stdio(false);
		cout << fixed << setprecision(IOS_PREC);
		if (AUTOFLUSH)
			cout << unitbuf;
	}
} PROCON_INIT;
#pragma endregion

int main()
{
	i64 A,B;
	cin >> A >> B;

	cout << max({ A+B,A-B,A*B }) << endl;
	return 0;
}


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

int main(){
	int N;
	cin >> N;
	if(N == 1){
		cout << 1 << endl;
	}else if(N%2 == 0){
		cout << 0.5 << endl;
	}else{
		cout << ((N+1)/2.0)/N << setprecision(20)<< endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
int main()
{
	int i,t;
	int data[5];
	scanf("%d %d %d %d %d",&data[0],&data[1],&data[2],&data[3],&data[4]);
	for(i=0;i<5;i++){
		for(t=i+1;t<5;t++){
			if(data[i]<data[t]){
				int work=data[i];
				data[i]=data[t];
				data[t]=work;
			}
		}
	}
	printf("%d %d %d %d %d\n",data[0],data[1],data[2],data[3],data[4]);
	return 0;
}

Measured memory_bytes: 596
#include <stdio.h>
#include <algorithm>

using namespace std;

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



Measured memory_bytes: 2756
#!/usr/bin/env python3
import sys
try:
    from typing import List
except ImportError:
    pass


def solve(H: int, W: int, S: "List[str]"):

    def isbomb(i: int, j: int):
        return 0 <= i < H and 0 <= j < W and S[i][j] == "#"

    ds = [
        (1, 0),
        (1, 1),
        (0, 1),
        (-1, 1),
        (-1, 0),
        (-1, -1),
        (0, -1),
        (1, -1),
    ]

    for i, Si in enumerate(S):
        print("".join(
            c if c == "#" else
            str(sum(
                isbomb(i + di, j + dj)
                for di, dj in ds
            ))
            for j, c in enumerate(Si)
        ))


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    H = int(next(tokens))  # type: int
    W = int(next(tokens))  # type: int
    S = [next(tokens) for _ in range(H)]  # type: "List[str]"
    solve(H, W, S)


if __name__ == '__main__':
    main()


Measured memory_bytes: 3064
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		long a = sc.nextLong();
		long b = sc.nextLong();
		long c = sc.nextLong();
		long k = sc.nextLong();
		if(k % 2 == 0) {
			System.out.println(a - b);
		} else {
			System.out.println(-(a - b));
		}
	}
}


Measured memory_bytes: 23124
# -*- coding: utf-8 -*-
"""
A - Colorful Transceivers
https://beta.atcoder.jp/contests/abc097/tasks/abc097_a

"""
import sys
from sys import stdin
input = stdin.readline


def solve(a, b, c, d):
    if abs(a - c) <= d:
        return 'Yes'
    if abs(a - b) <= d and abs(b - c) <= d:
        return 'Yes'
    return 'No'


def main(args):
    a, b, c, d = map(int, input().split())
    ans = solve(a, b, c, d)
    print(ans)


if __name__ == '__main__':
    main(sys.argv[1:])


Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int n;
  cin>>n;
  bool b=false;
  for(int i=1;i<10;i++){
    for(int j=1;j<10;j++){
      if(i*j==n)b=true;
    }
  }
  if(b)cout<<"Yes";
  else cout<<"No";
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i<n; ++i)
using namespace std;
using ll = int64_t;
using vi = vector<int>;
using vvi = vector<vi>;

int main() {
    int D, G;
    cin >> D >> G;
    vi p(D), c(D), x(D);
    rep(i, D){
        cin >> p[i] >> c[i];
        x[i] = 100*(p[i])*(i+1) + c[i];
    }

    int mi = INT_MAX;
    rep(i, 1<<D) {
        bitset<10> wh(i);
        int sum = 0;
        int j_ = -1;
        rep(j, D){
            if(wh[j]){
                sum += x[j];
            } else {
                j_ = j;
            }
        }
        
        int s=0;
        rep(j, D){
            if(wh[j]){
                s += p[j];
            }
        }
        if(sum >= G) {
            mi = min(mi, s);
        } else if(((G-sum) + (100*(j_+1)) - 1)/(100*(j_+1)) < p[j_]){
            mi = min(mi, s+((G-sum) + (100*(j_+1)) - 1)/(100*(j_+1)));
            //rep(j, D) cout << wh[j]; 
        }
        //cout << endl;
    }
    cout << mi << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <list>
#include <set>
#include <queue>
#include <map>
#include <algorithm>
#include <functional>
#include <string>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
using namespace std;

#define REP(i,p,n) for(int i=p;i<n;++i)
#define rep(i,n) REP(i,0,n)

using ll = long long int;
using pll = pair<ll, ll>;

int main()
{
    ll N;
    cin >> N;

    ll ans = 0;

    vector<ll> divisors;

    for (ll i=1;i*i<=N;++i)
    {
        if ((N % i) == 0)
        {
            divisors.push_back(i);

            const ll j = N / i;
            if (i != j) { divisors.push_back(j); }
        }
    }

    for (const auto i : divisors)
    {
        const ll num = i - 1;

        if (num >= 1 && N / num == N % num)
        {
            ans += num;
        }
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 384
import sys
input = sys.stdin.readline
n = int(input())
ab = [list(map(int,input().split())) for i in range(n)]
l,r = list(zip(*ab))
l = list(l)
r = list(r)
l.sort()
r.sort()
if n%2:
  print((r[n//2]-l[n//2])+1)
else:
  print(((r[n//2-1]+r[n//2])-(l[n//2-1]+l[n//2]))+1)

Measured memory_bytes: 131000
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);i++)
using namespace std;
using ll = long long;
using p = pair<int,int>;
int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);

    int n,p,sum=0,min_s=10000009;
    cin>>n;
    vector<int>x(n);
    rep(i,n)cin>>x[i];
    sort(x.begin(),x.end());
    for(int P=x[0];P<=x.back();P++){
        rep(j,n){
            sum+=pow(x[j]-P,2);
        }
        min_s=min(min_s,sum);
        sum=0;
    }
    cout << min_s<< endl;

    return 0;
}

Measured memory_bytes: 3584
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=(int)a;i<(int)b;++i)
int main(){
  int h,w;cin>>h>>w;
  vector<string> f(h);
  rep(i,h)cin>>f[i];
  rep(i,w+2)cout<<"#";
  cout<<endl;
  rep(i,h){
    cout<<"#";
    cout<<f[i];
    cout<<"#"<<endl;
  }
  rep(i,w+2)cout<<"#";
  cout<<endl;
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
using namespace std;
int main(){
  int N;
  cin >> N;
  int candy[2][N];
  for(int i = 0; i < 2; ++i){
  	for(int j = 0; j < N; ++j){
      cin >> candy[i][j];
  	}
  }
  int max = 0;
  for(int i = 0; i < N; ++i){
    int sumA = 0;
    int sumB = 0;
      for(int j = 0; j <= i; ++j) sumA += candy[0][j];
      for(int k = i; k < N; ++k) sumB += candy[1][k];
    int sum = sumA + sumB;
    if(sum >= max) max = sum;
  }
  cout << max << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)
#define all(c) c.begin(),c.end()
#define pb push_back
#define fs first
#define sc second
#define show(x) cout << #x << " = " << (x) << endl
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
using namespace std;
template<class S,class T> ostream& operator<<(ostream& o,const pair<S,T> &p){
	return o<<"("<<p.fs<<","<<p.sc<<")";
}
template<class T> ostream& operator<<(ostream& o,const vector<T> &vc){
	o<<"{";
	for(const T& v:vc) o<<v<<",";
	o<<"}";
	return o;
}
using ll = long long;
template<class T> using V = vector<T>;
template<class T> using VV = vector<vector<T>>;
int main(){
	V<int> deg(4);
	rep(i,3){
		int x,y;
		cin>>x>>y;
		x--,y--;
		deg[x]++;
		deg[y]++;
	}
	bool uni = false;
	rep(i,4) if(deg[i]==3) uni = true;
	if(uni) cout<<"NO"<<endl;
	else cout<<"YES"<<endl;
}

Measured memory_bytes: 256
import java.util.Scanner;

class Main{
    public static void main(String[] args){
	final Scanner sc=new Scanner(System.in);
	while(sc.hasNext()){
	    int a=sc.nextInt();
	    int b=sc.nextInt();
	    int sum=a+b;
	    int count=0;
	    while(true){
		count++;
		sum/=10;
		if(sum==0) break;
	    }
	    System.out.println(count);
	}
    }
}

Measured memory_bytes: 20424
num = int(input())
kazu = list(map(int, input().split()))
answer = 0
for n in range(1, num - 1):
  a, b, c = kazu[n - 1], kazu[n], kazu[n + 1]
  if (a < b and b < c) or (a > b and b > c):
    answer += 1
print(answer)

Measured memory_bytes: 3060
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Comparator;
import java.util.List;
import java.util.PriorityQueue;
import java.util.Queue;
import java.util.Scanner;

public class Main {

    public static final int MOD = 1000000007;

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int x = Integer.parseInt(sc.next());
        int n = Integer.parseInt(sc.next());
        if (n == 0) {
            System.out.println(x);
            return;
        }
        List<Integer> list = new ArrayList<>();
        for (int i = 0; i <= 101; i++) {
            list.add(i);
        }
        Integer[] p = new Integer[n];
        for (int i = 0; i < n; i++) {
            p[i] = Integer.parseInt(sc.next());
        }
        Arrays.sort(p, Comparator.reverseOrder());
        for (int i = 0; i < n; i++) {
            list.remove(p[i]);
        }
        int sub = 101;
        Queue<Integer> q = new PriorityQueue<>();
        for (int a : list) {
            if (sub == Math.abs(a - x)) {
                sub = Math.abs(a - x);
                q.add(a);
            } else if (sub > Math.abs(a - x)) {
                sub = Math.abs(a - x);
                q.clear();
                q.add(a);
            }
        }
        System.out.println(q.peek());
    }
}

Measured memory_bytes: 35832
#define _GLIBCXX_DEBUG
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
using namespace std;

int main(){

    int N, M, T;
    double sum;
    T = 0;

    cin >> N >> M;

    vector<int> vote(N);

    for(int i = 0; i < N; i++){
        cin >> vote.at(i);
        sum += vote.at(i);
    }

    sum = sum / (M*4);

    for(int i = 0; i < N; i++){
        if(sum <= vote.at(i)){
            T++;
        }
    }

    if(T >= M){
        cout << "Yes" << endl; 
    }
    else{
        cout << "No" << endl;
    }

}

Measured memory_bytes: 256
fn read<T: std::str::FromStr>(
    stdin_lock: &mut std::io::StdinLock,
    buf: &mut Vec<u8>,
    delimiter: u8,
) -> T {
    buf.clear();
    let l = std::io::BufRead::read_until(stdin_lock, delimiter, buf).unwrap();
    buf.truncate(l - 1); // remove delimiter
    let s = unsafe { std::str::from_utf8_unchecked(&buf) };
    s.parse().unwrap_or_else(|_| panic!("read"))
}

fn main() {
    let stdin = std::io::stdin();
    let mut stdin_lock = stdin.lock();
    let mut buf: Vec<u8> = Vec::new();
    let n: i32 = read(&mut stdin_lock, &mut buf, b' ');
    let a: i32 = read(&mut stdin_lock, &mut buf, b' ');
    let b: i32 = read(&mut stdin_lock, &mut buf, b'\n');
    let mut ans: i32 = 0;
    for i in 1..n + 1 {
        let mut m = i;
        let mut s = 0;
        while m != 0 {
            s += m % 10;
            m /= 10;
        }
        if a <= s && s <= b {
            ans += i;
        }
    }
    println!("{}", ans);
}


Measured memory_bytes: 4352
//http://judge.u-aizu.ac.jp/onlinejudge/review.jsp?rid=2676345#1
//http://judge.u-aizu.ac.jp/onlinejudge/review.jsp?rid=2676345#1
#include <iostream>
#include<cstdlib>
#include<queue>
#include<set>
#include<vector>
#include<string>
#include<algorithm>
#include<stack>
#include<map>
#include<cstdio>
#include<fstream>
#include<cstring>
using namespace std;
#define rep(i,a) for(int i=0;i<a;i++)
#define mp make_pair
#define P pair<int,int>
#define ll __int64
int n,m;
int t[100001];
const int MA=1<<21;
int sum[21][100001];//累積和
int cntu[21];//各種類が何個使われているか

int dp[MA];//attention!

const int INF=1000000007;


int main(){
cin>>n>>m;
rep(i,n){
cin>>t[i];
cntu[t[i]]++;
}
for(int i=1;i<=m;i++){
	for(int j=0;j<n;j++){
		if(t[j]==i)sum[i][j+1]=1;
	}
	for(int j=2;j<=n;j++)sum[i][j]+=sum[i][j-1];
	//for(int j=0;j<=n;j++)cout<<sum[i][j]<<" ";cout<<endl;
}


rep(i,MA)dp[i]=INF;
dp[0]=0;

bool used[20];
int cnt,ruikei;

for(int i=0;i<m;i++){
	for(int j=0;j<(1<<m);j++){//0から2^m-1まで回す
			cnt=0;
			ruikei=0;
			rep(k,m)used[k]=0;

			rep(k,m){
				if(j&(1<<k)){
					cnt++;
					used[k]=1;
					ruikei+=cntu[k+1];
				}
			}//ここまでで、jのbitを把握
			if(cnt!=i)continue;
			
			rep(k,m){
				if(used[k]==0){
					int next=j+(1<<k);
					int add;
					int l=ruikei;
					int r=ruikei+cntu[k+1];
					add=cntu[k+1]-(sum[k+1][r]-sum[k+1][l]);
					//cout<<j<<" "<<next<<" "<<add<<endl;
					dp[next]=min(dp[next],dp[j]+add);

				}
			}
			
	}
}
//for(int i=0;i<(1<<m);i++)cout<<i<<" "<<dp[i]<<endl;
cout<<dp[(1<<m)-1]<<endl;
	return 0;
}




Measured memory_bytes: 19404
# -*- coding: utf-8 -*-
from collections import deque


s = deque(list(input()))
q = int(input())

reverce = False
for _ in range(q):
    query = input()
    if query[0] == '1':
        reverce = not reverce
    else:
        _, f, c = query.split()
        if (f == '1' and not reverce) or (f == '2' and reverce):
            s.appendleft(c)
        else:
            s.append(c)

if reverce:
    s.reverse()

print("".join(s))


Measured memory_bytes: 74216
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;

/**
 * @author Pavel Mavrin
 */
public class Main {

    private void solve() throws IOException {
        String s = next();
        if (s.startsWith("YAKI")) {
            out.println("Yes");
        } else {
            out.println("No");
        }
    }

    // ------------------

    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    StringTokenizer st;
    PrintWriter out = new PrintWriter(System.out);

    String next() throws IOException {
        while (st == null || !st.hasMoreTokens()) {
            st = new StringTokenizer(br.readLine());
        }
        return st.nextToken();
    }

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

    public static void main(String[] args) throws IOException {
        new Main().run();
    }

    private void run() throws IOException {
        solve();
        out.close();
    }

}


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

using namespace std;

int main()
{
    int n;
    int dy[128] = {0}, dx[128] = {0};
    
    dy['N'] = 1, dy['S'] = -1, dx['E'] = 1, dx['W'] = -1;
    
    while (scanf("%d", &n) && n){
        int mp[32][32] = {{0}};
        
        for (int i = 0; i < n; i++){
            int x, y;
            scanf("%d %d", &x, &y);
            mp[y][x]++;
        }
        
        int m;
        scanf("%d", &m);
        
        int cnt = 0;
        int ny = 10, nx = 10;
        for (int i = 0; i < m; i++){
            char c;
            int r;
            scanf(" %c %d", &c, &r);
            for (int j = 0; j < r; j++){
                ny += dy[c];
                nx += dx[c];
                if (mp[ny][nx]){
                    cnt++;
                    mp[ny][nx]--;
                }
            }
        }
        
        printf("%s\n", cnt == n ? "Yes" : "No");
    }
    
    return (0);
}

Measured memory_bytes: 1172
#include <iostream>
using namespace std;
 int main()
{
 int a, b, c;

 cin>>a>>b>>c;;

 int ispoor = 0;
 if (a == b && b != c) ispoor = 1;
 if (b == c && c != a) ispoor = 1;
 if (c == a && a != b) ispoor = 1;

 if (ispoor) {
 puts("Yes");
 } else {
 puts("No");
 }

 return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>

void merge_sort(long long x[], int n)
{
	static long long y[200001] = {};
	if (n <= 1) return;
	merge_sort(&(x[0]), n/2);
	merge_sort(&(x[n/2]), (n+1)/2);
	
	int i, p, q;
	for (i = 0, p = 0, q = n/2; i < n; i++) {
		if (p >= n/2) y[i] = x[q++];
		else if (q >= n) y[i] = x[p++];
		else y[i] = (x[p] < x[q])? x[p++]: x[q++];
	}
	for (i = 0; i < n; i++) x[i] = y[i];
}

int main()
{
	int i, N, x[200001], y[200001];
	long long a[200001], b[200001];
	scanf("%d", &N);
	for (i = 1; i <= N; i++) {
		scanf("%d %d", &(x[i]), &(y[i]));
		a[i-1] = x[i] + y[i];
		b[i-1] = x[i] - y[i];
	}
	merge_sort(a, N);
	merge_sort(b, N);
	if (a[N-1] - a[0] > b[N-1] - b[0]) printf("%lld\n", a[N-1] - a[0]);
	else printf("%lld\n", b[N-1] - b[0]);
	fflush(stdout);
	return 0;
}

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

int frog(int *a,int n){
    int *dp=new int[n];
    dp[0]=0;
    dp[1]=abs(a[0]-a[1]);
    for(int i=2;i<n;i++){
        int p=dp[i-1]+abs(a[i]-a[i-1]);
        int q=dp[i-2]+abs(a[i]-a[i-2]);
        dp[i]=min(p,q);
    }
    int op=dp[n-1];
    delete [] dp;
    return op;
}

int main()
{
    //ios_base::sync_with_stdio(false);
    //cin.tie(NULL);

    int n;
    cin>>n;
    int *a=new int[n];
    for(int i=0;i<n;i++){
        cin>>a[i];
    }
    int op=frog(a,n);
    cout<<op;

    delete [] a;
    return 0;
}

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

typedef long long llt;

const int MaxN = 50 + 5;
const llt Mod = 1e9 + 7;

struct Matrix {
  llt mat[MaxN][MaxN];
  Matrix() {
    memset(mat, 0, sizeof mat);
  }
};

int N; llt K;
Matrix G;

inline Matrix operator * (Matrix A, Matrix B) {
  Matrix C;
  for (int i = 1; i <= N; ++i)
    for (int j = 1; j <= N; ++j) {
      for (int k = 1; k <= N; ++k)
        C.mat[i][j] = (C.mat[i][j] + A.mat[i][k] * B.mat[k][j]) % Mod;
    }
  return C;
}

inline Matrix operator ^ (Matrix low, llt high) {
  Matrix res;
  for (int i = 1; i <= N; ++i) res.mat[i][i] = 1;
  while (high) {
    if (high & 1) res = res * low;
    high >>= 1;
    low = low * low;
  }
  return res;
}

void init() {
  scanf("%d %lld", &N, &K);
  for (int i = 1; i <= N; ++i) for (int j = 1; j <= N; ++j)
    scanf("%lld", &G.mat[i][j]);
}

void solve() {
  G = G ^ K;
  llt res = 0;
  for (int i = 1; i <= N; ++i) for (int j = 1; j <= N; ++j)
    res = (res + G.mat[i][j]) % Mod;
  cout << res << endl;
}

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

Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define io ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
int main()
{
    io
    float n;
  	cin >> n;
  	cout << (int)(ceil)(n/2) << "\n";
    return 0;
}

Measured memory_bytes: 256
using System;

class MainClass {
  public static void Main (string[] args) {
    //入力
    var N = long.Parse(Console.ReadLine());
    var ans = (long)0;
    //処理
    if((N % 11) == 0){
      ans = (N / 11) * 2;
    }else if(N % 11 <= 6){
      ans = (N / 11) * 2 + 1;
    }else if(N % 11 > 6){
      ans = (N / 11) * 2 + 2;
    }
        
    //出力
    Console.WriteLine(ans);
  }
}

Measured memory_bytes: 11092
def m(L,R):
 T=[]
 for l in L[::-1]:
  while R and R[-1]>l:T+=[R.pop()]
  T+=[l]
 return R+T[::-1]
def d(A):
 l=len(A);global c;c+=l
 s=l//2;return m(d(A[:s]),d(A[s:]))if l>1 else A
def s():
 print(*d(list(map(int,input().split()))))
 print(c)
if'__main__'==__name__:c=-int(input());s()


Measured memory_bytes: 63692
#include <iostream>
#include <algorithm>
#include <set>
#include <functional>
#include <list>
#include <bitset>
#include <numeric>
#include <utility>
#include <cmath>
#include <vector>
#include <queue>
#include <string>
#include <map>
#include<deque>
#include<iomanip>

#define INF 1e9
#define MOD 1000000007
#define ll long long
using namespace std;
int dx[4]={1,0,-1,0},dy[4]={0,1,0,-1};
typedef unsigned long long ull;
typedef pair<ll, int> pr;

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n,m;
    cin>>n>>m;
    vector<int>x(m);
    for(int i=0;i<m;i++){
        cin>>x[i];

    }
    sort(x.begin(),x.end());
    // for(int i=0;i<m;i++){
    //     cout<<x[i]<<" ";
    // }
//    cout<<endl;

    vector<int>sa;
    for(int i=0;i<m-1;i++){
//        cout<<x[i+1]-x[i]<<" qqq"<<endl;
        sa.push_back(x[i+1]-x[i]);
    }
    sort(sa.begin(),sa.end());
    int q=0;
//    cout<<"qq"<<endl;
    for(int i=0;i<min(n-1,m-1);i++){
        q+=sa[m-2-i];
    }
//    cout<<q<<" q"<<endl;
    cout<<x[m-1]-x[0]-q<<endl;
    return 0;
}

Measured memory_bytes: 1276
#include<iostream>
#include<string>
#include<algorithm>
#include<cstdlib>
#include<cmath>
#include<vector>
#include<list>

using namespace std;

uint64_t num_all(int n){

  return (uint64_t)(4 * ((uint64_t)1<<n) -3);

}

uint64_t num_pat(int n){

  return (uint64_t)( ((uint64_t)1<<(n+1)) -1 );

}

int main(void){
  int N;
  uint64_t X;
  cin >> N;
  cin >> X;

  uint64_t l=1;
  uint64_t r=num_all(N);
  ////cout<< num_all(31) << endl;;
  //cout<< r << endl;;

  uint64_t cnt=0;

  int layer=N;
  //cout<< X << endl;
  //cout<< layer << endl;
  //cout<< num_pat(1) << endl;

  while(r - l > 0){
    //cout<< layer << endl;
    //cout<< r-l << endl;
    //cout<< r << endl;
    //cout<< l << endl;
    //cout<< X << endl;

    if(X == l){
      break;
    }

    else if(X == r){
      cnt += num_pat(layer);
      break;
    }


    if(layer==1){
      if(X-l < 4){
        cnt+=(X-l);
        break;
      }
      else{
        cnt+=3;
        break;
      }
    }

    if( X < (r+l)/2 ){
      //cout<< "smaller!" << endl;
      r=(r+l)/2 -1;
      l++;
      layer--;
    }
    else if( X > (r+l)/2 ){
      //cout<< "bigger!" << endl;
      l=(r+l)/2 +1;
      r--;
      layer--;
      cnt += num_pat(layer)+1;
    }
    else{
      //cout<< "same!" << endl;
      layer--;
      cnt += num_pat(layer)+1;
      break;
    }

  }


  cout<< cnt << endl;
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define lli long long int
#define ulli unsigned lli
#define ld long double
#define pb push_back
#define mp make_pair
#define bp pop_back
#define vi vector<int>
#define vvi vector< vector<int> >
#define vli vector<lli>
#define vvli vector< vector<lli> >
#define pii pair <int, int>
#define pli pair <lli, lli>
#define vpi vector<pii>
#define ppi pair<pii,int>
#define pip pair<int,pii>
#define forn(i,n) for(i=0;i<n;i++)
#define rof(i,k,n) for(i=k;i>=n;i--)
#define wh(k) while(k--)
#define mod 1000000007
#define all(i,m) auto i=m.begin();i!=m.end();i++
#define mii map<int,int>
#define F first
#define S second

const int MAX=1000000;

int main()
{
    fast;
    int s;
    cin>>s;
    if(s<3)
    {
    	cout<<"0\n";
    	exit(0);
    }
    lli dp[s+1];
    dp[0]=1;
    dp[1]=dp[2]=-1;
    for(int i=3;i<=s;i++)
    {
    	lli ans=0;
    	for(int j=i-3;j>=0;j--)
    	{
    		if(dp[j]!=-1)
    			ans=(ans+dp[j])%mod;
    	}
    	dp[i]=ans;
    }
    cout<<dp[s]<<'\n';
    return 0;
}

Measured memory_bytes: 3672
import math


A,B,N = map(int, input().split())

def func(x):
    return math.floor(A*x / B) - A * math.floor(x / B)
"""
for i in range(N+1):
    print(i, func(i))
"""

#exit()
if N >= B:

    print(func(B-1))
else:
    print(func(N))

Measured memory_bytes: 9020
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <map>
#include <string>
#include <vector>
#include <cmath>
#include <random>
#include <climits>
#include <set>
#include <deque>
#include <queue>
#include <bitset>
#include <stack>
#include <regex>

#define mod 1000000007
#define INF2 9999999999
#define INF (1<<30)
#define rep(i,n) for(int (i)=0; (i)<(n); (i)++)
#define P pair<int, int>

using namespace std;
using ll = int64_t;

int dx[] = {1, 0, -1, 0};
int dy[] = {0, 1, 0, -1};
int DX[] = {1, 1, 0, -1, -1, -1, 0, 1};
int DY[] = {0, -1, -1, -1, 0, 1, 1, 1};

void solve(){
    ll n, x, ans=0;
    cin >> n >> x;
    ll a[n];
    rep(i, n) cin >> a[i];

    if(a[0] > x) ans += (a[0]-x), a[0] = x;
    for(int i = 1; i < n; i++){
        if(a[i]+a[i-1] > x){
            ll temp = (a[i]+a[i-1])-x;
            ans += temp;
            a[i] -= temp;
        }
    }
    cout << ans << endl;
}

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

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
typedef int64_t ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
struct Solution {
    void solve(std::istream& in, std::ostream& out) {
        ll n, m;
        in >> n >> m;
        vvll g(n + 1, vll());
        map<ll, ll> h;
        for (ll i = 0; i < m; i++) {
            ll s, t;
            in >> s >> t;
            g[s].push_back(t);
            g[t].push_back(s);
            h[s]++;
            h[t]++;
        }
        stack<ll> st;
        for (ll i = 1; i <= n; i++) {
            if (h[i] == 1) {
                st.push(i);
            }
        }
        ll ans = 0;
        while (st.size()) {
            ll i = st.top();
            st.pop();
            ans++;
            for (auto& j : g[i]) {
                h[j]--;
                if (h[j] == 1) {
                    st.push(j);
                }
            }
        }
        out << (ans == n ? ans - 1 : ans) << '\n';
    }
};
void solve(std::istream& in, std::ostream& out) {
    out << std::setprecision(12);
    Solution solution;
    solution.solve(in, out);
}
#include <fstream>
#include <iostream>
int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    istream& in = cin;
    ostream& out = cout;
    solve(in, out);
    return 0;
}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using static System.Console;

class Program
{
    static void Main(string[] args)
    {
        var ST = ReadLine().Split(' ');
        var (S, T) = (ST[0], ST[1]);

        var ans = T + S;

        WriteLine(ans);
    }
}


Measured memory_bytes: 25664
n = int(input())

result  = [0,0,0,0]

for i in range(n):
    s = input()
    if s == "AC":
        result[0] += 1
    elif s == "WA":
        result[1] += 1
    elif s == "TLE":
        result[2] += 1
    elif s == "RE":
        result[3] += 1


print("AC x " + str(result[0]))
print("WA x " + str(result[1]))
print("TLE x " + str(result[2]))
print("RE x " + str(result[3]))

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

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

  vector<int> x(n), y(m);
  int max_x = X, min_y = Y;
  for (int i = 0; i < n; i++) {
    cin >> x[i];
    max_x = max(max_x, x[i]);
  }
  for (int i = 0; i < m; i++) {
    cin >> y[i];
    min_y = min(min_y, y[i]);
  }

  bool flag = false;
  if (max_x < min_y) {
    flag = true;
  }

  if (flag) {
    cout << "No War" << endl;
  }
  else {
    cout << "War" << endl;
  }


}


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

int main() {
    string s;
    cin >> s;
    long long ans = 0;
    int n = s.size();
    for (int i = 0; i < (1 << n - 1);  i++) {
        int idx = 0;
        for (int j = 0; j < n - 1; j++) {
            if (i >> j & 1) {
                string t(s.substr(idx, j-idx+1));
                ans += stoll(t);
                idx = j + 1;
            }
        }
        string t(s.substr(idx, n-idx));
        ans += stoll(t);
    }
    printf("%lld\n", ans);
    return 0;
}

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

int main() {
    //input
    int A,B,C;cin >> A >> B >> C;
    int p;
    p = 0;
    A = A % B;


    //compute
    for(int i = 1; i < B;i++){
        if(( A * i ) % B == C ){
            p = 1;
            break;
        }
    }

    //output
    if(p == 1 ){
        cout << "YES" << endl;
    }else{
        cout << "NO" << endl;
    }

}

Measured memory_bytes: 3636
// --霊長類の暇つぶし競プロ
// --（飲んだくれ中 @ 飲み屋）
// -- 生中３杯目
#include <iostream>
#include <cmath>
#include <vector>
#include <cstdio>
#include <algorithm>
#include <string>

using namespace std;

typedef long long LL;
typedef unsigned int UI;

#define rSort(a) 		sort(a.rbegin(),a.rend())
#define Sort(a) 		sort(a.begin(),a.end())
#define Reverse(a) 		reverse(a.begin(),a.end())
#define Sum(a)  		accumulate(a.begin(), a.end(), 0)
#define REP(i, n) 		for(UI i = 0;i < n;i++)
#define REPR(i, n) 		for(UI i = n;i >= 0;i--)
#define FOR(i, m, n) 	for(UI i = m;i < n;i++)
#define pb(i) 			push_back(i)
#define SWAP(x,y) 		((x!=y)&&(x^=y,y^=x,x^=y))

#define MOD  			(LL)1e9 + 7;
#define INF  			(LL)1 << 62;

int main(int argc, char* argv[]) {

	cin.tie(0);
	ios::sync_with_stdio(false);

	string s,ans;

	cin >> s;

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

		if(s[i]=='0'){
			ans+="0";
		}else if(s[i]=='1'){
			ans+="1";
		}else if(s[i]=='B'){
			if(ans.size()>0){
				ans.erase(ans.size()-1);
			}
		}
	}

    cout << ans << endl;

	return 0;
}


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

int main() {
    int N;
    cin >> N;
    int d[N];
    for(int i = 0; i < N; ++i) cin >> d[i];

    int counter = 1;
    sort(d, d+N, greater<int>());
    for(int i = 1; i < N; ++i){
        if(d[i-1] > d[i]) counter++;
    }

    cout << counter << endl;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <cmath>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <complex>
#include <unordered_map>
#include <unordered_set>
#include <random>
#include <cassert>
#include <fstream>
#define popcount __builtin_popcount
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
const ll MOD=1e9+7;
int main()
{
	int n; cin>>n;
	vector<double> vx[4], vy[4];
	map<char, int> mp;
	mp['R']=0, mp['L']=1, mp['U']=2, mp['D']=3;
	for(int i=0; i<n; i++){
		char d; double xi, yi; cin>>xi>>yi>>d;
		vx[mp[d]].push_back(xi), vy[mp[d]].push_back(yi);
	}
	double x[6], y[6];
	if(vx[0].empty()){
		x[0]=-1e10, x[3]=1e10;
	}else{
		x[0]=*max_element(vx[0].begin(), vx[0].end()), x[3]=*min_element(vx[0].begin(), vx[0].end());
	}
	if(vx[1].empty()){
		x[1]=-1e10, x[4]=1e10;
	}else{
		x[1]=*max_element(vx[1].begin(), vx[1].end()), x[4]=*min_element(vx[1].begin(), vx[1].end());
	}
	if(vx[2].empty()){
		x[2]=-1e10, x[5]=1e10;
	}else{
		x[2]=*max_element(vx[2].begin(), vx[2].end()), x[5]=*min_element(vx[2].begin(), vx[2].end());
	}
	if(!vx[3].empty()){
		x[2]=max(x[2], *max_element(vx[3].begin(), vx[3].end())), x[5]=min(x[5], *min_element(vx[3].begin(), vx[3].end()));
	}

	if(vy[2].empty()){
		y[0]=-1e10, y[3]=1e10;
	}else{
		y[0]=*max_element(vy[2].begin(), vy[2].end()), y[3]=*min_element(vy[2].begin(), vy[2].end());
	}
	if(vy[3].empty()){
		y[1]=-1e10, y[4]=1e10;
	}else{
		y[1]=*max_element(vy[3].begin(), vy[3].end()), y[4]=*min_element(vy[3].begin(), vy[3].end());
	}
	if(vy[0].empty()){
		y[2]=-1e10, y[5]=1e10;
	}else{
		y[2]=*max_element(vy[0].begin(), vy[0].end()), y[5]=*min_element(vy[0].begin(), vy[0].end());
	}
	if(!vy[1].empty()){
		y[2]=max(y[2], *max_element(vy[1].begin(), vy[1].end())), y[5]=min(y[5], *min_element(vy[1].begin(), vy[1].end()));
	}
	double ans=1e18;
	for(int i=0; i<=200000000; i++){
		double t=(double)i/2;
		double xmx=max({x[0]+t, x[1]-t, x[2]}), xmn=min({x[3]+t, x[4]-t, x[5]});
		double ymx=max({y[0]+t, y[1]-t, y[2]}), ymn=min({y[3]+t, y[4]-t, y[5]});
		ans=min(ans, (xmx-xmn)*(ymx-ymn));
	}
	printf("%.10lf\n", ans);
	return 0;
}

Measured memory_bytes: 2256
#include <algorithm>
#include <bitset>
#include <climits>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>

#define MOD 1000000007
#define MOD2 998244353
#define int long long
#define double long double
#define EPS 1e-9
//#define PI 3.14159265358979

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

using namespace std;

template < typename T >
ostream &operator<<(ostream &os, const vector< T > &A) {
	for (int i = 0; i < A.size(); i++)
		os << A[i] << " ";
	os << endl;
	return os;
}
template <>
ostream &operator<<(ostream &os, const vector< vector< int > > &A) {
	int N = A.size();
	int M;
	if (N > 0)
		M = A[0].size();
	for (int i = 0; i < N; i++) {
		for (int j = 0; j < M; j++)
			os << A[i][j] << " ";
		os << endl;
	}
	return os;
}

typedef pair< int, int > pii;
typedef long long ll;

struct edge {
	int from, to, d, c;
	edge(int _from = 0, int _to = 0, int _d = 0, int _c = 0) {
		from = _from;
		to = _to;
		d = _d;
		c = _c;
	}
	bool operator<(const edge &rhs) const {
		return (d == rhs.d) ? (c < rhs.c) : (d < rhs.d);
	}
};
struct aabb {
	int x1, y1, x2, y2;
	aabb(int x1, int y1, int x2, int y2) : x1(x1), y1(y1), x2(x2), y2(y2) {}
};

typedef vector< edge > edges;
typedef vector< edges > graph;
struct flow {
	int to, cap, rev, cost;
	flow(int to = 0, int cap = 0, int rev = 0, int cost = 0) : to(to), cap(cap), rev(rev), cost(cost) {}
};
typedef vector< vector< flow > > flows;

const int di[4] = {0, -1, 0, 1};
const int dj[4] = {-1, 0, 1, 0};
const int ci[5] = {0, 0, -1, 0, 1};
const int cj[5] = {0, -1, 0, 1, 0};
const ll LINF = LLONG_MAX / 2;
const int INF = INT_MAX / 2;
const double PI = acos(-1);

int pow2(int n) { return 1LL << n; }
template < typename T, typename U >
bool chmin(T &x, const U &y) {
	if (x > y) {
		x = y;
		return true;
	}
	return false;
}
template < typename T, typename U >
bool chmax(T &x, const U &y) {
	if (x < y) {
		x = y;
		return true;
	}
	return false;
}

struct initializer {
	initializer() {
		cout << fixed << setprecision(20);
	}
};
initializer _____;

int N, M, K, T, Q, H, W;
signed main() {
	cin >> N;
	vector< int > A(N);
	rep(i, N) cin >> A[i];
	int ans = 0;
	rep(i, N) {
		while (A[i] % 2 == 0) {
			ans++;
			A[i] /= 2;
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 384
N = int(input())
L = list(map(int, input().split()))

ans1 = 1
flag = ''
for i in range(1, N):
  if flag == '':
    if L[i] < L[i-1]:
      flag = 'minus'
    elif L[i] > L[i-1]:
      flag = 'plus'
    else:
      flag = ''

  if flag == 'plus':
    if L[i] < L[i-1]:
      flag = ''
      ans1 += 1
  elif flag == 'minus':
    if L[i] > L[i-1]:
      flag = ''
      ans1 += 1


print(ans1)

Measured memory_bytes: 14252
import sys

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007


def main():
    s = readline().strip()
    print(s[::2])
    
    return


if __name__ == '__main__':
    main()


Measured memory_bytes: 9100
#include<cstdio>
#include<algorithm>
int main(){
    char s[27],s2[27];
    int c[26]={};
    scanf("%s",s);
    int len=0;
    while(s[len]!='\0'){
        c[s[len]-'a']++;
        len++;
    }
    if(len<26){
        int i=0;
        while(c[i]==1)i++;
        printf("%s%c",s,'a'+i);
    }else{
        for(int i=0;i<26;i++)s2[i]=s[i];
        bool flag=std::next_permutation(s,s+26);
        if(!flag)printf("-1");
        else{
            int l=0;
            while(s[l]==s2[l])l++;
            for(int i=0;i<=l;i++)printf("%c",s[i]);
        }
    }
    return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <string>
#include <cstring>
#include <utility>
#include <set>
#include <stack>
#include <climits>

#define rep(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define all(x) (x).begin(),(x).end()
#define MEMSET(v, h) memset((v), h, sizeof(v))
typedef long long ll;

using namespace std;

int main(void){
    ll N, K;
    ll H[400];
    MEMSET(H, 0);
    cin>>N>>K;
    rep(i, N) cin>>H[i+1];
    ll dp[400][400];
    rep(i, N) rep(j, K+1) dp[i+1][j]=9000000000000;
    rep(i, N) rep(j, K+1){
        if(i==0&&j!=0) break;
        
    
        //dp[i+1][j]=min(dp[i+1][j], dp[i][j]+max(H[i+1]-H[i], (ll)0));
        rep(t, K-j+1){
            if(i+t==N){
                dp[N][j+t-1]=min(dp[i][j], dp[N][j+t-1]);
                break;
            }
            dp[i+t+1][j+t]=min(dp[i+t+1][j+t], dp[i][j]+max((ll)0, H[i+t+1]-H[i]));
            
            /*cout<<i<<" "<<j<<" " <<t<<endl;
            rep(l, N+1){
                rep(m, K+1) cout<<dp[l][m]<<" ";
                cout<<endl;
            }
            cout<<endl;*/
        }
    }
    ll Minim=90000000000000;
    rep(i, K+1){
        Minim=min(Minim, dp[N][i]);
    }
    /*rep(i, N+1){
        rep(j, K+1) cout<<dp[i][j]<<"\t\t";
        cout<<endl;
    }*/
    cout<<Minim<<endl;
    return 0;
}


Measured memory_bytes: 1152
#include <bits/stdc++.h>
// statics
using namespace std;
using int64 = long long;
using PAIR = pair<int, int>;
constexpr int INF = 1 << 30;
constexpr int64 LINF = 1LL << 60;
constexpr int MOD = 1e9 + 7;
constexpr int MAX_N = 1e5 + 1;

// init/input
#define int int64
#define INIT ios::sync_with_stdio(false);cin.tie(0);
#define VAR(type, ...) type __VA_ARGS__;MACRO_VAR_Scan(__VA_ARGS__);
template<typename T> void MACRO_VAR_Scan(T &t) {cin>>t;}
template<typename First, typename...Rest> void MACRO_VAR_Scan(First &first, Rest&...rest) {cin>>first;MACRO_VAR_Scan(rest...);}
#define VEC(type, c, n) vector<type> c(n);for(auto &&i:c)cin>>i;

// out
#define OUT(dist) cout<<(dist);
#define FOUT(n, dist) cout <<fixed<<setprecision(n)<<(dist);
#define SP cout<<" ";
#define BR cout<<"\n";
#define debug(x) cerr << #x << ":" << (x);BR;

// utility
#define ALL(a) (a).begin(), (a).end()
#define EACH(i, a) for(auto &&i:(a))
#define FOR(i, a, b) for(int i=(a);i<(b);++i)
#define RFOR(i, a, b) for(int i=(b)-1;i>=0;--i)
#define REP(i, n) for(int i=0;i<(n);++i)
#define RREP(i, n) for(int i=(n)-1;i>=0;--i)

signed main() {
  INIT;
  
  VAR(int, n, a, b);
  VEC(int, x, n);
  int ans = 0;
  REP(i, n - 1) {
    int d = x[i + 1] - x[i];
    ans += min(d * a, b);
  }
  OUT(ans)BR;
  
  return 0;
}


Measured memory_bytes: 1024
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<utility>
#include<tuple>
#include<map>
#include<queue>
#include<set>
#include<stack>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>

using namespace std;

using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

#define BIL ((ll)1e9)
#define MOD ((ll)1e9+7)
#define INF (1LL<<60)           //1LL<<63でオーバーフロー
#define inf (1<<29)             //1<<29でオーバーフロー

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

    ll ans=0;
    if((b-a-1)%2==0){
        ans=min(a-1,n-b)+1+(b-a-1)/2;
    }else{
        ans=(b-a-1)/2+1;
    }

    cout << ans << endl;

    return 0;
}


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

using namespace std;

const int N = 55;
int n,m;
char a[N][N],b[N][N];

bool check(int u,int v){
	for(int i=1;i<=m;i++){
		for(int j=1;j<=m;j++){
			if(b[i][j]!=a[u+i-1][v+j-1])
				return false;
		}
	}
	return true;
}

int main()
{
	std::ios::sync_with_stdio(false);
    cin.tie(0);
    memset(a,'1',sizeof(a));
    memset(b,'2',sizeof(b));
    cin >> n >> m;
    for(int i=1;i<=n;i++){
    	for(int j=1;j<=n;j++){
    		cin >> a[i][j];
		}
	}
    for(int i=1;i<=m;i++){
    	for(int j=1;j<=m;j++){
    		cin >> b[i][j];
		}
	}
	
    for(int i=1;i<=n;i++){
    	for(int j=1;j<=n;j++){
    		if(a[i][j]==b[1][1] && i+m<=n+1 && j+m<=n+1){
    			if(check(i,j)){
    				cout << "Yes" << "\n";
    				return 0;
				}
			}
		}
	}
    cout << "No" << "\n";
    
	return 0;
}


Measured memory_bytes: 256
n = int(input())
l = list(map(int, input().split()))
s = sorted(l)
cost = 0
for i in range(n):
    a = l.index(s[i])
    j = 0
    while a > i:
        j += 1
        b = l.index(s[a])
        cost += l[b]
        l[a], l[b] = l[b], l[a]
        a = b
    cost += min(s[i] * j, s[i] * 2 + s[0] * (j + 2))
print(cost)

Measured memory_bytes: 7760
#include <iostream>
#include <string>
#include <math.h>
#include <map>
#include <vector>
#include <algorithm>
#define REP(i, n) for(int i = 0; i < (n); i++)

using namespace std;
int n;
vector<int> uv[200001];
int a[200001];
int ans[200001];
void solve(int src, int fr, int* l, int ln) {

	int index = -1, orig;

	int* match = lower_bound(l, l + ln, a[src]);
	index = match - l;

	if (l[index] >= a[src] && ((index > 0 && l[index - 1] < a[src]) || (index == 0))) {
		index = index;
		orig = l[index];
		l[index] = a[src];
	}

	if (a[src] > l[ln - 1]) {
		index = ln;
		orig = -1;
		l[ln] = a[src];
		ln++;
	}
	ans[src] = ln;


	for (auto dest: uv[src]) {
		if (dest == fr)
			continue;
		solve(dest, src, l, ln);
	}

	if (index >= 0) {
		l[index] = orig;
		if (orig < 0)ln--;
	}
}

int main() {
	cin >> n;
	REP(i, n)cin >> a[i + 1];
	int u, v;
	REP(i, n - 1) {
		cin >> u >> v;
		uv[v].push_back(u);
		uv[u].push_back(v);
	}
	int l[200001] = {a[1], -1};
	solve(1, 0, l, 1);
	for (int i = 1; i <= n; i++)cout << ans[i] << endl;
	return 0;
}

Measured memory_bytes: 31248
#include <bits/stdc++.h>
#define IO_OP std::ios::sync_with_stdio(0); std::cin.tie(0);
#define F first
#define S second
#define V vector
#define PB push_back
#define MP make_pair
#define EB emplace_back
#define ALL(v) (v).begin(), (v).end()
#define debug(x) cerr << #x << " is " << x << endl

using namespace std;

typedef long long ll;
typedef pair<int, int> pi;
typedef V<int> vi;

const int INF = 1e9 + 7;

signed main()
{
	IO_OP;
	
	int n;
	cin >> n;
	vi a(n), b(n);
	for(int i = 0; i < n; i++) cin >> a[i] >> b[i];
	sort(ALL(a)), sort(ALL(b));
	if(n & 1) {
		cout << b[n / 2] - a[n / 2] + 1 << endl;
	} else {
		cout << b[n / 2] + b[n / 2 - 1] - a[n / 2] - a[n / 2 - 1] + 1 << endl;
	}

}





Measured memory_bytes: 4784
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<string.h>
#include<cmath>
using namespace std;
long long a[100010],s;
int main()
{
    int j,n,t1=0,t2=0;cin>>n;
    for(int i=1;i<=n;i++){cin>>a[i];}s=a[1];
    for(int i=2;i<=n;i++)
    {
        s=__gcd(s,a[i]);
        if(s==1)break;
    }
    cout<<s<<endl;
    return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define MIN INT_MIN
#define MAX INT_MAX
#define PB push_back
#define MP make_pair
#define F first
#define S second
#define E "\n"
#define rep(i,j,k,inc) for(int i=j;i<k;i+=inc)
typedef long long ll;
typedef unsigned long long ull;
typedef double db;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int,int>pii;
typedef pair<ll,ll> pll;
const ll mod=2019;
 
using namespace std;
void solve();
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    solve();
    return 0; 
}
 
void solve(){
	string s;
	cin>>s;
	int n=s.size();
	int suf=0;
	int pot=1;
	vector<int>cntsuf(mod);
	cntsuf[suf]++;
	ll ans=0;
	for(int i=n-1;i>=0;--i){
		int dig=s[i]-'0';
		suf=(suf+dig*pot)%mod;
		pot=(pot*10)%mod;
		ans+=cntsuf[suf];
		cntsuf[suf]++;
	}
	cout<<ans<<E;
}

Measured memory_bytes: 3744
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
typedef pair<int ,P> P3;
typedef pair<P ,P> PP;
const ll MOD = ll(1e9+7);
const int IINF = INT_MAX;
const ll LLINF = LLONG_MAX;
const int MAX_N = int(1e5 + 5);
const double EPS = 1e-6;
const int di[] = {0, 1, 0, -1}, dj[] = {1, 0, -1, 0};
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define SORT(v) sort((v).begin(), (v).end())
#define ALL(v) (v).begin(), (v).end()

int main() {
    int h, w, ans[105][105];
    string s[105];
    vector<P> pos;
    cin >> h >> w;
    REP(i,h) cin >> s[i];
    REP(i,h)REP(j,w){
        if(s[i][j]=='c')pos.push_back({i,j});
    }
    REP(i,h) fill(ans[i], ans[i]+w, -1);
    for(int t=0; t<w; t++){
        for(auto &p : pos){
            int i=p.first, j=p.second;
            if(j<w && ans[i][j]==-1){
                ans[i][j] = t;
                p.second++;
            }
        }
    }
    REP(i,h){
        REP(j,w) cout << ans[i][j] << " \n"[j==w-1];
    }
    return 0;
}



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

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

    int count = 0;
    rep(i, n - 2)
    {
        if (s.substr(i, 3) == "ABC")
        {
            count += 1;
        }
    }
    cout << count << endl;
}


Measured memory_bytes: 256
#include<stdio.h>
	int main(){
		int K,X,yen;
		scanf ("%d",&K);
		getchar();
		scanf ("%d",&X);
		getchar();
		yen=500;
		if (K*yen>=X){
			printf ("Yes\n");
		}else {
			printf ("No\n");
		}
		return 0;
	}


Measured memory_bytes: 1620