akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for(int i=0;i<(int)(n);++i)
#define REPR(i,n) for (int i=(int)(n)-1;i>=0;--i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
#define valid(y,x,h,w) (0<=y&&y<h&&0<=x&&x<w)
#define tpl(...) make_tuple(__VA_ARGS__)
const int INF = 0x3f3f3f3f;
const double EPS = 1e-8;
const double PI = acos(-1);
const int dy[] = {-1,0,1,0};
const int dx[] = {0,1,0,-1};
typedef long long ll;
typedef pair<int,int> pii;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
template<typename Ch,typename Tr,typename C,typename=decltype(begin(C()))>basic_ostream<Ch,Tr>& operator<<(basic_ostream<Ch,Tr>&os,
const C& c){os<<'[';for(auto i=begin(c);i!=end(c);++i)os<<(i==begin(c)?"":" ")<<*i;return os<<']';}
template<class S,class T>ostream&operator<<(ostream &o,const pair<S,T>&t){return o<<'('<<t.first<<','<<t.second<<')';}
template<int N,class Tp>void output(ostream&,const Tp&){}
template<int N,class Tp,class,class ...Ts>void output(ostream &o,const Tp&t){if(N)o<<',';o<<get<N>(t);output<N+1,Tp,Ts...>(o,t);}
template<class ...Ts>ostream&operator<<(ostream&o,const tuple<Ts...>&t){o<<'(';output<0,tuple<Ts...>,Ts...>(o,t);return o<<')';}
template<class T>void output(T t,char z=10){if(t<0)t=-t,putchar(45);int c[20];
int k=0;while(t)c[k++]=t%10,t/=10;for(k||(c[k++]=0);k;)putchar(c[--k]^48);putchar(z);}
template<class T>void outputs(T t){output(t);}
template<class S,class ...T>void outputs(S a,T...t){output(a,32);outputs(t...);}
template<class T>void output(T *a,int n){REP(i,n)cout<<a[i]<<(i!=n-1?',':'\n');}
template<class T>void output(T *a,int n,int m){REP(i,n)output(a[i],m);}
template<class T>bool input(T &t){int n=1,c;for(t=0;!isdigit(c=getchar())&&~c&&c-45;);
if(!~c)return 0;for(c-45&&(n=0,t=c^48);isdigit(c=getchar());)t=10*t+c-48;t=n?-t:t;return 1;}
template<class S,class ...T>bool input(S&a,T&...t){input(a);return input(t...);}
template<class T>bool inputs(T *a, int n) { REP(i,n) if(!input(a[i])) return 0; return 1;}

int main() {
  int n, m;
  while(input(n,m), n || m) {
    set<ll> S;
    ll sum = 0;
    ll ans = 0;
    REP(i,n) {
      int a; input(a);
      sum = (sum + a) % m;
      if (S.size()) {
        chmax(ans, (sum - *S.begin() + m) % m);
        auto it = S.upper_bound(sum);
        if (it != S.end()) {
          chmax(ans, (sum - *it + m) % m);
        }
      }
      chmax(ans, sum);
      S.insert(sum);
    }
    cout << ans << endl;
  }
}

Measured memory_bytes: 2368
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;

