akhauriyash/Code-Regression huggingface dataset:
from collections import deque
s = input()
q = int(input())
flag = True
atama = []  # 逆順
osiri = []
for i in range(q):
    inp = input()
    if inp == '1':
        flag = not flag

    else:
        _, f, c = map(str, inp.split())
        if f == '1':
            if flag:
                atama.append(c)
            else:
                osiri.append(c)
        else:
            if flag:
                osiri.append(c)
            else:
                atama.append(c)

if flag:
    for t in atama[::-1]:
        print(t, end='')
    print(s, end='')
    for t in osiri:
        print(t, end='')
else:
    for t in osiri[::-1]:
        print(t, end='')
    print(s[::-1],  end='')
    for t in atama:
        print(t, end='')


Measured memory_bytes: 86640
import java.util.Comparator;
import java.util.LinkedList;
import java.util.List;
import java.util.PriorityQueue;
import java.util.Queue;
import java.util.Scanner;

public class Main {
	class Edge {
		int to, dist, cost;
		Edge(int to, int dist, int cost) {
			this.to = to; this.dist = dist; this.cost = cost;
		}
	}
	class Pair {
		int f, s;
		Pair(int f, int s) {
			this.f = f; this.s = s;
		}
	}
	class Graph {
		 LinkedList<Edge> edges = new LinkedList<Edge>();
	}

	final int MAX_V = 10000;
	
	void run() {
		Scanner scan = new Scanner(System.in);
		while (true) {
			int n = scan.nextInt();
			int m = scan.nextInt();
			if (n + m == 0)
				break;
//			List<Edge>[] g = new LinkedList[MAX_V];
//			for (int i = 0; i < MAX_V; i++)
//				g[i] = new LinkedList<Edge>();
			
			Graph[] g = new Graph[MAX_V];
			for (int i = 0; i < MAX_V; i++)
				g[i] = new Graph();

			for (int i = 0; i < m; i++) {
				int u = scan.nextInt();
				int v = scan.nextInt();
				int d = scan.nextInt();
				int c = scan.nextInt();
				g[u].edges.add(new Edge(v, d, c));
				g[v].edges.add(new Edge(u, d, c));
			}
			int[] dist = new int[MAX_V + 1];
			int[] cost = new int[MAX_V + 1];
			for (int i = 0; i < MAX_V; i++)
				dist[i] = Integer.MAX_VALUE;
			Queue<Pair> que = new PriorityQueue<Pair>(new Comparator<Pair>() {
	            @Override
	            public int compare(Pair p1, Pair p2) {
	                return p1.f - p2.f;
	            }
	        });
			dist[1] = 0;
			que.add(new Pair(0, 1));

			while (!que.isEmpty()) {
				Pair p = que.poll();
				int v = p.s;
//				System.out.println("p.s: " + p.s + ", p.f: " + p.f);
				if (dist[v] < p.f) continue;
//				System.out.println("g[v].size:" + g[v].size());
				for (int i = 0; i < g[v].edges.size(); i++) {
					Edge e = g[v].edges.get(i);
					if (dist[e.to] > dist[v] + e.dist) {
						dist[e.to] = dist[v] + e.dist;
						cost[e.to] = e.cost;
//						System.out.println("que.add: " + dist[e.to] + ", " + e.to);
						que.add(new Pair(dist[e.to], e.to));
					} else if (dist[e.to] == dist[v] + e.dist) {
						cost[e.to] = Math.min(cost[e.to], e.cost);
					}
				}
//				for (int i = 0; i < n; i++)
//					System.out.print(dist[i] + " ");
//				System.out.println("dist");
//				for (int i = 0; i < n; i++)
//					System.out.print(cost[i] + " ");
//				System.out.println("cost");
//				System.out.println();
			}
			int ans = 0;
			for (int i = 0; i <= MAX_V; i++)
				if (cost[i] != Integer.MAX_VALUE) ans += cost[i];
			System.out.println(ans);
		}
	}
	public static void main(String[] args) {
		new Main().run();
	}
}



Measured memory_bytes: 166436
n, k, q = map(int, input().split())

a_list = [0 for i in range(n)]
for i in range(q):
    j = int(input())-1
    a_list[j] += 1

for a in a_list:
    if q-a < k:
        print('Yes')
    else:
        print('No')

Measured memory_bytes: 4672
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
#define let const auto
#define rep(i,n) for(int i=0; i<(n); ++i)
#define reps(i,f,n) for(int i=(f); i<=(n); ++i)
#define outl(x) cout<< (x) << '\n'

const int INF = 1 << 20;

int main()
{
   cin.tie(0), ios::sync_with_stdio(false);
   int N, m, X;
   bool f[128] = {};

   cin >> N >> m >> X;
   rep(i, m) {
      int a;
      cin >> a;
      f[a] = true;
   }

   int ans;
   int r = 0, l=0;

   for (int i=X; i>=0; --i) {
      if (f[i]) ++r;
   }

   for (int i=X; i<=N; ++i) {
      if (f[i]) ++l;
   }

   outl(min(r,l));
}



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

typedef vector<int> vi;

template<typename T>
static inline void p(T x) { cout << x << endl; }

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

	int n, cnt = 0;
	cin >> n;

	vi A(n), G;
	for (int &x: A)
		cin >> x;

	for (int i = 1, x = 1; x <= n; x = (pow(3, ++i) - 1) / 2)
		G.push_back(x);
	reverse(G.begin(), G.end());

	for (int g: G)
		for (int i = g; i < n; i++) {
			int v = A[i], j = i - g;
			for(; j >= 0 && A[j] > v; j -= g)
				A[j+g] = A[j], cnt++;
			A[j+g] = v;
		}

	p(G.size());
	for (int &x: G)
		cout << (&x == &G[0] ? "" : " ") << x;
	p("");
	p(cnt);
	for (int x: A)
		p(x);
}


Measured memory_bytes: 6748
package main

import (
	"bufio"
	"fmt"
	"os"
)

var sc = bufio.NewScanner(os.Stdin)

func init() {
	const maxWord = (1 << 30)
	buf := []byte{}
	sc.Buffer(buf, maxWord)
	sc.Split(bufio.ScanWords)
}

func input() string {
	sc.Scan()
	return sc.Text()
}

type ARange struct {
	start int
	mean  int
	end   int
}

func solve(s string) int {
	n := len(s) + 1
	aRanges := make([]ARange, 0, n)
	start := 0
	mean := 0
	end := 1
	current := s[0]
	if current == '<' {
		mean++
	}
	for i := 1; i < n-1; i++ {
		if current == '<' {
			if s[i] == '<' {
				mean++
				end++
			} else {
				end++
				current = s[i]
			}
		} else {
			if s[i] == '<' {
				aRanges = append(aRanges, ARange{start, mean, end})
				start = end
				mean = end + 1
				end++
				current = s[i]
			} else {
				end++
			}
		}
	}
	aRanges = append(aRanges, ARange{start, mean, end})

	ans := 0
	for _, v := range aRanges {
		up := v.mean - v.start
		down := v.end - v.mean
		if up == 0 {
			ans += (down + 1) * down / 2
		} else if down == 0 {
			ans += (up + 1) * up / 2
		} else {
			if up > down {
				ans += (up + 1) * up / 2
				ans += down * (down - 1) / 2
			} else {
				ans += (down + 1) * down / 2
				ans += up * (up - 1) / 2
			}
		}
	}
	return ans
}