#define rep(i, n) for (int i = 0; i < n; ++i)
#pragma region Debug
template <typename T>
void view(const std::vector<T> &v)
{
    for (const auto &e : v)
    {
        std::cout << e << " ";
    }
    std::cout << std::endl;
}
template <typename T>
void view(const std::vector<std::vector<T>> &vv)
{
    for (const auto &v : vv)
    {
        view(v);
    }
}
#pragma endregion

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

    int ans = -1;
    rep(i, 1005)
    {
        int acand = floor((float)i * 0.08);
        int bcand = floor((float)i * 0.1);

        if (a == acand && b == bcand)
        {
            ans = i;
            break;
        }
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
from sys import stdin
import numpy as np
def main():
    #入力
    readline=stdin.readline
    n,m,k=map(int,readline().split())
    a=list(map(int,readline().split()))
    b=list(map(int,readline().split()))

    a=np.array(a,dtype=np.int64).cumsum()
    b=np.array(b,dtype=np.int64).cumsum()

    a=a[a<=k]
    a=k-a

    if a.size>=1:
        res=np.searchsorted(b,a,side="right")
        tmp=np.arange(1,a.size+1,dtype=np.int64)

        print(max((res+tmp).max(),b[b<=k].size))

    else:
        print(b[b<=k].size)

if __name__=="__main__":
    main()

Measured memory_bytes: 59544
import scala.io.StdIn.readDouble

object Main extends App {
  var x = 0D;var h = 0D
  while( {x=readDouble;x} != 0D && {h=readDouble;h} != 0D ) {
    val hh = Math.sqrt(h*h+x*x/4)
    println(x*x+2*x*hh)
  }
}

Measured memory_bytes: 43576
#include <iostream>
#include <vector>
#include <algorithm>
//#include <pair>

using namespace std;

using lint = long long;

int main(void)
{
	int N, K;
	cin >> N >> K;
	int maxK = (N-1) *(N - 2) / 2;
	if (K > maxK){
		cout << -1 << endl;
		return 0;
	}
	cout << N - 1 + maxK - K << endl;
	for (int i = 1; i < N; i++){
		cout << i << " " << N << endl;
	}
	
	for (int i = 1; i < N; i++){
		for (int j = i + 1; j < N; j++){
			if (maxK == K)
				break;
			cout << i << " " << j << endl;
			maxK--;
		}
	}
	return 0;
}

Measured memory_bytes: 256
class PriorityQueue
	def initialize
		@node = []
		@n = 0
	end

	private

	def left_key key
		2*key+1
	end

	def right_key key
		2*key+2
	end

	def from_root_swap key, 
		right = right_key(key)
		left = left_key(key)
		if  key < 0 
			return nil
		end
		if !@node[left] && !@node[right]
			return nil
		elsif @node[left] && !@node[right]
			if @node[left].cost < @node[key].cost
				@node[key], @node[left] =  @node[left], @node[key]
				from_root_swap(left)
			end
		elsif @node[right] && !@node[left]
			if @node[right].cost < @node[key].cost
				@node[key], @node[right] =  @node[right], @node[key]
				from_root_swap(right)
			end
		elsif @node[key].cost >= @node[left].cost && @node[left].cost <= @node[right].cost
			@node[key], @node[left] =  @node[left], @node[key]
			from_root_swap(left)
		elsif @node[key].cost >= @node[right].cost && @node[right].cost <= @node[left].cost
			@node[key], @node[right] =  @node[right], @node[key]
			from_root_swap(right)
		end
	end

	def from_leaf_swap key
		if key == 0
			return nil
		end
		parent_key = (key-1)/2
		if @node[parent_key].cost > @node[key].cost
			@node[key], @node[parent_key] = @node[parent_key], @node[key]
			from_leaf_swap(parent_key)
		end
	end

	def extract!
		node = @node[0]
		if @node.size == 0
			railse "Queue is Empty"
		elsif @node.size == 1
			@n -= 1
			return @node.pop
		else
		@n -= 1
		node = @node[0]
		@node[0] = @node.pop
		from_root_swap(0)
		return node
		end
	end

	def insert! node
		@node << node
		@n += 1
		from_leaf_swap(@n - 1)
	end



	public

	def << node
		insert!(node)
	end

	def pop
		extract!
	end

	def empty?
		@node.empty?
	end

end



n = gets.to_i
m = Array.new(n){Array.new(n){-1}}
n.times do |i|
	s = gets.split.map(&:to_i)
	s[1].times do |j|
		m[s[0]][s[ 2 * j + 2]] = s[2 * j + 3]
	end
end

Vector = Struct.new(:sta, :end, :cost)
pq = PriorityQueue.new
BLACK = 0
WHITE = 1
color = Array.new(n){WHITE}
cost = Array.new(n){Float::INFINITY}
cost[0] = 0
color[0] = BLACK
u = 0
loop{

	n.times do |i|
		pq << Vector.new(u, i, cost[u] + m[u][i] ) if color[i] == WHITE && m[u][i] != -1
	end


	break if pq.empty?
	vector = pq.pop
	next if vector.cost == Float::INFINITY

	color[vector.end] = BLACK
	 cost[vector.end] = vector.cost if cost[vector.end] > vector.cost
	 u = vector.end
}

n.times do |i|
	puts "#{i} #{cost[i]}"
end

Measured memory_bytes: 9000
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import accumulate, permutations, combinations, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(str, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7
import numpy as np

a = input()
print(eval(a))


Measured memory_bytes: 13596
#include "bits/stdc++.h"
using namespace std;
using ll = long long;

int main() {
	int n;
	cin >> n;
	vector<ll> a(n);
	ll ans = 0;
	ll maxtall = a[0];
	for (int i = 0; i < n; i++) {
		cin >> a[i];
		if (i == 0) {
			maxtall = a[i];
		}
		if (i > 0) {
			if (a[i] < maxtall) {
				ans += maxtall - a[i];
			}
			else {
				maxtall = a[i];
			}
		}
	}
	cout << ans << endl;
}

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

#define pb push_back
#define pob pop_back
#define pf push_front
#define pof pop_front
#define eb emplace_back
#define rep(i, a, b) for (long i = (a); i <= (b); ++i)
#define per(i, a, b) for (long i = (a); i >= (b); --i)
#define mmst(v) memset(v, 0, sizeof(v))

template<typename T1,typename T2> inline void chmin(T1 & a, T2 b) { if (a > b) a = b; }
template<typename T1,typename T2> inline void chmax(T1 & a, T2 b) { if (a < b) a = b; }

const long kMax2 = 109;
const long kMax3 = 1009;
const long kMax4 = 10009;
const long kMax5 = 100009;
const long kMax6 = 1000009;
const long kInfI = 0x3F3F3F3F;
const float kInfF = 1e15;
const long long kMod = 1000000007;

const long kMAX = 1000000000;

using namespace std;
using ll = long long;

inline int readInt() {
  char c = getchar();
  while(!isdigit(c) && c != '-') c = getchar();
  int sigma = 1;
  if (c == '-') {
    sigma = -1;
    c = getchar();
  }
  int x = 0;
  while (isdigit(c)) {
    x = x * 10 + c - '0';
    c = getchar();
  }
  return x * sigma;
}

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

  ll ans = 0, count = -1;

  int n;
  vector<ll> a;

  cin >> n;
  int tmp = kMod;
  rep(i, 0, n - 1) {
    int x;
    cin >> x;
    if (x <= tmp) {
      ++count;
      tmp = x;
    } else {
      ans = max(ans, count);
      count = 0;
      tmp = x;
    }
  }
  ans = max(ans, count);
  cout << max(ans, 0ll) << endl;
}


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

int main()
{
    vector<vector<int>> bingo(3, vector<int>(3));

    for (int i = 0; i < 3; i++)
    {
        for (int j = 0; j < 3; j++)
        {
            cin >> bingo[i][j];
        }
    }

    // for (int i = 0; i < 3; i++)
    // {
    //     for (int j = 0; j < 3; j++)
    //     {
    //         cout << "before" << bingo[i][j] << endl;
    //     }
    // }

    int N;
    cin >> N;
    for (int k = 0; k < N; k++)
    {
        int n;
        cin >> n;
        for (int i = 0; i < 3; i++)
        {
            for (int j = 0; j < 3; j++)
            {
                if (n == bingo[i][j])
                {
                    bingo[i][j] = -1;
                }
            }
        }
    }

    // for (int i = 0; i < 3; i++)
    // {
    //     for (int j = 0; j < 3; j++)
    //     {
    //         cout << "after" << bingo[i][j] << endl;
    //     }
    // }

    bool ans = false;
    ans |= bingo[0][0] + bingo[0][1] + bingo[0][2] == -3;
    ans |= bingo[1][0] + bingo[1][1] + bingo[1][2] == -3;
    ans |= bingo[2][0] + bingo[2][1] + bingo[2][2] == -3;

    ans |= bingo[0][0] + bingo[1][0] + bingo[2][0] == -3;
    ans |= bingo[0][1] + bingo[1][1] + bingo[2][1] == -3;
    ans |= bingo[0][2] + bingo[1][2] + bingo[2][2] == -3;

    ans |= bingo[0][0] + bingo[1][1] + bingo[2][2] == -3;
    ans |= bingo[0][2] + bingo[1][1] + bingo[2][0] == -3;

    if (ans)
    {
        cout << "Yes" << endl;
    }
    else
    {
        cout << "No" << endl;
    }
}

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

int main(void){
	double l;
	double a;
	double ans;

	scanf("%lf",&l);
	a=l/3;
	ans = a*a*a;
	printf("%lf",ans);
	return 0;
}


Measured memory_bytes: 128
fun main(args: Array<String>) {
    a69(readLineList())
}

fun readLineList(): Array<String> {
    val lineList = mutableListOf<String>()
    while (true) {
        val line = readLine()
        if (line.isNullOrBlank()) {
            break
        } else {
            lineList.add(line!!)
        }
    }
    return lineList.toTypedArray()
}

fun a69(args: Array<String>) {
    if (args.size != 1) {
        throw IllegalArgumentException()
    }
    val (x, y) = args[0].split(" ").map { it.toInt() }
    println((x - 1) * (y - 1))
}


Measured memory_bytes: 36384
#include <iostream>
//#include <iomanip>
//#include <string>
#include <vector>
//#include <algorithm>
//#include <utility>
//#include <set>
//#include <map>
//#include <queue>
//#include <deque>
//#include <bitset>
//#include <math.h>
using namespace std ;
using ll = long long ;
//using ld = long double ;
using vll = vector<ll> ;
using vvll = vector<vll> ;
//using vc = vector<char> ;
//using vvc = vector<vc> ;
using vb = vector<bool> ;
//using vvb = vector<vb> ;
//using pll = pair<ll,ll> ;
//#define all(v) v.begin(),v.end()
//ll mod = 1000000007 ;
//long double pie = acos(-1) ;
//ll INF = 1000000000000 ;

//void yorn(bool a){if(a) cout << "Yes" << endl ; else cout << "No" << endl ;}
//void YorN(bool a){if(a) cout << "YES" << endl ; else cout << "NO" << endl ;}
//ll gcd(long long a,long long b){if(b==0) return a ; return gcd(b,a%b) ;}
//ll lcm(long long a,long long b){return a/gcd(a,b)*b ;}
//ll sa(long long a,long long b){if(a>b) return a-b ; return b-a ;}
//void fix_cout(){cout << fixed << setprecision(20) ;}

void DFS(vvll &g,vb &ok,int p){
	if(ok.at(p)) return ;
	ok.at(p) = true ;
	for(int i=0;i<g.at(p).size();i++) DFS(g,ok,g.at(p).at(i)) ;
}

int main(){
	ll n,m ;
	cin >> n >> m ;
	vvll g(n,vll(0)) ;
	for(int i=0;i<m;i++){
		ll a,b,c ;
		cin >> a >> b >> c ;
		a-- ; b-- ;
		g.at(a).emplace_back(b) ;
		g.at(b).emplace_back(a) ;
	}
	vb ok(n,false) ;
	ll ans = 0 ;
	for(int i=0;i<n;i++){
		if(!ok.at(i)){
			ans++ ;
			DFS(g,ok,i) ;
		}
	}
	cout << ans << endl ;
}


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

int main(){
    string s,t;
    int i=0, n=0;
    cin >> s >> t;
    n = s.length() - t.length();
    while(n >= 0){
        for(i=0; i<t.length(); i++){
            if(s[i+n] != '?' && s[i+n] != t[i]){
                break;
            }
            if(i == t.length()-1){
                for(i=0; i<t.length(); i++){
                    s[i+n] = t[i];
                }
                for(i=0; i<s.length(); i++){
                    if(s[i] == '?'){
                        s[i] = 'a';
                    }
                }
                cout << s;
                return 0;
            }
        }
        n--;
    }
    cout << "UNRESTORABLE";
    return 0;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {

    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);
        int A = sc.nextInt();
        long B = sc.nextLong();
        long N = sc.nextLong();

        long x = Math.min(B-1,N);
        long ans = A*x/B - A*(x/B);
        System.out.println(ans);
    }
}


Measured memory_bytes: 35932
#include <stdio.h>
int p[14][14];
int main()
{
  int x,y,s,i,j,w=0,m=0;
  while((scanf("%d,%d,%d",&x,&y,&s)) != EOF){
    x += 2; y+=2;
    switch(s){
    case 3:
      p[x][y-2]++; p[x][y+2]++; p[x-2][y]++; p[x+2][y]++;
    case 2:
      p[x-1][y-1]++; p[x-1][y+1]++; p[x+1][y-1]++; p[x+1][y+1]++;
    case 1:
      p[x][y]++; p[x-1][y]++; p[x+1][y]++; p[x][y-1]++; p[x][y+1]++;
    }
  }
  for(i=2;i<12;i++){
    for(j=2;j<12;j++){
      if(p[i][j] == 0) w++;
      if(m<p[i][j]) m = p[i][j];
    }
  }
  printf("%d\n%d\n",w,m);
  return 0;
}

Measured memory_bytes: 0
#include <iostream>
#include <string>
using namespace std;
int main() {
	string s;
	int sum;
	while (1) {
		sum = 0;
		cin >> s;
		for (int i = 0; i < s.length();i++) {
			sum += s[i] - '0';
		}
		if (!sum) break;
		cout << sum << endl;
	}
}

Measured memory_bytes: 3144
#![allow(dead_code)]
#![allow(unused_variables)]
#![allow(unused_variables)]

use std::io::stdin;
use std::str::FromStr;

fn read<T: FromStr>() -> T {
    let mut str = String::new();
    stdin().read_line(&mut str).ok();
    str.trim().parse().ok().unwrap()
}

fn read_vec<T: FromStr>() -> Vec<T> {
    let mut str = String::new();
    stdin().read_line(&mut str).ok();
    str.trim().split_whitespace().map(|e| e.parse().ok().unwrap()).collect()
}

fn read_n_vec<T: FromStr>(n: u32) -> Vec<Vec<T>> {
    let mut v_outer = Vec::new();
    for _ in 0..n {
        let v_inner = read_vec();
        v_outer.push(v_inner);
    }
    v_outer
}

fn main() {
    let x : u64 = read();
    let n_500 = x / 500;
    let n_5 = (x - 500*n_500) / 5;

    println!("{}", n_500*1000 + n_5*5);
}

Measured memory_bytes: 4352
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+1];
    
    for(int i = 1; i <= N; i++){
      a[i] = sc.nextInt();
    }
    
    int cnt = 1;
    int point_now = 1;
    
    while(cnt <= N){
      point_now = a[point_now];
      if(point_now == 2){
        System.out.print(cnt);
        return;
      }
      cnt++;
    }
    System.out.println(-1);
  }
}
    

Measured memory_bytes: 58896
#include <algorithm>
#include <cassert>
#include <cmath>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <limits>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <vector>
#define repeat(i, n) for (int i = 0; (i) < (n); ++(i))
#define repeat_from(i, m, n) for (int i = (m); (i) < (n); ++(i))
using namespace std;
template <class T>
void setmax(T &a, T const &b) {
    if (a < b) a = b;
}

template <class T>
void setmin(T &a, T const &b) {
    if (a > b) a = b;
}

template <typename T, typename X>
auto vectors(T a, X x) { return vector<T>(x, a); }

template <typename T, typename X, typename Y, typename... Zs>
auto vectors(T a, X x, Y y, Zs... zs) {
    auto cont = vectors(a, y, zs...);
    return vector<decltype(cont)>(x, cont);
}

// ei1333
struct UnionFind {
    vector<int> data;

    UnionFind(int sz) {
        data.assign(sz, -1);
    }

    bool unite(int x, int y) {
        x = find(x), y = find(y);
        if (x == y) return (false);
        if (data[x] > data[y]) swap(x, y);
        data[x] += data[y];
        data[y] = x;
        return (true);
    }

    int find(int k) {
        if (data[k] < 0) return (k);
        return (data[k] = find(data[k]));
    }

    int size(int k) {
        return (-data[find(k)]);
    }
};

// たぶん、(x, y)をマージしていって、グループに分けて、
// そのグループについては、1つAiの数字が決まったらすべてのAiが一意に決まると考えた