func main() {
	s := input()
	fmt.Println(solve(s))
}


Measured memory_bytes: 6784
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
#include<ext/pb_ds/tag_and_trait.hpp>

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

using namespace std;
using namespace __gnu_pbds;

typedef long long ll;

struct Data {
  ll v;
  int ID;
  bool operator < ( const Data &data ) const {
    if( v != data.v ) return v > data.v;
    return ID < data.ID;
  }
};

int main() {
  int N,C;
  scanf("%d %d",&N,&C);
  vector<ll> score(N,0);
  tree<Data,null_type,less<Data>,rb_tree_tag,tree_order_statistics_node_update> S;
  rep(i,N) S.insert((Data){0,i});
  rep(i,C) {
    int o;
    scanf("%d",&o);
    if( o == 0 ) {
      int t,p;
      scanf("%d %d",&t,&p);
      --t;
      S.erase((Data){score[t],t});
      score[t] += p;
      S.insert((Data){score[t],t});
    } else {
      int m;
      scanf("%d",&m);
      --m;
      Data d = *S.find_by_order(m);
      cout << d.ID+1 << " " << score[d.ID] << endl;
    }
  }
  return 0;
}

Measured memory_bytes: 9976
#include<stdio.h>
int main(void){
int n,a,b,a1,b1,i;
while(1){
a1=0;
b1=0;
scanf("%d",&n);
if(n==0){break;}
for(i=0;i<n;i++){
scanf("%d%d",&a,&b);
if(a>b){
a1+=a+b;
}else if(b>a){
b1+=a+b;
}else{
a1+=a;
b1+=b;
}
}
printf("%d %d\n",a1,b1);
}
return 0;
}

Measured memory_bytes: 600
#include<iostream>
#include<vector>
#include<string>
#define rep(i, start, end) for (int i = (int)start; i < (int)end; ++i)
#define rrep(i, start, end) for (int i = (int)start - 1; i >= (int)end; --i)
#define all(x) (x).begin(), (x).end()
using namespace std;
using ll = long long;
template<typename T> inline bool chmax(T& a, T b) {if (a < b) {a = b; return true;} return 0;}
template<typename T> inline bool chmin(T& a, T b) {if (a > b) {a = b; return true;} return 0;}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N;
    string S;
    cin >> N >> S;
    vector<ll> cnt(3, 0);
    string rgb = "RGB";
    ll ans = 0;
    rep(i, 0, N) {
        rep(j, i + 1, N) {
            if (S[i] != S[j]) {
                rep(k, 0, 3) {
                    if (rgb[k] != S[i] && rgb[k] != S[j]) {
                        ans += cnt[k] - (2 * i - j >= 0 && S[2 * i - j] == rgb[k]);
                        break;
                    }
                }
            }
        }
        rep(j, 0, 3) {
            if (rgb[j] == S[i]) {
                ++cnt[j];
            }
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3608
def examA():
    C = [SI()for _ in range(3)]
    ans = C[0][0]+C[1][1]+C[2][2]
    print(ans)
    return

def examB():
    N, M = LI()
    P = [0]*N
    S = [LSI()for _ in range(M)]
    pena = 0
    ac = set()
    for p,s in S:
        p = int(p)-1
        if s=="WA":
            P[p] += 1
        else:
            if p in ac:
                continue
            ac.add(p)
            pena += P[p]

    print(len(ac),pena)
    return

def examC():
    W, H, N = LI()
    lx, rx, ly, ry = 0, W, 0, H
    A = [LI()for _ in range(N)]
    for x,y,a in A:
        if a==1:
            lx = max(lx,x)
        elif a==2:
            rx = min(rx,x)
        elif a==3:
            ly = max(ly,y)
        elif a==4:
            ry = min(ry,y)
    ans = max(0,rx-lx)*max(0,ry-ly)
    print(ans)
    return

def examD():
    N, H = LI()
    B = [0]*N
    maxa = 0
    ans = 0
    for i in range(N):
        a, B[i] = LI()
        if a>maxa:
            maxa = a
    B.sort(reverse=True)
    for b in B:
        if b<maxa:
            break
        H -= b
        ans += 1
        if H<=0:
            print(ans)
            return
    ans += -(-H//maxa)
    print(ans)
    return

def examE():
    ans = 0
    print(ans)
    return

def examF():
    ans = 0
    print(ans)
    return

import sys,bisect,itertools,heapq,math,random
from copy import deepcopy
from heapq import heappop,heappush,heapify
from collections import Counter,defaultdict,deque
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
def I(): return int(readline())
def LI(): return list(map(int,readline().split()))
def LSI(): return list(map(str,sys.stdin.readline().split()))
def LS(): return sys.stdin.readline().split()
def SI(): return sys.stdin.readline().strip()
global mod,mod2,inf,alphabet,_ep
mod = 10**9 + 7
mod2 = 998244353
inf = 10**18
_ep = 10**(-12)
alphabet = [chr(ord('a') + i) for i in range(26)]

sys.setrecursionlimit(10**7)

if __name__ == '__main__':
    examD()

"""
142
12 9 1445 0 1
asd dfg hj o o
aidn
"""

Measured memory_bytes: 42460
#include<stdio.h>
#define N 100

int main(){
  int min,i,j,n,a[N],swap,y=0;

  scanf("%d",&n);

  for(i=0;i<n;i++) scanf("%d",&a[i]);
    
  for(i=0;i<n;i++){
    min=i;
    for(j=i;j<n;j++){      
      if(a[j]<a[min]){
	min=j;	
      }      
    }
          
    if(min!=i){
      swap=a[i];
      a[i]=a[min];
      a[min]=swap;
      y++;      
    }
    
  }
   
  for(i=0;i<n;i++){
    printf("%d",a[i]);
    if(i!=n-1) printf(" ");
  }
  
  printf("\n%d\n",y);
  return 0;
}
      



Measured memory_bytes: 2128
package main

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

func gcd(a int, b int) int {
	if b == 0 {
		return a

	}
	return gcd(b, a%b)
}

func lcm(a int, b int) int {
	return a * b / gcd(a, b)
}

func main() {

	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)

	array := make([]int, 2)
	for i := 0; i < 2; i++ {
		sc.Scan()
		array[i], _ = strconv.Atoi(sc.Text())
	}
	answer := lcm(array[0], array[1])

	fmt.Println(answer)
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
#include <atcoder/all>
using namespace std;
using namespace atcoder;
using ll = long long;
int main(){
  ios::sync_with_stdio(0);
  cin.tie(0);
  int n,m;
  cin >> n >> m;
  dsu d(n);
  while(m--){
    int u,v;
    cin >> u >> v;
    d.merge(u-1,v-1);
  }
  cout << d.groups().size()-1;
  return 0;
}

Measured memory_bytes: 8944
#include<iostream>

using namespace std;

int main(){
  int N, M, *A, *B, *fpoint, mcount;
  int i, j;
  cin >> N >> M;
  A = new int[M];
  B = new int[N];
  fpoint = new int[N];
  for(i =0 ; i < N; i++) fpoint[i] = 0;
  for(i = 0; i < M; i++) cin >> A[i];
  for(i = 0; i < M; i++){
    mcount = 0;
	  for(j = 0; j < N; j++) cin >> B[j];
    for(j = 0; j < N; j++){
      if(B[j] == A[i]) fpoint[j]++;
      else mcount++;
    }
    fpoint[A[i]-1] += mcount;
  }
  for(i = 0; i < N; i++) cout << fpoint[i] << endl;
  return 0;
}

Measured memory_bytes: 3076
#include <iostream>
#include <string>
#include <vector>

#define INC(i, a, b) for(int i = a; i < b; ++i)
#define DEC(i, a, b) for(int i = a; i > b; --i)
#define REP(i, n) INC(i, 0, n)

typedef unsigned int uint;
typedef unsigned long ul;
typedef long long  ll;
typedef unsigned long long ull;

void TFprint(bool b, std::string T, std::string F){
    if(b){
        std::cout << T << std::endl;
    }else{
        std::cout << F << std::endl;
    }
}

int main(){
    int n; std::cin >> n;
    std::vector<ull> a;
    ull temp;
    ull ans = 0;

    REP(i, 3 * n){
        std::cin >> temp;
        a.push_back(temp);
    }
    std::sort(a.begin(), a.end(), std::greater<ull>());

    REP(i, n){
        //std::cout << a[2 * i + 1] << ' ';
        ans += a[2 * i + 1];
    }
    std::cout << std::endl;
    std::cout << ans << std::endl;
    return 0;
}

Measured memory_bytes: 6384
def isCLKWISE(ph) : return not ((ph[-1][0] - ph[-3][0])*(- ph[-3][1] + ph[-2][1]) - (ph[-2][0] - ph[-3][0])*(- ph[-3][1] + ph[-1][1] ) < 0)
      
def ConvexHullScan(P):
    P = sorted(P)
    phU = [P[0],P[1]]
    for p in P[2:]:
        phU.append(p)
        while(True):
            try :
                if isCLKWISE(phU) : break
                else : del phU[-2]
            except IndexError : break
    phL = [P[-1],P[-2]]
    for p in P[-3::-1]:
        phL.append(p)
        while(True):
            try :
                if isCLKWISE(phL) : break
                else : del phL[-2]
            except IndexError : break
    ph = phU + phL[1:-1]
    return ph
  
n = range(int(input()))
P = [[int(x) for x in input().split()] for _ in n]
Q = ConvexHullScan(P)
Q.reverse()
print(len(Q))
idx = min([[x[1][1],x[1][0],x[0]] for x in enumerate(Q)])[2]
R = Q[idx:] + Q[:idx]
for r in R : print(r[0],r[1])

Measured memory_bytes: 33904
#include <stdio.h>
int main(void){
    int i,j,H,W;
    while(1){
        scanf("%d %d",&H,&W);
        if(H==0&&W==0) break;
        for(i=1;i<=H;i++){
            for(j=1;j<=W;j++) putchar('#');
            putchar('\n');
        }
        putchar('\n');
    }
   
    return 0;
}



Measured memory_bytes: 2100
void main() {
	auto ip = readAs!(int[]), H = ip[0], W = ip[1];
	auto c = readMatrix!int(10, 10);
	auto A = readMatrix!int(H, W);

	foreach(k; 0..10) foreach(i; 0..10) foreach(j; 0..10) {
		if(c[i][j] > c[i][k] + c[k][j]) c[i][j] = c[i][k] + c[k][j];
	}
	ulong res;
	foreach(i; A) foreach(j; i) {
		if(j != -1) res += c[j][1];
	}
	res.writeln;
}

// ===================================

import std.stdio;
import std.string;
import std.functional;
import std.algorithm;
import std.range;
import std.traits;
import std.math;
import std.container;
import std.bigint;
import std.numeric;
import std.conv;
import std.typecons;
import std.uni;
import std.ascii;
import std.bitmanip;
import core.bitop;

T readAs(T)() if (isBasicType!T) {
	return readln.chomp.to!T;
}

T readAs(T)() if (isArray!T) {
	return readln.split.to!T;
}

T[][] readMatrix(T)(uint height, uint width) if (!isSomeChar!T) {
	auto res = new T[][](height, width);
	foreach(i; 0..height) {
		res[i] = readAs!(T[]);
	}
	return res;
}

T[][] readMatrix(T)(uint height, uint width) if (isSomeChar!T) {
	auto res = new T[][](height, width);
	foreach(i; 0..height) {
		auto s = rs;
		foreach(j; 0..width) res[i][j] = s[j].to!T;
	}
	return res;
}

int ri() {
	return readAs!int;
}

double rd() {
	return readAs!double;
}

string rs() {
	return readln.chomp;
}


Measured memory_bytes: 3580
#include <stdio.h>
 
int main(void) {
 
	char x[10];
	scanf("%s",x);
 
	if(x[0] == x[1] || x[1] == x[2] || x[2] == x[0]){
		printf("No");
	}else{
		printf("Yes");
	}
	
	return 0;
}


Measured memory_bytes: 128
/*
confirm 0LL and 1LL
confirm cornercases such as 0
confirm times of cin < 10^6
*/
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
using Vec = vector<ll>;
using VecP = vector<P>;
using VecB = vector<bool>;
using VecC = vector<char>;
using VecS = vector<string>;
using VecVec = vector<Vec>;
using Tree = vector<VecP>;
#define REP(i, m, n) for(ll (i) = (m); (i) < (n); ++(i))
#define REPN(i, m, n) for(ll (i) = (m); (i) <= (n); ++(i))
#define REPR(i, m, n) for(ll (i) = (m)-1; (i) >= (n); --(i))
#define REPNR(i, m, n) for(ll (i) = (m); (i) >= (n); --(i))
#define rep(i, n) REP(i, 0, n)
#define repn(i, n) REPN(i, 1, n)
#define repr(i, n) REPR(i, n, 0)
#define repnr(i, n) REPNR(i, n, 1)
#define all(s) (s).begin(), (s).end()
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define fs first
#define sc second
template <typename T>
bool chmax(T &a, const T& b){if(a < b){a = b; return true;} return false;}
template <typename T>
bool chmin(T &a, const T& b){if(a > b){a = b; return true;} return false;}
template <typename T>
void co(const T n){cout << n << endl;}
template <typename T>
void cosp(const T n){cout << n << ' ';}
void coVec(const Vec &v){for(ll i : v) cosp(i); cout << endl;}
void sonic(){ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);}
void setp(const ll n){cout << fixed << setprecision(n);}
const ll INF = 1e9+1;
const ll LINF = 1e18+1;
const ll MOD = 1e9+7;
//const ll MOD = 998244353;
const double PI = acos(-1);
const double EPS = 1e-9;

VecVec dp;

int main(void){
	string s, t;
	cin >> s >> t;
	ll lenS = s.length(), lenT = t.length();
	dp.resize(lenS+1);
	rep(i, lenS+1) dp[i].resize(lenT+1);

	rep(i, lenS+1) dp[i][0] = 0;
	rep(j, lenT+1) dp[0][j] = 0;

	repn(i, lenS) repn(j, lenT){
		if(s[i-1] == t[j-1]) dp[i][j] = dp[i-1][j-1]+1;
		chmax(dp[i][j], dp[i-1][j]);
		chmax(dp[i][j], dp[i][j-1]);
	}

	ll x = lenS, y = lenT;
	string ans;
	while(x > 0 && y > 0){
		if(dp[x][y] == dp[x-1][y-1]+1 && s[x-1] == t[y-1]){
			ans += s[x-1];
			x--; y--;
		}else if(dp[x][y] == dp[x-1][y]){
			x--;
		}else if(dp[x][y] == dp[x][y-1]){
			y--;
		}else return 0;
	}
	reverse(all(ans));
	co(ans);

	return 0;
}


Measured memory_bytes: 70784
n,a,b,c,d = map(int,input().split())
S = input()
 
ans = 0
def aaa(s,g):
    global ans
    if S[s:g].count("##") == 0:
        ans += 1
    
def bbb(s,g):
    global ans
    if S[s:g].count("##") == 0:
        ans += 1
        return(1)
    else:
        return(0)

def ccc(s,g):
    global ans
    if S[s:g].count("##") == 0:
        return(1)
    else:
        return(0)
        
if c < d:
    aaa(b,d)
    aaa(a,c)
else:
    flag = bbb(b,d)
    flag2 = ccc(a,c)
 #   print(ans)
    if flag == 1 and flag2 == 1:
        for i in range(b,d+1):
      #      print(i)
            if S[i-1:i] != "#":
                k = S[i-2:i-1] + "#" + S[i:i+1]
      #          print(k,i)
                if k.count("##") == 0:
                    ans += 1
                    break
#    print(flag)
#    print(ans)
 
if ans == 2:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 42480
import Data.Functor ((<$>))

main :: IO ()
main = do
  _ <- (read :: String -> Int) <$> getLine
  as <- map (read :: String -> Int) . words <$> getLine
  let min_a = minimum as
      max_a = maximum as
      sum_a = sum as
  putStrLn (show min_a ++ " " ++ show max_a ++ " " ++ show sum_a)



Measured memory_bytes: 11272
#include <iostream>
#include <algorithm>

using namespace std;
//入力された英文の中の単語Wの数を出力する
int main(){
	int ans = 0;
	string w;
	cin >> w;
	string word;
	while(cin >> word){
		string lower_word = "";
		for(auto itr = begin(word); itr != end(word); itr++){
			lower_word += tolower(*itr);
		}
		if(w == lower_word) ans++;
	}
	cout << ans << endl;
}



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

#define ld long double
#define ll long long
#define ALL(a)  (a).begin(),(a).end()
#define spa << " " <<
ll MOD = 1e9+7;
void chmin(ll &a, ll b) { if (a > b) a = b; }
void chmax(ll &a, ll b) { if (a < b) a = b; }

int main(){
  
  ll n;
  cin >> n;
  if(n % 2 == 0)
  cout << n << endl;
  else
    cout << n * 2 << endl; 

  return 0;
}

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

const int MAXN = 1005;

char s[MAXN], t[MAXN];

int main(){
	scanf("%s %s", s, t);
	
	int res = 1 << 20;
	for(int i = 0; s[i]; i++){
		int j = 0, c = 0;
		for( ; t[j] && s[i + j]; j++){
			if(s[i + j] != t[j]){
				c++;
			}
		}
		
		if(!t[j])res = min(res, c);
	}
	printf("%d\n", res);
	
	return 0;
}


Measured memory_bytes: 3832
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define pi 3.141592653589793238
#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define MOD 1000000007
bool sortbysec(const pair<ll,ll> &a,const pair<ll,ll> &b) { 
    return (a.second < b.second); 
}
int main()
{
	fast;
	ll n,a,b,sum=0;
	cin>>n;
	vector<pair<int,int>> v;
	for(ll i=0;i<n;i++)
	{
		cin>>a>>b;
		sum+=a;
		v.push_back({a,b});
	}
	sum=0;
	sort(v.begin(),v.end(),sortbysec);
	for(int i=0;i<n;i++){
		sum+=v[i].first;
		if(sum>v[i].second)
		{
			cout<<"No";
			return 0;
		}
	}
	cout<<"Yes";
	return 0;
}


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

using namespace std;
int main(void) {
    long l, r;
    cin >> l >> r;

    long res = 2e10;

    for(long i=0; i<2010; i++) {
        for(long j=i+1; j<2010; j++) {
            long ll = l + i;
            long rr = l + j;
            if(rr > r) break;
            res = std::min((ll*rr) % 2019L, res);
        }
    }

    cout << res << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <utility>
#include <functional>
#include <math.h>
#include <cmath>
#include <algorithm>
#include <iomanip>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <tuple>
#include <stdlib.h>
#include <stdio.h>
#include <sstream>
using namespace std;
#define rep(i,n,x) for(int i=n;i<x;i++)
#define rem(i,n,x) for(int i=n;i>x;i--)
#define SORT(x) sort(x.begin(),x.end())
#define REV(x) reverse(x.begin(),x.end())
#define all(x) x.begin(),x.end()
#define pb push_back
#define mp make_pair
#define fir first
#define sec second
#define setp(x) setprecision(x)
using LL = long long;
using ULL = unsigned long long;

int main() {
	int H, W, h, w;
	cin >> H >> W >> h >> w;

	int white = H * W;
	cout << white - (H * w + (W - w) * h) << endl;

	return 0;
}

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

int main()
{
	int k, t,i,max=0;
	int *a;
	scanf("%d %d", &k, &t);

	a = (int*)malloc(t * sizeof(int));

	for (i = 0; i < t; i++) {
		scanf("%d", &a[i]);
	}
	for (i = 0; i < t; i++) {
		if (a[i] > max)max = a[i];
	}
	if (k - max >= max)printf("%d\n", 0);
	else printf("%d\n", 2 * max - k - 1);

	free(a);
	return 0;
}

Measured memory_bytes: 128
#include <algorithm>
#include <iostream>
#include <cstdio>
#include <map>
#include <numeric>
#include <cmath>
#include <set>
#include <sstream>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <complex>
#include <string.h>
#include <unordered_set>
#include <unordered_map>
#include <bitset>
#include <iomanip>
#include <sys/time.h>
#include <tuple>
#include <random>
using namespace std;

#define endl '\n'
#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
#define UNIQ(v) (v).erase(unique((v).begin(), (v).end()), (v).end())

typedef long long ll;
typedef long double ld;
typedef pair<int, int> P;
typedef complex<double> comp;
typedef vector< vector<ld> > matrix;
struct pairhash {
public:
    template<typename T, typename U>
    size_t operator()(const pair<T, U> &x) const {
	size_t seed = hash<T>()(x.first);
	return hash<U>()(x.second) + 0x9e3779b9 + (seed<<6) + (seed>>2);
    }
};
const int inf = 1e9 + 9;
const ll mod = 1e9 + 7;
const double eps = 1e-8;
const double pi = acos(-1);

int n;
string s;

ll dp[3010][3010];

ll solve() {
    dp[0][0] = 1;
    for (int i = 0; i < n-1; i++) {
        if (s[i] == '<') {
            dp[i+1][0] = 0;
            for (int j = 1; j <= i+1; j++) {
                dp[i+1][j] = dp[i+1][j-1] + dp[i][j-1];
                dp[i+1][j] %= mod;
            }
        } else {
            dp[i+1][i+1] = 0;
            for (int j = i; j >= 0; j--) {
                dp[i+1][j] = dp[i+1][j+1] + dp[i][j];
                dp[i+1][j] %= mod;
            }
        }
    }

    ll res = 0;
    for (int i = 0; i < n; i++) {
        res += dp[n-1][i];
        res %= mod;
    }
    return res;
}

void input() {
    cin >> n >> s;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(15);

    input();
    cout << solve() << endl;
}


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

int main(){
    ll a, b , c, d;
    cin >> a >> b >> c >> d;
    ll ans = max(0LL, min(b,d)-max(a,c));
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <string>
#include <sstream>
#include <fstream>
#include <cassert>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <numeric>
#include <utility>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <complex>

using namespace std;

using ll = long long;
using ld = long double;
using pii = pair<int, int>;

constexpr int MAXN = 100005;
int k;
// value mod k, last digit = sum of digits
int dist[MAXN][10];

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

    scanf("%d", &k);
    deque<pii> q;
    memset(dist, -1, sizeof(dist));
    dist[1][1] = 1;
    q.push_back({1, 1});

    while (!q.empty()) {
        pii x = q.front();
        q.pop_front();

        // multiply by 10
        int by_ten = (x.first * 10) % k;
        if (dist[by_ten][0] == -1) {
            dist[by_ten][0] = dist[x.first][x.second];
            q.push_front({by_ten, 0});
        }

        int add_one = (x.first + 1) % k;
        if (x.second + 1 < 10 and dist[add_one][x.second + 1] == -1) {
            dist[add_one][x.second + 1] = dist[x.first][x.second] + 1;
            q.push_back({add_one, x.second + 1});
        }
    }

    int res = 987654321;
    for (int i = 0; i < 10; ++i) {
        if (dist[0][i] == -1) continue;
        res = min(res, dist[0][i]);
    }

    printf("%d\n", res);

    return 0;
}


Measured memory_bytes: 4992
#define _CRT_SECURE_NO_WARNINGS

#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <set>
#include <map>
#include <vector>
#include <math.h>
#include <cmath>
#include <queue>
#include <stack>
#include <list>
#include <functional>
#include <numeric>
#include <iostream>
#include <string>
#include <time.h>

using namespace std;
typedef long long ll;
#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define all(x) (x).begin(),(x).end()
ll GCD(ll a, ll b) { return b ? GCD(b, a % b) : a; }

int N;

int main() {

	scanf("%d", &N);

	int C = 0;
	rep(i, N) {
		if (i + 1 >= 1 && i + 1 <= 9) C++;
		if (i + 1 >= 100 && i + 1 <= 999) C++;
		if (i + 1 >= 10000 && i + 1 <= 99999) C++;
	}

	printf("%d\n", C);

	return 0;
}


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

struct edge {
    int a, b;
    i64 w;
};

i64 kruskal(vector<edge>& edges, int n) {
    vector<int> par(n);
    for (int i = 0; i < n; i++) {
        par[i] = i;
    }
    function<int(int)> find = [&](int x) {
        if (x == par[x]) return x;
        return par[x] = find(par[x]);
    };
    auto unite = [&](int x, int y) {
        x = find(x);
        y = find(y);
        par[x] = y;
    };
    auto same = [&](int x, int y) {
        return find(x) == find(y);
    };
    sort(edges.begin(), edges.end(), [](edge a, edge b) {
        return a.w < b.w;
    });
    i64 ret = 0;
    for (edge e: edges) {
        if (!same(e.a, e.b)) {
            unite(e.a, e.b);
            ret += e.w;
        }
    }
    return ret;
}

int main() {
    int v, e;
    cin >> v >> e;
    vector<edge> edges;
    for (int i = 0; i < e; i++) {
        int a, b;
        i64 w;
        cin >> a >> b >> w;
        edges.push_back({a, b, w});
    }
    cout << kruskal(edges, v) << endl;
}


Measured memory_bytes: 4956
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define FOR(i,l,r) for(i=l;i<r;i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(x) x.begin(),x.end()
#define P pair<ll,ll>
#define F first
#define S second
signed main(){
  int i;string S;cin>>S;
  REP(i,S.size()){
    if(S.at(i)=='P')cout<<"P";
    else cout<<"D";
  }
  cout<<endl;
  return 0;
}

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

using namespace std;
vector<int>P;
bool f(int n) {
	for (int m = 0; m < P.size(); ++m) {
		if (0 == n % P[m]) {
			return false;
		}
	}
	return true;
}



int main() {
	int X;
	cin >> X;
	for (int n = 2;n<200000;++n) {
		if (!f(n)) {
			continue;
		}
		if (n < X) {
			P.push_back(n);
		}else{
			cout <<n <<endl;
			return 0;
		}
	}
	
	return 0;
}


Measured memory_bytes: 3692
#include <stdio.h>

int main(void){
    char s[4];
    scanf("%s", s);
    int i;
    for(i = 0; i < 3; i++){
        if(s[i] == s[i+1]){
            printf("Bad\n");
            return 0;
        }
            
    }
    printf("Good\n");
    return 0;
}

Measured memory_bytes: 128
# 累積和の考え方
#   listに積み重ねた数値を出しておくことで特定範囲の数値を求める時間を短縮する
#   例：ABBBBAABBBBAB があるときに(l,r)にAがいくつ含まれるかを求める場合は以下のように(1長い)listを作る
#      BBABBBAABBBBAA
#      000111123333345
#   このリストの文字列のr-lで出せる(3,7)ならstr[7]-str[3]を出すと3-1で2となる

n, q = map(int, input().split())
s = input()
lr = [list(map(int, input().split())) for _ in range(q)]

# 累積和のリストを作成
cumsum = [0]*(n+1)
for i in range(1, n):
    if s[i-1] == 'A' and s[i] == 'C':
        cumsum[i+1]+=cumsum[i]+1
    else:
        cumsum[i+1]=cumsum[i]

# 012345   index
# 123456   input
# ACACAC   s
# 0011223  cumsum
for left, right in lr:
    print(cumsum[right]-cumsum[left])

Measured memory_bytes: 30700
#include <bits/stdc++.h>
using ll = long long;
using namespace std;
ll GCD(ll a, ll b){ return a ? GCD(b % a, a) : b; }
int main(){
    ll a,b,n;
    cin>>a>>b>>n;
    ll x=min(b-1,n);
    cout<<floorl(a*x/b)-((floorl(x/b))*a);
}

Measured memory_bytes: 3796
import java.util.Scanner;

public class Main {

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

        int n = scanner.nextInt();

        long takahashi = 1;
        long aoki = 1;

        for(int i=0; i<n; i++){
            int t = scanner.nextInt();
            int a = scanner.nextInt();

            long tmp1 = takahashi/t;
            long tmp2 = aoki/a;

            tmp1 += (takahashi%t==0)?0:1;
            tmp2 += (aoki%a==0)?0:1;

            long tmp = Math.max(tmp1, tmp2);

            takahashi = t*tmp;
            aoki = a*tmp;
        }

        System.out.println(takahashi + aoki);
    }
}


Measured memory_bytes: 13280
#include<cstdio>
int n,a[100005],cur;
inline int gcd(int a,int b){return b?gcd(b,a%b):a;}
const char*s[]={"First","Second"};
int main(){
	scanf("%d",&n);
	for(int i=1;i<=n;++i)scanf("%d",a+i);
	for(;;cur^=1){
		int c=0,d=0;
		bool b=0;
		for(int i=1;i<=n;++i)c+=!(a[i]&1),b|=a[i]==1,d=gcd(d,a[i]^(a[i]&1));
		if(b)return puts(s[c&1^!cur]),0;
		if(c&1)return puts(s[cur]),0;
		if(c!=n-1)return puts(s[!cur]),0;
		for(int i=1;i<=n;++i)a[i]/=d;
	}
}

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

int main(){
    int n; cin >> n;
    vector <int> a(n, 0);
    vector <int> b(n, 0);
    vector <int> c(n, 0);
    rep(i, n){
        cin >> a[i];
    }
    rep(i, n){
        cin >> b[i];
    }
    rep(i, n){
        cin >> c[i];
    }
    sort(a.begin(), a.end());
    sort(b.begin(), b.end());
    sort(c.begin(), c.end());
    ll res = 0;
    rep(i, n){
        ll l = lower_bound(a.begin(), a.end(), b[i]) -a.begin();
        ll r = n - (upper_bound(c.begin(), c.end(), b[i]) -c.begin());
        res += l*r;
    }
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 1408
// Created by Kshitij Anand NSIT
#include <bits/stdc++.h>
//#include <ext/numeric>
//using namespace __gnu_cxx;


using namespace std;


#define int long long
#define pb push_back
#define P pair<int,int>
#define F first
#define S second
#define vi vector<int>
#define vc vector<char>
#define vb vector<bool>
#define all(x) x.begin(),x.end()
#define sz(x) (int)x.size()
#define mp(a, b) make_pair(a, b)
#define min3(a, b, c) min(min(a, b), c)
#define min4(a, b, c, d) min(min(a, b), min(c, d))
#define max3(a, b, c) max(max(a, b), c)
#define max4(a, b, c, d) max(max(a, b), max(c, d))
#define fill(arr,val) memset(arr,val,sizeof(arr))
#define inf 1e18
#define ps(x,y) fixed<<setprecision(y)<<x
#define db(x)  cout<<#x<<" : "<<x<<endl


const int N = 1000000007;

void solve(){

    int n,a,b,c,d ,  ans=0, count=0, sum=0;
    cin>>a>>b>>c>>d;

    ans = a*c;

    ans = max({a*c , b*d , a*c , a*d , b*c});

    cout<<ans<<endl;
    return;

    

}

int32_t main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);
    
    
  //  int t; cin>>t; while(t--)
    {     
      solve();
    }

  return 0;
}


Measured memory_bytes: 3676
class UnionFind:
    __slots__ = ["N", "root", "rank"]

    def __init__(self, N):
        """
        N:要素数
        root:各要素の親要素の番号を格納するリスト.
             ただし, root[x] < 0 ならその頂点が根で-root[x]が木の要素数.
        rank:ランク
        """
        self.N = N
        self.root = [-1] * N

    def __repr__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())

    def find(self, x):
        """頂点xの根を見つける"""
        while self.root[x] >= 0:
            x = self.root[x]
        return x

    def union(self, x, y):
        """x, yが属する木をunion"""
        # 根を比較する
        # すでに同じ木に属していた場合は何もしない.
        # 違う木に属していた場合はrankを見てくっつける方を決める.
        # rankが同じ時はrankを1増やす
        x = self.find(x)
        y = self.find(y)
        if x == y:
            return
        elif self.root[y] < self.root[x]:
            x, y = y, x
        self.root[x] += self.root[y]
        self.root[y] = x

    def same(self, x, y):
        """xとyが同じグループに属するかどうか"""
        return self.find(x) == self.find(y)

    def count(self, x):
        """頂点xが属する木のサイズを返す"""
        return - self.root[self.find(x)]

    def members(self, x):
        """xが属する木の要素を列挙"""
        _root = self.find(x)
        return [i for i in range(self.N) if self.find == _root]

    def roots(self):
        """森の根を列挙"""
        return [i for i, x in enumerate(self.root) if x < 0]

    def group_count(self):
        """連結成分の数"""
        return len(self.roots())

    def all_group_members(self):
        """{ルート要素: [そのグループに含まれる要素のリスト], ...}の辞書を返す"""
        return {r: self.members(r) for r in self.roots()}


import sys
input = sys.stdin.readline
n, q = map(int, input().split())
uf = UnionFind(n)
res = []
for i in range(q):
    t, u, v = map(int, input().split())
    if t:
        res.append(int(uf.same(u, v)))
    else:
        uf.union(u, v)
print("\n".join(map(str, res)))


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

int n;
int a[100];
int dp[101][101];

int main(){
  scanf("%d",&n);
  for(int i=0;i<n;i++)
    scanf("%d",&a[i]);

  for(int i=0;i<=n;i++)dp[i][i]=1;

  
  for(int i=1;i<=n;i++){
    for(int j=0;j+i<=n;j++){
      for(int k=j+1;k<j+i;k++){
        if(a[j]==a[k]){
          dp[j][i+j]|=dp[j+1][k]*dp[k+1][i+j];
          dp[j][i+j]|=dp[j+1][k]*dp[k][i+j];
        }
      }
    }
  }

  printf( dp[0][n] ? "yes\n" : "no\n" );
  return 0;
}

Measured memory_bytes: 3268
#include <iostream>
#include <vector>
#include <tuple>
#include <algorithm>
#include <queue>
#include <functional>

using namespace std;

typedef long long ll;

int main()
{
    int N;
    cin >> N;
    vector<ll> vs(3 * N);

    for (auto &v : vs) cin >> v;

    vector<ll> ans_all(N + 1, 0);

    priority_queue<ll, vector<ll>, greater<ll>> fq;
    for (int i = 0; i < N; i++) {
        ans_all[0] += vs[i];
        fq.push(vs[i]);
    }
    for (int i = N; i < 2 * N; i++) {
        fq.push(vs[i]);
        ll low = fq.top();
        fq.pop();
        ans_all[i + 1 - N] = ans_all[i - N] - low + vs[i];         
    }

    vector<ll> ans_all_b(N + 1, 0);
    priority_queue<ll> bq;
    for (int i = 3 * N - 1; i >= 2 * N; i--) {
        ans_all_b[N] += vs[i];
        bq.push(vs[i]);
    }
    for (int i = 2 * N - 1; i >= N; i--) {
        bq.push(vs[i]);
        ll high = bq.top();
        bq.pop();
        ans_all_b[i - N] = ans_all_b[i - N + 1] - high + vs[i];
    }

    ll ans = -10000000000000000ULL;
    for (int i = 0; i <= N; i++) {
        ans = max(ans, ans_all[i] - ans_all_b[i]);
    }
    cout << ans << endl;
}

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


int main()
{
	string s;
	cin>>s;
	map<string,string> m;
	m["Sunny"]="Cloudy";
	m["Cloudy"]="Rainy";
	m["Rainy"]="Sunny";
	cout<<m[s]<<endl;
	return 0;
}


Measured memory_bytes: 256
from collections import deque
k = int(input())

que = deque([])
for i in range(1,10):
    que.appendleft(i)


for i in range(k):
    x = que.pop()
    if x % 10 != 0:
        que.appendleft(10*x+(x%10)-1)
    
    que.appendleft(10*x+(x%10))
    
    if x % 10 != 9:
        que.appendleft(10*x+(x%10)+1)

print(x)

Measured memory_bytes: 40816
#include<bits/stdc++.h>
using namespace std;
using ll = long long;


int main() {
	ll K, A, B;
	cin >> K >> A >> B;

	if(A + 1 <= K && B - A > 2) {
		ll rest = K - (A - 1);
		cout << A + (rest / 2) * (B - A) + rest % 2 << endl;
	}else {
		cout << K + 1 << endl;
	}

	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define BUF 1e5
#define INF 1 << 30
constexpr ll mod = 1e9 + 7;
using namespace std;
ll A, B, C, D, G, H, N, M, L, K, P, Q, R, W, X, Y, Z;
string S, T;
ll ans = 0;

int main() {
    cin >> N >> D;
    vector<vector<int>> x(N, vector<int>(D));
    for (int i = 0; i < N; i++) {
        for (int j = 0; j < D; j++)
            cin >> x[i][j];
    }
    for (int i = 0; i < N; i++) {
        for (int j = i + 1; j < N; j++) {
            int dist = 0;
            for (int d = 0; d < D; d++) {
                dist += (x[i][d] - x[j][d]) * (x[i][d] - x[j][d]);
            }
            int tmp = sqrt(dist);
            if (dist == tmp * tmp) {
                ans++;
            }
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
 
typedef long long ll;
typedef pair<int,int> ii;
 
int main() {
	cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(0);
	ll n,x; cin>>n>>x;
	vector<ll> a(n);
	for (int i=0; i<n; i++)
		cin>>a[i];
	sort(a.begin(),a.end());
	ll ret=0, sum=0;
	for (int i=0; i<n-1; i++) {
		sum+=a[i];
		if(sum<=x)
			ret++;
	}
	if(sum+a[n-1]==x)
		ret++;
	cout << ret << endl;
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

using namespace std;

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

#define RREP(a, i, n) for (int i = n - 1; i >= 0; --i)

int max(int X, int Y) {
    return X > Y ? X : Y;
}

int min(int X, int Y) {
    return X < Y ? X : Y;
}

int abs(int X, int Y) {
    return X > Y ? X - Y : Y - X;
}

int dp(int N, int K, int h[], int m[]) {
    int idx = N - 1;

    if ((-1) != m[idx]) {
        return m[idx];
    }

    if (2 == N) {
        return abs(h[idx], h[idx - 1]);
    } else {
        REP(1, i, K + 1) {
            if (N - i >= 2) {
                m[idx - i] = dp(N - i, K, h, m);
            }
        }

        int ans = 2000000000;
        REP(1, i, K + 1) {
            if (N - i >= 2) {
                ans = min(ans, abs(h[idx], h[idx - i]) + m[idx - i]);
            } else {
                ans = min(ans, abs(h[idx], h[idx - i]));
                break;
            }
        }

        return ans;
    }
}

int main() {
    int N; // 2 <= N <= 10^5
    int K; // 1 <= K <= 100
    scanf("%d %d", &N, &K);

    int h[N]; // 1 <= hi <= 10^4
    REP(0, i, N) {
        scanf("%d", &h[i]);
    }

    int m[N];
    REP(0, i, N) {
        m[i] = -1;
    }

    printf("%d\n", dp(N, K, h, m));

    return 0;
}

/*
5 3
10 30 40 50 20
30

3 1
10 20 10
20

2 100
10 10
0

10 4
40 10 20 70 80 10 20 70 80 60
40
*/


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

using namespace std;

string s0;
int N;
vector<int> digits;
long long totalSum=0;
long long dp[12]={0};
void dfs(int step){
	if (step==N-1){
		totalSum+=digits[N-1];
		return;
	}
	long long preNum=0;
	for (int firstP=step;firstP<N;firstP++){
		preNum = preNum*10+digits[firstP];
		totalSum += preNum * (1<<max(N-2-firstP,0));
		dfs(firstP+1);
	}
}

void solve(){
	cin>>s0;
	N = s0.size();
	for (int i=0;i<N;i++){
		digits.push_back(int(s0[i])-int('0'));
	}

	dfs(0);
	cout<<totalSum<<endl;
}


int main(){
//	freopen("in.txt","r",stdin);
	std::ios::sync_with_stdio(false);

//	int TestCase;
//	cin>>TestCase;
//	for (int i=0;i<TestCase;i++){
		solve();
//	}

	return 0;
}


Measured memory_bytes: 256
function Main(input){
    var [x,y] = input.split(" ").map(Number);
    var min = Number.MAX_SAFE_INTEGER;
{
    var arr = [0,0,0];
    arr[0] = Math.floor(x/3)*y
    var p = Math.ceil(x/3*2);
    arr[1] = p*Math.ceil(y/2);
    arr[2] = p*Math.floor(y/2);
   // console.log(arr)
    min = Math.min(Math.max.apply(null,arr)-Math.min.apply(null,arr),min);
}
{
    var arr = [0,0,0];
    arr[0] = Math.ceil(x/3)*y
    var p = Math.floor(x/3*2);
    arr[1] = p*Math.ceil(y/2);
    arr[2] = p*Math.floor(y/2);
    //console.log(arr)
    min = Math.min(Math.max.apply(null,arr)-Math.min.apply(null,arr),min);
}
x = y + (y=x,0);
{
    var arr = [0,0,0];
    arr[0] = Math.floor(x/3)*y
    var p = Math.ceil(x/3*2);
    arr[1] = p*Math.ceil(y/2);
    arr[2] = p*Math.floor(y/2);
    //console.log(arr)
    min = Math.min(Math.max.apply(null,arr)-Math.min.apply(null,arr),min);
}
{
    var arr = [0,0,0];
    arr[0] = Math.ceil(x/3)*y
    var p = Math.floor(x/3*2);
    arr[1] = p*Math.ceil(y/2);
    arr[2] = p*Math.floor(y/2);
    //console.log(arr)
    min = Math.min(Math.max.apply(null,arr)-Math.min.apply(null,arr),min);
}
{
    if(x%3==0){
        min = 0;
    }else{
        min = Math.min(min,y)
    }
}
{
    if(y%3==0){
        min = 0;
    }else{
        min = Math.min(min,x)
    }
}
console.log(min)
}Main(require("fs").readFileSync("/dev/stdin", "utf8").trim());


Measured memory_bytes: 29540
#include <bits/stdc++.h>
#define pb push_back
#define all(v) (v).begin() , (v).end()

using namespace std;

typedef vector<int> vi;
typedef long long   ll;

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

int main()
{
    int n;
    cin >> n;
    ll a[n] , sum = 0;
    for(int i=0;i<n;++i){
        cin >> a[i];
        sum += a[i];
    }
    ll cursum = 0 , ans = abs(a[0]-(sum-a[0]));
    for(int i=0;i<n-1;++i){
        cursum += a[i];
        ll cc = abs(cursum-(sum-cursum));
        ans = min(cc,ans);
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
#define repd(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
#define int long long
typedef long long ll;
using namespace std;
const int MOD = 1000000007;
const int INF = 1010000000;
const double EPS = 1e-10;
const pair<int,int> fd[] = {make_pair(1,0),make_pair(-1,0),make_pair(0,1),make_pair(0,-1)}; 

vector<int> init(int size){
  vector<int> par(size,-1);
  return par;
}

int root(int x, vector<int>& par){
  if(par[x] < 0){
    return x;
  }else{
    return par[x] = root(par[x],par);
  }
}

bool same(int x, int y, vector<int>& par){
  return root(x, par) == root(y, par);
}

void unite(int x, int y, vector<int>& par){
  x = root(x, par), y = root(y, par);
  if(same(x,y, par))return;
  par[x] += par[y];
  par[y] = x;
}

int size(int x, vector<int>& par){
  return -par[root(x, par)];
}

int pow(int x, int n){
  if(n == 0)return 1;
  if(n % 2 == 0)return pow(x * x % MOD, n/2);
  else return x * pow(x, n-1) % MOD;
}


signed main(){
  double n,d;cin>>n>>d;
  cout << ceil(n/(2*d+1)) << endl;
}


Measured memory_bytes: 256
fun main(args: Array<String>) {
    val (N, M) = readLine()!!.split(" ").map(String::toInt)

    val AN = readLine()!!.split(" ").map(String::toInt).sortedDescending()
    val a = AN.sum().toDouble() / (4.0 * M)

    if(AN.take(M).all { it.toDouble() >= a }){
        println("Yes")
    }else{
        println("No")
    }

}





Measured memory_bytes: 37932
n = int(input())
a = list(map(int, input().split()))
flag = True
for i in range(n):
    if a[i]%2 == 0:
        if a[i]%3 == 0 or a[i]%5 == 0:
            pass
        else:
            flag = False
if flag:
    print("APPROVED")
else:
    print("DENIED")

Measured memory_bytes: 38384
#include <bits/stdc++.h>
using namespace std;
int main(){
  int N,a=0,b=0;
  cin>>N;
  vector<int> A(N);
  for(int i=0; i<N; i++)
    cin>>A.at(i);
  sort(A.begin(),A.end());
  reverse(A.begin(),A.end());
  for(int i=0; i<N; i++){
    if(i%2==0)a+=A.at(i);
    else b+=A.at(i);
  }
  cout<<a-b<<endl;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
long long n, x, a, b, c, d;
int main() {
	cin>>n>>a>>b;
	while(--n) {
		cin>>c>>d;
		x = max((a-1)/c+1, (b-1)/d+1);
		a = c*x, b = d*x;
	}
	cout<<a+b;
	return 0;
}

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

int main(){
  int w,h,n;
  cin >> w >> h >> n;
  int m[101][101]={};
  int x,y,a;
  for(int i=0;i<n;++i){
	cin >> x >> y >> a;
	if(a==1){
		for(int j=0;j<x;++j){
			for(int k=0;k<h;++k){
				m[k][j]=1;
			}
		}
	}else if(a==2){
		for(int j=x;j<w;++j){
			for(int k=0;k<h;++k){
				m[k][j]=1;
			}
		}
	}else if(a==3){
		for(int j=0;j<w;++j){
			for(int k=0;k<y;++k){
				m[k][j]=1;
			}
		}
	}else{
		for(int j=0;j<w;++j){
			for(int k=y;k<h;++k){
				m[k][j]=1;
			}
		}
	}
  }
  
	int cnt=0;
	for(int i=0;i<w;++i){
		for(int j=0;j<h;++j){
			if(m[j][i]==0)cnt++;
		}	
	}
	cout << cnt << endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long int
#define yorn(f) cout<<((f)?"Yes":"No")<<endl;
#define YORN(f) cout<<((f)?"YES":"NO")<<endl;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repi(i, n) for (int i = 1; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
#define put(x) cout << x << endl;
#define println(x) cout << x << endl;
using namespace std;
int main()
{
    int k, n;
    cin >> k >> n;
    vector<int> a(n);
    rep(i, n) cin >> a[i];
    
    rep(i, n) a[i] = a[i] % k;
    sort(all(a));

    int best = 0;
    rep(i, n) {
        int d = 0;
        if (i == n -1) {
            d = k + a[0] - a[n-1];
        }
        else {
            d = a[i+1] - a[i];
        }
        best = max(best, d);
    }
    put(k - best);

    return 0;
}

Measured memory_bytes: 4056