int main() {
    int N, M;
    cin >> N >> M;
    UnionFind uf(N);
    repeat(i, M) {
        int x, y, z;
        cin >> x >> y >> z;
        uf.unite(x - 1, y - 1);
    }

    vector<bool> used(N, false);
    int res = 0;
    repeat(i, N) {
        int par = uf.find(i);
        if (used[par]) {
            continue;
        } else {
            used[par] = true;
            ++res;
        }
    }
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 3748
#include<bits/stdc++.h>
using namespace std;
#define R(i,n) for(int i=0;i<n;i++)
main(){int n,a=1e9,c[2][20];cin>>n;R(i,n)cin>>c[0][i];R(i,n)cin>>c[1][i];vector<vector<int>>p(1<<n,vector<int>(51,1e9));p[0][0]=0;R(B,1<<n){int o=0,d[n];R(i,n)if(!(B&1<<i))d[i]=o++;R(i,n){int k=c[abs(i-n+o)%2][i];R(j,k+1)p[B|1<<i][k]=min(p[B|1<<i][k],p[B][j]+d[i]);}}R(i,51)a=min(a,p[(1<<n)-1][i]);cout<<(a>1e8?-1:a);}

Measured memory_bytes: 65792
/*BY-ADITYA OJHA
  LEARN DSA SINCERELY*/
#include <bits/stdc++.h>
#define ll long long int
#define forin for(int i=0;i<n;i++)
#define forjn for(int j=0;j<n;j++)
#define pb push_back
#define vx vector<ll> x
#define fas1  ios_base::sync_with_stdio(false)
#define fas2   cin.tie(NULL)
using namespace std;

int main()
{
  ll n;
  cin>>n;
  set<int>x;
  forin
  {
     ll p;
    cin>>p;
    x.insert(p);
  }
  if(x.size()==n)
    cout<<"YES"<<endl;
  else
    cout<<"NO"<<endl;
}

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

const int M = 1e5;

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

	//一致してるものをフラグ立て
	for (int i = 0;i<N;i++) {
		if (p[i] == i+1) {
			p[i] = 1;
		}
		else {
			p[i] = 0;
		}
	}

	//1の個数をカウントしながら次のを0に
	int ans=0;
	for (int i = 0;i<N;i++) {
		if (p[i] == 1) {
			ans=ans+1;
			p[i + 1] = 0;
		}
	}
	cout << ans;
}

Measured memory_bytes: 640
#include <iostream>
#include <cmath>
#include <vector>
#include <string>
#include <map>
#include <algorithm>
#include <limits>
using namespace std;

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

typedef long long ll;

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

    vector<int> h(N);
    vector<int> dp(N,0);
    rep(i,N) cin >> h[i];
    rep(i,N) {

        if (i==0) {dp[i] = 0; continue;}
        if (i >= 2) {
            dp[i] = min(dp[i-1]+abs(h[i]-h[i-1]), dp[i-2]+abs(h[i]-h[i-2]));
        } else {
            dp[i] = dp[i-1]+abs(h[i]-h[i-1]);
        }

        //rep(j,N) cout << dp[j] << ",";
        //cout << endl;
    }

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


Measured memory_bytes: 1024
#include <iostream>

using namespace std;

int main(){
	int m, f, b;

	cin >> m >> f >> b;

	if (m >= b){
		cout << "0" << endl;
	}else if ((b - m) <= f){
		cout << b - m << endl;
	}else {
		cout << "NA" << endl;
	}

}

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

using ll = long long;
#define ALL(c) (c).begin(), (c).end()
const int MOD = 1000000007;

int main() {
    ll a, b, x;
    cin >> a >> b >> x;
    ll aa = a % x;
    ll bb = b % x;
    cout << (b / x - a / x + (aa == 0 ? 1 : 0)) << endl;

}


Measured memory_bytes: 256
# -*- coding: utf-8 -*-
K, X = map(int,input().split())

L = []
L.append(X)
for n in range(K):
  if n < K-1:
    L.append(X-n-1)
    L.append(X+n+1)
sorted_L = sorted(L)
s = ' '.join([str(n) for n in sorted_L])

print(s)

Measured memory_bytes: 3060
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<unordered_map>
#include<set>
#include<unordered_set>
#include<numeric>
#include<algorithm>
#include<tuple>
#include<cmath>
#include <iomanip>

typedef unsigned long long ull;
typedef long long ll;

ll DENOM = 1000000000LL + 7LL;
ll D2 = 998244353LL;
using namespace std;

ll n, m, k;
ll pow5(ll x){
    ll ret = x*x*x*x*x;
    return ret;
}
ll pow4(ll x){
    ll ret = x*x*x*x;
    return ret;
}

int main(){
    cin >> n;
    ll a,b;
    ll mx = ceil(sqrt(sqrt(n)));
    for(ll i=1;i < mx+1; ++i){
        for(ll j=0; j<mx+1; ++j){
            if(pow5(i) - pow5(j) == n){
                a = i;
                b = j;
                break;
            }else if(pow5(i) + pow5(j) == n){
                a = i;
                b = -j;
                break;
            }
        }
    }
    cout << a << " " << b << endl;

    return 0;
}

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

typedef long long ll;
typedef unsigned long long ull;
#define FOR(i,a,b) for(int i=(a);i<(int)(b);i++)
#define rep(i,n) FOR(i,0,n)
#define ALL(x) (x).begin(),(x).end()
#define RALL(x) (x).rbegin(),(x).rend()
#define SZ(x) (int)(x).size()
#define mset(a,x) memset(a,x,sizeof(a))
#define dbg(x) cout<<#x<<": "<<(x)<<"\n"
#define pb push_back
#define mp make_pair

int main() {
    string a,b,c;
    cin>>a>>b>>c;
    cout<<a[0]<<b[0]<<c[0];


    return 0;
}


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

typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;
const ull mod = 1e9 + 7;
#define REP(i,n) for(int i=0;i<(int)n;++i)

//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

template < typename T >
void vprint(T &v){
	REP(i, v.size()){
		cout << v[i] << " ";
	}
	cout << endl;
}

int main(){
	ll N;
	cin >> N;
	vector<ll> A(N);
	REP(i, N) cin >> A[i];

	bool flag = true;
	if(A[0]>0) flag = false;
	REP(i, N-1) if(A[i+1]>A[i]+1) flag = false;
	if(!flag){
		cout << -1 << endl;
		return 0;
	} 

	ll res = 0;
	REP(i, N-1){
		if(A[i+1]==A[i]+1) res += 1;
		else res += A[i+1];
	}
	cout << res << endl;
    return 0;
}

Measured memory_bytes: 1792
#include <vector>
#include <queue>
#include <stack>
#include <algorithm>
#include <iostream>
#include <string>
#include <tuple>
#include <set>
#include <map>
#include <unordered_map>
#include <complex>
#include <iomanip>
#include <cmath>
#include <tuple>
using namespace std;
typedef long long ll;

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

    cout << 3 * r * r << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <cstring>
#include <math.h>
#include <bitset>
#include <queue>
#include <set>
#include <iomanip>
#include <math.h>
#include <assert.h>
// #include<bits/stdc++.h>
using namespace std;
typedef long long ll;
constexpr long long int INFLL = 1001001001001001LL;
constexpr long long int infll = 1001001001001001LL;
constexpr int INF = 1000000007;
constexpr int inf = 1000000007;
const int mod = 1000000007;

template <class T>
inline bool chmin(T &a, T b)
{
    if (a > b)
    {
        a = b;
        return true;
    }
    return false;
}
template <class T>
inline bool chmax(T &a, T b)
{
    if (a < b)
    {
        a = b;
        return true;
    }
    return false;
}

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

ll lcm(ll a, ll b)
{
    return a / gcd(a, b) * b;
}

inline double nCr(const int n, int r)
{
    if (n == 0)
    {
        return 0;
    }
    if (r == 0)
    {
        return 1;
    }
    if (r == 1)
    {
        return n;
    }
    if (n == r)
    {
        return 1;
    }

    if (r > n / 2)
    {
        r = n / 2;
    }

    double result = 1;
    for (double i = 1; i <= r; i++)
    {
        result *= (n - i + 1) / i;
    }

    return (result);
}

template <typename T>
T seinomi(T a)
{
    if (a > 0)
    {
        return a;
    }
    else
    {
        return 0;
    }
}

template <typename T>
map<T, T> soinsuubunkai(T n) //連想配列[素因数f.first][個数f.second]
{
    map<T, T> ret;
    for (T i = 2; i * i <= n; i++)
    {
        while (n % i == 0)
        {
            ret[i]++;
            n /= i;
        }
    }
    if (n != 1)
        ret[n] = 1;
    return ret;
}

template <typename T>
T ketasuu(T num)
{
    return std::to_string(num).length();
}

int kaizyou(int k)
{
    int sum = 1;
    for (int i = 1; i <= k; ++i)
    {
        sum *= i;
    }
    return sum;
}

template <class ForwardIt, class T>
void iota(ForwardIt first, ForwardIt last, T value)
{
    while (first != last)
    {
        *first++ = value;
        ++value;
    }
}

//nの階乗を計算
int factorial(int n)
{
    int answer = 1;
    while (n > 1)
    {
        answer *= n;
        n--;
    }
    return answer;
}
int comb(int n, int r)
{
    return factorial(n) / (factorial(r) * factorial(n - r));
}

long long modpow(long long a, long long n, long long mod)
{
    long long res = 1;
    while (n > 0)
    {
        if (n & 1)
            res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}


template <typename T>
T amarinasi(T a,T b){
    if(a%b==0)
{
    return a/b;
}
else if(a%b>0)
{
    return a/b+1;
}
else
{
    return a/b-1;
}
}


//小数点以下10桁テンプレート（main関数内の最初に貼付け）
//std::cout << std::fixed << std::setprecision(10);

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


int main() {
ll n;
cin>>n;
ll ruiseki[n+1];
ruiseki[0]=0;
ll a;
for(ll i=0;i<n;i++){
    cin>>a;
    ruiseki[i+1]=ruiseki[i]+a;
}
ll ans=infll;
for(ll i=1;i<n;i++){
    chmin(ans,llabs(ruiseki[i]-(ruiseki[n]-ruiseki[i])));
}
cout<<ans<<endl;
}








Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
/*#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
template<typename T> using gpp_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
template<typename T, typename L> using gpp_map = tree<T, L, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
template<typename T> using gpp_multiset = tree<T, null_type, less_equal<T>, rb_tree_tag, tree_order_statistics_node_update>;*/
struct fast_ios { fast_ios(){ cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(20); }; } fast_ios_;
#define FOR(i, begin, end) for(int i=(begin);i<(end);i++)
#define REP(i, n) FOR(i,0,n)
#define IFOR(i, begin, end) for(int i=(end)-1;i>=(begin);i--)
#define IREP(i, n) IFOR(i,0,n)
#define Sort(v) sort(v.begin(), v.end())
#define Reverse(v) reverse(v.begin(), v.end())
#define all(v) v.begin(),v.end()
#define SZ(v) ((int)v.size())
#define Lower_bound(v, x) distance(v.begin(), lower_bound(v.begin(), v.end(), x))
#define Upper_bound(v, x) distance(v.begin(), upper_bound(v.begin(), v.end(), x))
#define Max(a, b) a = max(a, b)
#define Min(a, b) a = min(a, b)
#define bit(n) (1LL<<(n))
#define bit_exist(x, n) ((x >> n) & 1)
#define debug(x) cout << #x << "=" << x << endl;
#define vdebug(v) { cout << #v << "=" << endl; REP(i_debug, v.size()){ cout << v[i_debug] << ","; } cout << endl; }
#define mdebug(m) { cout << #m << "=" << endl; REP(i_debug, m.size()){ REP(j_debug, m[i_debug].size()){ cout << m[i_debug][j_debug] << ","; } cout << endl;} }
#define Return(ans) { cout << (ans) << endl; return 0; }
#define pb push_back
#define f first
#define s second
#define int long long
#define INF 1000000000000000000
template<typename T> istream &operator>>(istream &is, vector<T> &v){ for (auto &x : v) is >> x; return is; }
template<typename T> ostream &operator<<(ostream &os, vector<T> &v){ for(int i = 0; i < v.size(); i++) { cout << v[i]; if(i != v.size() - 1) cout << endl; }; return os; }
template<typename T1, typename T2> ostream &operator<<(ostream &os, pair<T1, T2> p){ cout << '(' << p.first << ',' << p.second << ')'; return os; }
template<typename T> void Out(T x) { cout << x << endl; }
template<typename T1, typename T2> void Ans(bool f, T1 y, T2 n) { if(f) Out(y); else Out(n); }
 
using vec = vector<int>;
using mat = vector<vec>;
using Pii = pair<int, int>;
using PiP = pair<int, Pii>;
using PPi = pair<Pii, int>;
using bools = vector<bool>;
using pairs = vector<Pii>;
 
//int dx[4] = {1,0,-1,0};
//int dy[4] = {0,1,0,-1};
//char d[4] = {'D','R','U','L'};
 
const int mod = 1000000007;
//const int mod = 998244353;
//#define Add(x, y) x = (x + (y)) % mod
//#define Mult(x, y) x = (x * (y)) % mod

#include <bits/stdc++.h>
using namespace std;
signed main(){
    int L,R; cin>>L>>R;
    int ans= INF;
    if(R-L+1>=2019) ans = 0;
    else{
        FOR(i,L,R){
            FOR(j,i+1,R+1){
                ans = min(ans,(i*j)%2019);
            }
        }
    }
    Out(ans);
}

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

using namespace std;

typedef long double ld;
const ld PI = acos(0)*ld(2.0);

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

    //freopen("a.in", "r", stdin);
    //freopen("a.out", "w", stdout);

    ld R;
    cin >> R;
    R = ld(2)*R*PI;
    cout << R << '\n';
    
    return 0;
}


Measured memory_bytes: 3800
s = input()
n = len(s)
s_x = ''.join(s.split('x'))
for i in range(len(s_x)//2):
    if s_x[i] != s_x[-1-i]:
        print(-1)
        exit(0)
ans = 0
i = 0
j = n-1
while i < j:
    if s[i] == 'x' and s[j] == 'x':
        i += 1
        j -= 1
    elif s[i] == 'x':
        ans += 1
        i += 1
    elif s[j] == 'x':
        ans += 1
        j -= 1
    else:
        i += 1
        j -= 1
print(ans)


Measured memory_bytes: 5236
n = int(input())
c = list(map(int, input().split()))
c.sort(reverse = True)
a = 0
for i in range(int((n+1)//2)):
  a += c[i]
if n%2==0:
  print(a*2-c[0])
else:
  print(a*2-c[0]-c[n//2])

Measured memory_bytes: 31584
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {

        Scanner sc = new Scanner(System.in);
        
        String C1 = sc.next();
        String C2 = sc.next();
        String C3 = sc.next();
        
        System.out.println(""+ C1.charAt(0) + C2.charAt(1) + C3.charAt(2));
    }
}
 

Measured memory_bytes: 23124
#include <iostream>
using namespace std;
static const int MAX=100;
static const int INFTY=(1<<21);
static const int WHITE=0;
static const int GRAY=1;
static const int BLACK=2;
int n,M[MAX][MAX];
int prim(){
  int u,minv;
  int d[MAX],p[MAX],color[MAX];
  for(int i=0;i<n;i++){
	d[i]=INFTY;
	p[i]=-1;
	color[i]=WHITE;
	  }
  d[0]=0;
  while(1){
	minv=INFTY;
	u=-1;
	for(int i=0;i<n;i++){
	  if(minv>d[i] && color[i]!=BLACK){
		u=i;
		minv=d[i];
	  }
	}
	if(u==-1) break;
	color[u]=BLACK;
	for(int v=0;v<n;v++){
	  if(color[v]!=BLACK && M[u][v]!=INFTY){
		if(d[v]>M[u][v]){
		  d[v]=M[u][v];
		  p[v]=u;
		  color[v]=GRAY;
		}
	  }
	}
  }
  int sum=0;
  for(int i=0;i<n;i++){
	if(p[i]!=-1) sum+=M[i][p[i]];
  }

  return sum;
}

int main(){
  cin>>n;
  for(int i=0;i<n;i++){
	for(int j=0;j<n;j++){
	  int e; cin >>e;
	  M[i][j]=(e==-1) ? INFTY:e;
	}
  }
  cout << prim() <<endl;
  return 0;
}
  
		  



Measured memory_bytes: 3108
#include<iostream>
#include<algorithm>
#include<string>
using namespace std;
int m, n, a[10], a_2[10], ID[100001];
int table[] = { 0, 2, 4, 6, 8, 1, 3, 5, 7, 9};

int main(){
  cin >> n;
  for(int i = n ; i ; i-- ){
    char c;
    cin >> c;
    if(c == '*') ID[i] = -1;
    else ID[i] = i % 2 ? c - '0' : table[c - '0'];
  }
  cin >> m;
  for(int i = 0 ; i < m ; i++ ){
    cin >> a[i];
    a_2[i] = table[a[i]];
  }

  int dp[2][10] = {{}};
  dp[0][0] = 1;
  for(int i = 1 ; i < n + 1 ; i++ ){ // 桁
    for(int j = 0 ; j < 10 ; j++ ){
      dp[i & 1][j] = 0;
    }
    if(~ID[i]) {
      for(int j = 0 ; j < 10 ; j++ ){
        dp[i & 1][( j + ID[i] ) % 10] += dp[(i - 1) & 1][j];
      }
    } else {
      for(int k = 0 ; k < m ; k++ ){
        int next = (i % 2 ? a[k] : a_2[k]);
        for(int j = 0 ; j < 10 ; j++ ){
          dp[i & 1][( j + next ) % 10] += dp[(i - 1) & 1][j];
        }
      }
    }
  }
  cout << dp[n & 1][0] << endl;
}

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

int main() {
  int a, b, c, d;
  cin>>a>>b>>c>>d;
  if (a != c) puts("1"); else puts("0");
  return 0;
}

Measured memory_bytes: 384
n = raw_input()
n = int(n)
minv = raw_input()
minv = int(minv)
maxv = -1000000000
  
for j in range(n-1):
  num = raw_input()
  num = int(num)  
  diff = num - minv
  if maxv < diff:
    maxv = diff
  if num < minv:
    minv = num
  
print maxv

Measured memory_bytes: 12632
gets # n
ns = gets.split.map(&:to_i)

counts = Hash.new(0)
# cumulative sums
ns.inject([0]) { |a, n| a << a.last + n }.each do |n|
  counts[n] += 1
end

# sum of nC2
p counts.values.map { |n| n * (n - 1) / 2 }.reduce(:+)


Measured memory_bytes: 33724
#%%
def ceil(x, y):
    if x%y == 0:
        return x//y
    else:
        return x//y + 1

a, b = map(int, input().split())
c = b
if b <= a:
    ans = 1
else:
    ans = 0
    b -= a
    ans += 1
    ans += ceil(b,a-1)

if c == 1:
    ans = 0

print(ans)


Measured memory_bytes: 2940
// In The Name Of Allah

#include<bits/stdc++.h>
using namespace std;

#define F first
#define S second
#define pp pop_back
#define pb push_back
#define mp make_pair
#define int long long
#define all(x) x.begin(), x.end()
#define debug(x) cerr << #x << " : " << x

typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
typedef pair<ll, ll> pll;
typedef vector<pll> vpll;

const int maxx = 1e6 + 19;
const int inf = 1e18 + 19;
const int mod = 1000000007LL;

int n, ans = 0;
vector<int> v;

int32_t main() {
    ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
    cin >> n;
	for (int i = 0; i < 2 * n; i++) {
		int x;
		cin >> x;
		v.pb(x);
	}
	sort(all(v));
	for (int i = 0; i < 2 * n; i += 2)
		ans += v[i];
	cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
n=int(input())
a=list(map(int,input().split()))
a.sort()
s=0
for i in range(n):
  if n%2==0:
    if i%2==0:
      s+=a[i]
  else:
    if i%2!=0:
      s+=a[i]

print(sum(a)-s*2)

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

using namespace std;

const int N = 505, mod = 1e9 + 7;

long long dp[2][N][105], sum[N][105], sumq[N][105];
int a[N];

void add(long long & var, long long val) {
  var = (var + val) % mod;
  if (var < 0)
    var += mod;
}

int main() {
  int n, x;
  scanf("%d %d", &n, &x);
  for (int i = 0; i < n; ++i) {
    scanf("%d", a+i);
  }
  sort(a, a+n);
  reverse(a, a+n);
  int c = 0, b = 1;
  dp[c][a[0]][1] = 1;
  int tot = a[0];
  for (int z = 1; z < n; ++z) {
    swap(b, c);
    int l = a[z];
    tot = min(tot + l, x);
    for (int i = 0; i <= tot; ++i)
      for (int j = 0; j <= z+1; ++j) {
        dp[c][i][j] = 0;
        sum[i+1][j] = (sum[i][j] + dp[b][i+1][j]) % mod;
        sumq[i+1][j] = (sumq[i][j] + 1LL * (i+1) * dp[b][i+1][j]) % mod;
      }
    for (int p = l; p <= tot; ++p) {
      for (int q = 1; q <= z+1; ++q) {
        long long & now = dp[c][p][q];
        add(now, dp[b][p-l][q-1] * q);
        long long cnt = p - (l - 1) * q;
        if (cnt > 0) {
          add(now, dp[b][p][q] * cnt);
        }
        add(now, 2LL * q * (sum[p-1][q] - sum[p-l][q]));
        long long A = (sumq[p][q+1] - sumq[p-l+1][q+1]), B = sum[p][q+1] - sum[p-l+1][q+1];
        long long cur = (A + B * (l-p-1)) % mod;
        add(now, cur * q);
      }
    }
  }
  long long ans = 0;
  for (int i = 1; i <= n; ++i)
    add(ans, dp[c][x][i]);
  printf("%lld\n", ans);
  return 0;
}


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


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

struct edge {int to; ll cost; };

int dx[] = {-1, 1, 0,  0};
int dy[] = { 0, 0, 1, -1};
 
int main(){
  int n, m;
  ll k;
  cin >> n >> m >> k;
  vector<ll> a(n+1, 0), b(m+1, 0);
  for(int i=1; i<=n; i++){
    cin >> a[i];
    a[i] += a[i-1];
  }
  for(int i=1; i<=m; i++){
    cin >> b[i];
    b[i] += b[i-1];
  }
  int ans = 0;
  for(int i=0; i<=n; i++){
    if(k<a[i]) break;
    int cnt = i;
    cnt += upper_bound(b.begin(), b.end(), k-a[i]) - b.begin() - 1;
    ans = max(ans, cnt);
  }
  cout << ans << endl;
  return 0;
}


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

using namespace std;

int main(){
  int N, M;
  cin >> N >> M;
  
  string S;
  cin >> S;
  
  vector<int> step;
  bool ok = true;
  int i = N;
  while(i > 0 && ok){
    ok = false;
    for(int j = M; j > 0; j--){
      if(i - j >= 0 && S[i - j] == '0'){
        ok = true;
        step.push_back(j);
        i -= j;
        break;
      }
    }
  }
  
  if(ok){
    reverse(step.begin(), step.end());
    for(int i = 0; i < step.size() - 1; i++){
      cout << step[i] << ' ';
    }
    cout << step[step.size() - 1] << endl;
  }else{
    cout << -1 << endl;
  }
  
  return 0;
}

Measured memory_bytes: 1144
r1,c1,r2,c2=map(int,input().split())

mod = 10**9+7
MAX_N = 3*10**6

fact = [1]
fact_inv = [0]*(MAX_N+4)
for i in range(MAX_N+3):
    fact.append(fact[-1]*(i+1)%mod)

fact_inv[-1] = pow(fact[-1],mod-2,mod)
for i in range(MAX_N+2,-1,-1):
    fact_inv[i] = fact_inv[i+1]*(i+1)%mod

def comb(n,k,mod=mod):
    if n<k:return 0
    return fact[n] * fact_inv[k] % mod * fact_inv[n-k] %mod

ans=comb(c1+r1,r1)-comb(c1+r2+1,r2+1)-comb(c2+r1+1,r1)+comb(c2+r2+2,r2+1)
ans%=mod

print(ans)


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

using namespace std;
typedef unsigned long long int ull;
typedef long long int ll;
typedef long double ld;
#define fr(i,a,b) for(ll i=a; i<b; i++)
#define rf(i,a,b) for(ll i=a; i>=b; i--)
#define pb push_back
#define mp make_pair
#define show(a) for(auto el:a)cout<<el<<" "
#define ff first
#define ss second
#define pairv vector<pair<ll,ll>>
#define vec vector <ll> 
#define all(a) a.begin(),a.end()
#define fam(v,i) for(auto i=v.begin();i!=v.end();i++)
#define fai(v,i) for(auto i : v)
#define mo 1000000007
#define nn cout<<"\n";
ll pow1(ll n,ll p)
{
if(p==0) return 1;
ll x=pow1(n, p/2);
x=(x*x)%mo;
if(p%2==0)
return x;
else
return (x*n)%mo;
}
bool sortbysec(const pair<ll,ll> &a, 
const pair<ll,ll> &b) 
{ 
return (a.second < b.second); 
} 
bool compare(const pair<ll, ll>&p1, const pair<ll,ll>&p2)
{
if(p1.ff < p2.ff) return true;
if(p1.ff == p2.ff) return p1.ff < p2.ss;
return false;
}


int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    ll x,a,b,c,d;
    cin>>a>>b>>c>>d;
        ll e[4];
      e[0] =a*c;
e[1]=a*d;

    e[2]=b*c;
    e[3]=b*d;
sort(e,e+4);
cout<<e[3];
    
     return 0;
}


Measured memory_bytes: 3628
A,B,M = map(int,input().split())
Ali = list(map(int,input().split()))
Bli = list(map(int,input().split()))
C=[]
while True:
    try:
        C.append(list(map(int,input().split())))

    except:
        break;

notuse = min(Ali) + min(Bli)
minuse =10000000
for i in range(M):
    minuse = min(Ali[C[i][0]-1] +Bli[C[i][1]-1]-C[i][2],minuse)
print(min(minuse,notuse))

Measured memory_bytes: 38568
#include<iostream>
#include<string>
using namespace std;
int main() {
	int n, k; cin >> n >> k;
	string s; cin >> s;
	char s1;
	if (s[k - 1] == 'A') {
		s1 = 'a';
	}
	else if (s[k - 1] == 'B') {
		s1 = 'b';
	}
	else if (s[k - 1] == 'C') {
		s1 = 'c';
	}
	s[k - 1] = s1;
	cout << s << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <cstdlib>

long long INF = 1LL << 60;

template<class T> inline bool chmin(T& a, T b) {
  if ( a > b ) {
    a = b;
    return true;
  }
  return false;
}

int main()
{
  long long dp[100010];
  for ( int i = 0; i < 100010; i++ ) dp[i] = INF;
  int N; std::cin >> N;
  long long h[N];
  for ( int i = 0; i < N; i++ ) std::cin >> h[i];

  dp[0] = 0;
  for ( int i = 1; i < N; i++ ) {
    chmin(dp[i], dp[i-1] + std::abs(h[i] - h[i-1]));
    if ( i > 1 ) chmin(dp[i], dp[i-2] + std::abs(h[i] - h[i-2]));
  }

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


Measured memory_bytes: 1792
package main

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

func main() {
	X := getStdinInt()
	if 400 <= X && X < 600 {
		fmt.Printf("%d", 8)
	} else if X < 800 {
		fmt.Printf("%d", 7)
	} else if X < 1000 {
		fmt.Printf("%d", 6)
	} else if X < 1200 {
		fmt.Printf("%d", 5)
	} else if X < 1400 {
		fmt.Printf("%d", 4)
	} else if X < 1600 {
		fmt.Printf("%d", 3)
	} else if X < 1800 {
		fmt.Printf("%d", 2)
	} else {
		fmt.Printf("%d", 1)
	}
}

var sc = bufio.NewReaderSize(os.Stdin, 1024*1024*10)

func getStdin() string {
	return readLine()
}
func getStdinInt() int {
	str := getStdin()
	rtn, _ := strconv.Atoi(str)
	return rtn
}
func getStdinInt2() (int, int) {
	list := getStdinIntArr()
	return list[0], list[1]
}
func getStdinInt3() (int, int, int) {
	list := getStdinIntArr()
	return list[0], list[1], list[2]
}
func getStdinInt64() int64 {
	str := getStdin()
	rtn, _ := strconv.ParseInt(str, 10, 64)
	return rtn
}
func getStdinInt64_2() (int64, int64) {
	list := getStdinIntArr64()
	return list[0], list[1]
}
func getStdinInt64_3() (int64, int64, int64) {
	list := getStdinIntArr64()
	return list[0], list[1], list[2]
}
func getStdinIntArr() []int {
	str := getStdin()
	list := strings.Split(str, " ")
	rtn := make([]int, len(list))
	for idx, val := range list {
		rtn[idx], _ = strconv.Atoi(val)
	}
	return rtn
}
func getStdinIntArr64() []int64 {
	str := getStdin()
	list := strings.Split(str, " ")
	rtn := make([]int64, len(list))
	for idx, val := range list {
		rtn[idx], _ = strconv.ParseInt(val, 10, 64)
	}
	return rtn
}
func readLine() string {
	buf := make([]byte, 0, 0)
	for {
		l, p, _ := sc.ReadLine()
		buf = append(buf, l...)
		if !p {
			break
		}
	}
	return string(buf)
}


Measured memory_bytes: 2184
#include <bits/stdc++.h>
#define pi 3.14159
using namespace std;
typedef long long LL;
const LL MOD = 1e9 + 7;
const long long N = 2e7 + 9, M = 1e7, OO = 0x3f3f3f3f;
vector<long long>v;
void bfs(long long n, long long m)
{
    queue<long long> q;
    for (long long i = 0 ; i <= 9 ; i++)
        q.push(i);

    while (!q.empty())
    {
        long long stepNum = q.front();
        q.pop();
        if (stepNum <= m && stepNum >= n){
           v.push_back(stepNum);
        }
        if (stepNum == 0 || stepNum > m)
            continue;
        long long lastDigit = stepNum % 10;
        long long stepNumC=stepNum * 10 + (lastDigit);
        long long stepNumA = stepNum * 10 + (lastDigit- 1);
        long long stepNumB = stepNum * 10 + (lastDigit + 1);
        if (lastDigit == 0){
            q.push(stepNumB);
            q.push(stepNumC);
        }

        else if (lastDigit == 9){
            q.push(stepNumC);
            q.push(stepNumA);
        }

        else
        {
            q.push(stepNumC);
            q.push(stepNumA);
            q.push(stepNumB);
        }
    }
}
int main()
{
int k;
bfs(0,8e10);
sort(v.begin(),v.end());
scanf("%d",&k);
printf("%lld",v[k]);






    return 0;
}


Measured memory_bytes: 18796
Q = gets.to_i

def is_prime(x)
  if x < 2
    return false
  end

  if x == 2
    return true
  end

  if x % 2 == 0
    return false
  end

  i = 3
  while i <= x**(1/2.0)
    if x % i == 0
      return false
    end
    i += 2
  end

  return true
end

MAX = 10**5 + 1
like_numbers = Array.new(MAX) { 0 }
1.upto(MAX) do |i|
  if i % 2 == 0
    next
  else
    if is_prime(i) && is_prime((i+1)/2)
      like_numbers[i] = 1
    end
  end
end

# p like_numbers

sum = Array.new(MAX+1) {0}
0.upto(MAX-1) do |i|
  sum[i+1] = sum[i] + like_numbers[i]
end

# p sum

Q.times do
  l, r = gets.split.map(&:to_i)
  puts sum[r+1] - sum[l]
end


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

#define REP(i, n, N) for(ll i=(n); i<(N); i++)
#define RREP(i, n, N) for(ll i=(N-1); i>=(n); i--)
#define LREP(lst,itr) for(auto itr = lst.begin(); itr != lst.end(); ++itr)
#define CK(n, a, b) ((a)<=(n)&&(n)<(b))
#define ALL(v) (v).begin(),(v).end()
#define MCP(a, b) memcpy(b,a,sizeof(b))
#define P(s) cout<<(s)<<endl
#define P2(a, b) cout<<(a)<<" "<<(b)<<endl
#define P3(a, b, c) cout<<(a)<<" "<<(b)<<" "<<(c)<<endl
#define V2(T) vector<vector<T>>
typedef long long ll;
using namespace std;
const ll MOD = 1e9 + 7;
const ll INF = 1e18;

vector<int> vec;

int N,ans=0;

void dfs(int l, int r){ //[l,r)?????
    if(l==N) return;
    if(l==r){
        ans+=vec[l];
        return;
    }

    //???????????????
    int mini=1000, idx=-1;
    REP(x,l,r){
        if(mini<=vec[x]) continue;
        mini=vec[x];
        idx=x;
    }

    //??????????????????
    REP(x,l,r){
        vec[x]-=mini;
    }

    ans+=mini;
    dfs(l,idx);
    dfs(idx+1,r);
}

int main(){
    cin >> N;
    vec.resize(N);
    REP(i,0,N){
        cin >> vec[i];
    }
    dfs(0,N);
    P(ans);
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, N) for (int i = 0; i < (N); i++)
#define swap(a, b) (a += b, b = a - b, a -= b)
using namespace std;
int main()
{
    int N, D;
    cin >> N >> D;
    int sum = 1 + 2 * D;
    if (N % sum == 0)
    {
        cout << N / sum << endl;
    }
    else
    {
        cout << N / sum + 1 << endl;
    }
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
ll x,a,b;
bool check(ll a,ll b){
	if(a*a*a*a*a - b*b*b*b*b == x) return true;
	return false;
}
int main(){
	cin>>x;
	for(ll i = -500;i<=500;i++) for(ll j=-500;j<=500;j++){
		if(check(i,j)){
			a = i,b = j;
			break;
		}
	}
	cout<<a<<" "<<b<<endl;
	return 0;
}

Measured memory_bytes: 3568
#include<bits/stdc++.h>
using namespace std;
int main(){
int n;
  cin>>n;
  vector<int>v(n);
  for(int i=0;i<n;i++){
  	cin>>v[i];
  }
sort(v.begin(),v.end(),greater<int>());
  long long int sum=0;
  for(int i=1;i<n;i++){
  	sum+=v[i/2];
  }
  
cout<<sum<<endl;
}


Measured memory_bytes: 3936
n,k = map(int,input().split())
a = list(map(int,input().split()))

cs_l = [0] * (n+2)
cs_r = [0] * (n+2)
for cs,ax in zip([cs_l,cs_r],[a,a[::-1]]):
    for i in range(n):
        cs[i+1] = cs[i] + max(ax[i],0)

cs_r = cs_r[::-1]

ans = 0
center = sum(a[:k])
for i in range(n-k+1):
    ans = max(ans, max(0,center) + cs_l[i] + cs_r[i+k+1])
    if(i==n-k):
        break
    center += a[i+k] - a[i]
print(ans)

Measured memory_bytes: 88768