akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cctype>
#include <cmath>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <algorithm>
#include <utility>
#include <deque>
#include <stack>
#include <bitset>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<int,ll> pil;
typedef pair<ll,int> pli;
#define rep(i,n) for (int i=0;i<n;++i)
#define REP(i,n) for (int i=1;i<=n;++i)
#define all(x) x.begin(),x.end()
#define mp make_pair
#define pb push_back
#define pf push_front
#define F first
#define S second
#define read(x) scanf("%d",&x)
int P,R,T;
int pp[305][305];
int rr[305];
class state{
public:
	int p[305][305];
	int r[305];
	inline bool off(int i){
		for (int j=1;j<=R;++j) if (p[i][j]) return 0;
		return 1;
	}
	inline bool on(int i){
		for (int j=1;j<=R;++j) if (p[i][j]) return 1;
		return 0;
	}
	inline bool available(int i){
		for (int j=1;j<=R;++j) if (p[i][j]>r[j]) return 0;
		return 1;
	}
	inline void release(int i){
		for (int j=1;j<=R;++j) r[j]+=pp[i][j];
	}
	inline bool judge(){// O(n^3)
		int p1[305][305],r1[305];
		rep(i,305) rep(j,305) p1[i][j]=p[i][j];
		rep(j,305) r1[j]=r[j];
		while(1){
			int cnt=0;
			for (int i=1;i<=P;++i) if (on(i)) ++cnt;
			if (!cnt){
				rep(i,305) rep(j,305) p[i][j]=p1[i][j];
				rep(j,305) r[j]=r1[j];
				return 1;
			}
			bool term=1;
			for (int i=1;i<=P;++i){
				if (off(i)) continue;
				if (available(i)){
					term=0;
					for (int j=1;j<=R;++j){
						r[j]-=p[i][j];p[i][j]=0;r[j]+=pp[i][j];
					}
					break;
				}
			}
			if (term){
				rep(i,305) rep(j,305) p[i][j]=p1[i][j];
				rep(j,305) r[j]=r1[j];
				return 0;
			}
		}
		
	}
	state operator = (const state& st){
		rep(i,305) rep(j,305) p[i][j]=st.p[i][j];
		rep(j,305) r[j]=st.r[j];
		return *this;
	}
};

int p_[200005],r_[200005];
map<int,state> m;
map<int,state>::iterator it;
int main(){
	std::ios::sync_with_stdio(false);
	cin>>P>>R>>T;
	for (int i=1;i<=R;++i){
		cin>>rr[i];m[0].r[i]=rr[i];
	}
	for (int i=1;i<=P;++i) for (int j=1;j<=R;++j){
		cin>>pp[i][j];m[0].p[i][j]=pp[i][j];
	}
	m[T]=m[0];
	for (int i=1;i<=T;++i){
		cin>>p_[i]>>r_[i];
		--m[T].p[p_[i]][r_[i]];
		--m[T].r[r_[i]];
	}
	for (int i=1;i<=P;++i) if (m[0].on(i)&&m[T].off(i)) m[T].release(i);
	if (m[T].judge()){
		cout<<-1<<endl;return 0;
	}
	if (!m[0].judge()){
		cout<<0<<endl;return 0;
	}
	int l=0,r=T;// l can, r can't
	while(r-l>1){
		int t=(l+r)/2;
		m[t]=m[l];
		for (int i=l+1;i<=t;++i){
			--m[t].p[p_[i]][r_[i]];
			--m[t].r[r_[i]];
		}
		for (int i=1;i<=P;++i) if (m[l].on(i)&&m[t].off(i)) m[t].release(i);
		if (m[t].judge()) l=t;
		else r=t;
	}
	cout<<r<<endl;
	return 0;
}


Measured memory_bytes: 12516
#include "bits/stdc++.h"
using namespace std;

// GNU C Compiler
//template<class T> inline string toString(T x) { ostringstream sout; sout << x; return sout.str(); }

// type
using ll = int_fast64_t;
using ull = uint_fast64_t;
using LL = long long;
using ULL = unsigned long long;
using PII = pair<int, int>;
//using pair<T1, T2> = p12;

//container
#define PB emplace_back
#define MP make_pair 
#define SZ(a) int((a).size())
#define ALL(v) v.begin(),v.end()

//repetition
#define REP(n) for(ll i=0; i<(n); i++)
#define REPj(n) for(ll j=0; j<(n); j++)
#define REPinit(i,a,n) for(ll i=(a); i<(n); i++)
#define REPinitj(j,a,n) for(ll j=(a); j<(n); j++)

//algorithm
#define SORT(c) sort((c).begin(),(c).end())
#define CONTAINER_ALL(a) a.begin(),a.end()

//constant

//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))

//Optimizer
// #pragma GCC optimize("Ofast")
// #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")


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

    int N, M;
    cin >> N >> M;

    vector<int> q(M, 0);
    int ans = 0;

    int K, A;
    REPinit(i, 0, N) {
        cin >> K;
        REPinit(j, 0, K) {
            cin >> A;
            q[A - 1]++;
        }
    }

    REPinit(i, 0, M) {
        if (q[i] == N) ans++;
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 3608
package main

import (
	"bufio"
	"errors"
	"fmt"
	"io"
	"math"
	"os"
	"sort"
	"strconv"
)

func main() {
	sc := NewScanner(os.Stdin)
	n, _ := sc.NextInt()
	a, _ := sc.NextInts(n)
	fmt.Println(solve(n, a))
}

func solve(n int, a []int) (ans int) {
	count := make(map[int]int, n)
	divisible := make(map[int]bool, n)
	for _, ai := range a {
		count[ai]++
		divisible[ai] = false
	}

	sort.Ints(a)
	max := a[n-1]
	for _, ai := range a {
		if divisible[ai] {
			continue
		}
		for j := 2 * ai; j <= max; j += ai {
			if _, ok := divisible[j]; ok {
				divisible[j] = true
			}
		}
		if count[ai] == 1 {
			ans++
		}
	}
	return
}

// Scanner is a wrapper of bufio.Scanner which is customized for competitive programing.
type Scanner struct {
	bufio.Scanner
}

// NewScanner is a constructor for Scanner.
func NewScanner(r io.Reader) *Scanner {
	sc := Scanner{*bufio.NewScanner(r)}
	sc.Buffer([]byte{}, math.MaxInt64)
	sc.Split(bufio.ScanWords)
	return &sc
}

// NextInt reads a integer from io stream.
func (sc *Scanner) NextInt() (int, error) {
	if !sc.Scan() {
		return -1, errors.New("failed to scan")
	}
	return strconv.Atoi(sc.Text())
}

// NextInts reads n integers from io stream.
func (sc *Scanner) NextInts(n int) (arr []int, e error) {
	arr = make([]int, n)
	for i := 0; i < n; i++ {
		v, e := sc.NextInt()
		if e != nil {
			return nil, e
		}
		arr[i] = v
	}
	return arr, nil
}


Measured memory_bytes: 13340
#include <iostream>
#include <fstream>
#include <bitset>
using namespace std;
const int nmax=2005;
bitset<nmax*nmax> b[2];
int a,s,i,x,n,use;
int main()
{
    cin>>n;
    b[0][0]=1;
    for(i=1;i<=n;i++)
    {
        cin>>a;
        s+=a;
        use=1-use;
        b[use]=(b[1-use]|(b[1-use]<<a));
    }
    x=(s+1)/2;
    while(b[use][x]==0)
       x++;
    cout<<x;
    return 0;
}

Measured memory_bytes: 2816
# include <bits/stdc++.h>
typedef long long lint;
using namespace std;

lint gcd(lint x, lint y) {
  if(x == 0) { return y; }
  else { return gcd(y%x,x); }
}

lint lcm(lint x, lint y) { return abs(x-y)/gcd(x,y); }


int main() {
  lint n,k; cin >> n >> k;
  vector<lint> a(n,0);
  lint index;

  for(lint i=0;i<n;i++) {
    cin >> a[i];
    if(a[i] == 1) { index = i; }
  }

  lint ans=0;
  ans = (n-1)/(k-1);
  if( (n-1)%(k-1) > 0 ) { ans += 1; }

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

Measured memory_bytes: 1024
package main

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

var reader = bufio.NewReaderSize(os.Stdin, 1000000)
var writer = bufio.NewWriter(os.Stdout)
func NextLine() string {
  buffer := make([]byte, 0)
  for true {
    line, isPrefix, err := reader.ReadLine()
    if err != nil { panic(err) }
    buffer = append(buffer, line...)
    if !isPrefix { break }
  }
  return string(buffer)
}
func NextInt() int {
  n, _ := strconv.Atoi(NextLine())
  return n
}
func NextIntVec() []int {
  L := strings.Split(NextLine(), " ")
  N := make([]int, len(L))
  for i := range N {
    N[i], _ = strconv.Atoi(L[i])
  }
  return N
}
func Write(s interface{}) {
  fmt.Fprintln(writer, s)
}
func Output() {
  _ = writer.Flush()
}

func MinInt(A ...int) int {
  min := A[0]
  for _, a := range A {
    if a < min { min = a }
  }
  return min
}

func Solve() {
  HN := NextIntVec()
  H, N := HN[0], HN[1]
  M := make([][]int, N)
  for i := range M {
    M[i] = NextIntVec()
  }
  DP := make([][]int, N + 1)
  for i := range DP {
    DP[i] = make([]int, H)
    if 0 < i { continue }
    for j := range DP[0] {
      DP[0][j] = 1000000000
    }
  }
  for i, m := range M {
    for j := range DP[i + 1] {
      if j < m[0] {
        DP[i + 1][j] = MinInt(m[1], DP[i][j])
      } else {
        DP[i + 1][j] = MinInt(DP[i + 1][j - m[0]] + m[1], DP[i][j - m[0]] + m[1],  DP[i][j])
      }
    }
  }
  Write(DP[N][H - 1])
  return
}

func main() {
  Solve()
  Output()
}

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

int main() {
    string w;
    cin >> w;
    map<char, int> c;
    for (auto& e : w) c[e]++;
    string ans = "Yes";
    for (auto& e : c) if (e.second % 2 == 1) ans = "No";
    cout << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0;i<n;i++)
using namespace std;
template<class T>bool chmax(T &a, const T &b) { if (b>a) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
const long long INF = 2LL << 60;
using ll = long long;
using P = pair<ll, ll>;

int main(int argc, char const *argv[]) {
    double L;
    cin >> L;
    printf("%lf", L*L*L/27.0);
    return 0;
}


Measured memory_bytes: 256
object Main {
  import java.util.Scanner

  implicit class RichScanner(sc: Scanner) {
    def readInts(n: Int): Array[Int] = Array.fill(n) { sc.nextInt() }
  }

  def main(args: Array[String]): Unit = solve(new Scanner(System.in))

  def solve(sc: Scanner): Unit = {
    val Array(n, m, q) = sc.readInts(3)
    val LR = Array.fill(m)(sc.readInts(2))
    val Q = Array.fill(q)(sc.readInts(2))

    val mutableIntervals: Array[Array[Int]] = Array.fill(n)(Array.fill(n)(0))
    LR.foreach { case Array(l, r) => mutableIntervals(l - 1)(r - 1) += 1 }
    val summedInterval = mutableIntervals.map(_.scan(0)(_+_)).transpose.map(_.scan(0)(_+_)).transpose

    Q.foreach { case Array(l, r) =>
      println(summedInterval(r)(r) - summedInterval(l - 1)(r) - summedInterval(r)(l - 1) + summedInterval(l - 1)(l - 1))
    }
  }
}


Measured memory_bytes: 130552
#include<iostream>
using namespace std;
 
int main(){
    int a, b;
    for(int i=0; i>=0; i++){
        cin >> a >> b;
        if(a==0 && b==0) break;
        for(int j=0; j<a; j++){
            for(int k=0; k<b; k++){
                cout << "#";
            }
            cout << endl;
        }
        cout << endl;
    }
    return 0;
}

Measured memory_bytes: 1152
import java.util.*;
import java.lang.*;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String s = sc.next();
		int zero = 0;
		int one = 0;
		for (int i = 0; i < s.length(); i++) {
			if (s.charAt(i) == '0') {
				zero++;
			} else if (s.charAt(i) == '1') {
				one++;
			}
		}
		System.out.println(s.length() - Math.abs(zero - one));
 	}
}

Measured memory_bytes: 25044
fun main(args: Array<String>) {
    val line = readLine()!!.split(" ").map { it.toInt()}
    val k = line[0]
    val s = line[1]

    var result = 0
    for (x in 0..k) {
        for (y in 0..k) {
            if (x + y <= s && s <= x + y + k) {
                result += 1
            }
        }
    }

    print(result)
}

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

int main(){
    long long a,b,n,shuki=0,ans=0;
    cin >> a >> b >> n;
    shuki = b;
    //shuki = b/(__gcd(a,b));
    //shuki = shuki * b / (__gcd(shuki,b));
    //cout << shuki << endl;
    if(n>=shuki)n = shuki-1;
    ans = (a*n/b) - a*(n/b);
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3632
#include<bits/stdc++.h>
#define ll  long long int
#define fr(i,n) for(ll i=0; i<n; i++)
#define fre(i,n) for(ll i=1; i<=n; i++)
#define pb push_back
#define mp(i,j) make_pair(i,j)
#define fi first
#define se second
#define pii pair<ll,ll>
#define ve vector
#define piii pair<pii, ll>
#define FAST ios_base::sync_with_stdio(0); cin.tie(NULL); cout.tie(NULL);
using namespace std;


int main()
{  
    FAST;
    int n, k;
    cin>>n>>k;

    long long int cost[n], a[n];

    fr(i, n) cin>>a[i];
    cost[0] = 0;

    for(int i=1; i<n; i++){
        long long int x = LONG_MAX;
        for(int t=1; t<=k; t++ ){
            if(i-t<0)break;
            x= min(x, abs(a[i]-a[i-t])+ cost[i-t]);
        }
        cost[i] = x;
    }
    cout<<cost[n-1]<<endl;
}


Measured memory_bytes: 1792
N = int(input())
xs = list(map(int,input().split()))
sortxs = [i for i in xs]
sortxs.sort()
mins = sortxs[N//2-1]
majs = sortxs[N//2]
for i in range(N):
    t = xs[i]
    if t <= mins:
        print(majs)
    else:
        print(mins)


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

int main(){
  ll h, w;
  cin >> h >> w;
  if(h % 3 == 0 || w % 3 == 0){
    cout << "0" << endl;
    return 0;
  }
  ll ans = min(h, w);
  for(ll i = 1; i < h; i++){
    if(w % 2 == 0) ans = min(ans, abs(i*w - (h-i)*w/2));
    else {
      ll a = w*i, b = (h-i)*(w/2), c = (h-i)*(w/2+1);
      ans = min(ans, max(abs(a-b), max(abs(b-c), abs(c-a))));
    }
  }
  for(ll i = 1; i < w; i++){
    if(h % 2 == 0) ans = min(ans, abs(i*h - (w-i)*h/2));
    else {
      ll a = h*i, b = (w-i)*(h/2), c = (w-i)*(h/2+1);
      ans = min(ans, max(abs(a-b), max(abs(b-c), abs(c-a))));
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
package main

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

var sc, wr = bufio.NewScanner(os.Stdin), bufio.NewWriter(os.Stdout)

func scanString() string   { sc.Scan(); return sc.Text() }
func scanRunes() []rune    { return []rune(scanString()) }
func scanInt() int         { a, _ := strconv.Atoi(scanString()); return a }
func scanInt64() int64     { a, _ := strconv.ParseInt(scanString(), 10, 64); return a }
func scanFloat64() float64 { a, _ := strconv.ParseFloat(scanString(), 64); return a }

func scanInts(n int) []int {
	res := make([]int, n)
	for i := 0; i < n; i++ {
		res[i] = scanInt()
	}
	return res
}

func debug(a ...interface{}) { fmt.Fprintln(os.Stderr, a...) }

func abs(a int) int {
	if a < 0 {
		return -a
	}
	return a
}
func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}
func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}

//•*¨*•.¸¸♪main•*¨*•.¸¸♪(　-ω-)ノ　(　・ω・)
func main() {
	defer wr.Flush()
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, 10000), 1001001)

	n := scanInt()
	a := scanInts(n)
	b := scanInts(n)

	arr := make([]int, n*3)

	for i := 0; i < n*2-1; i++ {
		arr[n+i] = a[i%n] ^ a[(i+1)%n]
	}
	for i := 0; i < n-1; i++ {
		arr[i] = b[i] ^ b[i+1]
	}
	arr[n-1] = -1
	memo := zalgorithm(arr)[n : n+n]

	for i := 0; i < n; i++ {
		if memo[i] == n-1 {
			fmt.Fprintln(wr, i, b[0]^a[i])
		}
	}

}

func zalgorithm(s []int) []int {
	n := len(s)
	res := make([]int, n)
	i, j := 1, 0
	res[0] = n
	for i < n {
		for i+j < n && s[j] == s[i+j] {
			j++
		}
		res[i] = j
		if j == 0 {
			i++
			continue
		}
		k := 1
		for i+k < n && k+res[k] < j {
			res[i+k] = res[k]
			k++
		}
		i += k
		j -= k
	}
	return res
}


Measured memory_bytes: 20060
#define _GLIBCXX_DEBUG//TLEの原因になるので注意！！！！！！！！！！！
#include<cmath>
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
vector<int> arr;
stack<int> st;
queue<int> qu;
queue<pair<int,int> > qu2;
priority_queue<int> pq;
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define rep2(i,n) for(int i=1; i<=(int)(n); i++)
#define mins(x,y) x=min(x,y)
#define maxs(x,y) x=max(x,y)
typedef set<int> set_t;
typedef set<string> set_g;
typedef complex<double> xy_t;
static const int NIL = -1;
static const int INF = 1000000007;
#define mp make_pair
#define sz(x) int(x.xise())

/*int P[10010];
void init(int n){//Union-find
    for(int i=0;i<n;++i)P[i]=i;
}
int root(int a) {
    if(P[a]==a)return a;
    return (P[a]=root(P[a]));
}
bool is_same_set(int a,int b){
    return root(a) == root(b);//代表元を求める
}
void unite(int a,int b){
    P[root(a)]=root(b);
}//対set,グラフ？
//セグメント木？？
*/

double dot_product(xy_t a, xy_t b) { return (conj(a)*b).real(); }//内積
double cross_product(xy_t a, xy_t b) { return (conj(a)*b).imag(); }//外積
xy_t projection(xy_t p, xy_t b) { return b*dot_product(p,b)/norm(b); }//投影
//対図形

#define mod 1000000007
/*ll f[2001];
//int n,k とかしておく

ll pw(ll x, ll y){//euclidの互除法より
    ll a= 1;
    while(y){
        if(y&1){//奇数なら
            a = a*x%mod;
        }
        x = x*x%mod;
        y /= 2;
    }
    return a;
}

ll modinv(ll x){//逆元を求める
    return pw(x, mod - 2 );
}

ll comb(int n,int r){
    if(n<r){
        return 0;
    }
    return f[n] * modinv(f[r])%mod*modinv(f[n-r])%mod;
}//対combination//ただしfは用意してね
*/

//cerrはコメントアウトしなくても通る

int main(){
    string s;
    cin >> s;
    if(s=="Sunny"){
        cout<<"Cloudy"<<endl;
    }else if(s=="Cloudy"){
        cout<<"Rainy"<<endl;
    }else{
        cout<<"Sunny"<<endl;
    }
    return 0;
}

Measured memory_bytes: 256
import sys
from itertools import accumulate

read = sys.stdin.read

N, K, *p = map(int, read().split())

p = [(1 + i) / 2 for i in p]
p = [0] + p
P = list(accumulate(p))
answer = max(P[i] - P[i - K] for i in range(K, N + 1))

print(answer)


Measured memory_bytes: 25420
fun main(args: Array<String>) {
    val n = readLine()!!.toInt()
    val array = (1..n).map {
        readLine()!!.toInt()
    }

    println(array.asSequence().filter { isPrime(it) }.count())
}

fun isPrime(n: Int): Boolean {
    when (n) {
        0 -> return false
        1 -> return false
        else -> {
            for (i in 2..Math.sqrt(n.toDouble()).toInt())
                if (n % i == 0)
                    return false
            return true
        }
    }
}


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

int main(){
    string N;
    cin >> N;
    
    ll sum = 0;
    int i = 0;
    while( (N[i] >= '0') && (N[i] <= '9') ){
        sum = sum + N[i] - '0';
        i++;
    }
    
    if (sum % 9 == 0){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }

    return 0;
}

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

// 3つの数の整列
int N = 3;

int main() {
  vector<int> vec(N);
  for (int i = 0; i < N; i++) {
    cin >> vec.at(i);
  }

  sort(vec.begin(), vec.end());

  cout << vec[0] << " " << vec[1] << " " << vec[2] << endl;
}


Measured memory_bytes: 3144
#include<algorithm>
#include<bitset>
#include<cassert>
#include<cfloat>
#include<climits>
#include<cmath>
#include<deque>
#include<functional>
#include<iomanip>
#include<iostream>
#include<map>
#include<queue>
#include<set>
#include<stack>
#include<string>
#include<unordered_map>
#include<unordered_set>
#include<utility>
#include<vector>

using namespace std;

using lint = long long;
using P = pair<int, int>;
using LLP = pair<long long, long long>;

#define REP(i, x, n) for(int i = (x), i##_len = (int)(n) ; i < i##_len ; ++i)
#define rep(i, n) for(int i = 0, i##_len = (int)(n) ; i < i##_len ; ++i)
#define reps(i, n) for(int i = 1, i##_len = (int)(n) ; i <= i##_len ; ++i)
#define rrep(i, n) for(int i = (int)(n) - 1 ; i >= 0 ; --i)
#define rreps(i, n) for(int i = (int)(n) ; i > 0 ; --i)
#define SORT(x) sort((x).begin(), (x).end())
#define SORT_INV(x) sort((x).rbegin(), (x).rend())
#define REVERSE(x) reverse((x).begin(), (x).end())
#define TWINS(x) cout << ((x) ? "Yay!" : ":(") << '\n'
#define endl '\n'

constexpr int IINF = (1 << 30) - 1;
constexpr long long LLINF = 1LL << 61;
constexpr double EPS = 1e-10;

constexpr int dx4[] = {1, 0, -1, 0}, dy4[] = {0, 1, 0, -1};
constexpr int dx8[] = {1, 1, 0, -1, -1, -1, 0, 1}, dy8[] = {0, -1, -1, -1, 0, 1, 1, 1};

struct edge{
    int to, cost;
};

struct node{
    int id, cost;

    bool operator<(const node& rhs) const {
        return cost > rhs.cost;
    }
};

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

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

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

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

    vector< vector<edge> > g(n);
    rep(i, m){
        int a, b, c;
        cin >> a >> b >> c;
        g[--a].push_back({--b, c});
    }

    vector<int> cost(n, IINF);
    cost[0] = 0;
    priority_queue<node> que;
    que.push({0, 0});

    int ans = -1;

    while(!que.empty()){
        node now = que.top();
        que.pop();
        if(cost[now.id] < now.cost){
            continue;
        }
        for(auto e : g[now.id]){
            if(now.cost > e.cost){
                continue;
            }
            if(e.to == n - 1){
                chmax(ans, e.cost);
            }else if(chmin(cost[e.to], e.cost)){
                que.push({e.to, e.cost});
            }
        }
    }

    cout << ans << endl;

    cout << flush;

    return 0;
}


Measured memory_bytes: 8624
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
     
using namespace std;
     
typedef long long ll;
typedef pair<int, int> pii;
     
#define fi first
#define se second
#define mp make_pair
#define fastIO ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
     
mt19937 rnd(chrono::steady_clock().now().time_since_epoch().count());
     
int main(){
    fastIO;
    int n, c, k;
    cin >> n >> c >> k;
    int t[n];
    for(int i = 0 ; i < n; i ++ )
        cin >> t[i];
    sort(t,t + n);
    int L, R;
    int p = 0;
    int cnt;
    int res = 0;
    while(p < n){
        L = t[p];
        R = L + k;
        cnt = 1;
        res ++ ;
        while(cnt <= c && p < n && t[p] <= R){
            cnt ++ ;
            p ++ ;
        }
    }
    cout << res;
    return 0;
}

Measured memory_bytes: 640
s = input()
def is_one_char(str):
    if len(set([c for c in str])) == 1:
        return True
    else:
        return False

candidate = set([c for c in s])
counts = []
for alpha in candidate:
    newstr = ""
    oldstr = s
    flag = is_one_char(oldstr)
    count = 0
    while(not flag):
        for i in range(len(oldstr) - 1):
            if oldstr[i] == alpha or oldstr[i+1] == alpha:
                newstr += alpha
            else:
                newstr += oldstr[i]
        flag = is_one_char(newstr)
        count = len(s) - len(newstr)
        oldstr = newstr
        newstr = ""
    counts.append(count)
print(min(counts))
    
        
        


Measured memory_bytes: 3064
#pragma GCC optimize("Ofast","inline","-ffast-math")
#pragma GCC target("avx,sse2,sse3,sse4,mmx")
#include <bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/hash_policy.hpp>
using namespace __gnu_pbds;
using namespace std;

inline bool check(string x)
{
	for(int i=0;i<x.size()/2;i++) if(x[i]!=x[x.size()-i-1]) return false;
	return true;	
} 

signed main()
{
	ios::sync_with_stdio(false);
	string s;
	cin>>s;
	string s1=s.substr(0,(s.size()-1)/2),s2=s.substr((s.size()+1)/2);
	if(check(s)&&check(s1)&&check(s2)) cout<<"Yes"<<endl;
	else cout<<"No"<<endl; 
	return 0;
}

Measured memory_bytes: 256
/*input
1 100 2 10
*/
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace std;
using namespace __gnu_pbds;
#define REP(i,j,k)     for(int i = j ; i < k ; ++i)
#define RREP(i,j,k)    for(int i = j ; i >=k ; --i)
#define A    first
#define B    second
#define mp   make_pair
#define pb   emplace_back
#define PII pair<int , int>
#define MEM(i,j)   memset(i , j , sizeof i)
#define ALL(i)     i.begin() , i.end()
#define DBGG(i,j)     cout << i << " " << j << endl
#define DB4(i,j,k,l)  cout << i << " " << j << " " << k << " " << l << endl
#define IOS cin.tie(0) , cout.sync_with_stdio(0)
#define endl "\n"
///------------------------------------------------------------
#define MAX 
#define INF 0x3f3f3f3f

int a , b , c , d;
int32_t main(){
	IOS;
	cin >> a >> b >> c >> d;
	int v1 = (abs(a - b) <= d);
	int v2 = (abs(b - c) <= d);
	int v3 = (abs(a - c) <= d);
	if((v1 && v2) || v3) cout << "Yes" << endl;
	else cout << "No" << endl;
    return 0;
}

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

#define LL long int


int main(){
    int n;cin >> n;
    vector<int> v(n);

    int max1 = -1,max2 = -1;

    for(int i = 0; i < n; ++i){
        cin >> v[i];

        if(max1 < v[i]){
            max2 = max1;
            max1 = v[i];
        }else if(max2 < v[i]){
            max2 = v[i];
        }
    }

    for(int i = 0; i < n; ++i){
        if(max1 != v[i]){
            cout << max1 << endl;
        }else{
            cout << max2 << endl;
        }
    }

    return 0;
}

Measured memory_bytes: 2432
#include "bits/stdc++.h"
 
typedef long long ll;
#define int ll
#define fi first
#define se second
#define SORT(a) sort(a.begin(),a.end())
#define rep(i,n) for(int i = 0;i < (n) ; i++) 
#define REP(i,n) for(int i = 0;i < (n) ; i++) 
#define MP(a,b) make_pair(a,b)
#define pb(a) push_back(a)
#define INF LLONG_MAX/2

using namespace std;

int MOD = 1000000007;
int ans = 0;
int h,w,a,b;


ll bitpow(ll x,ll n){
    ll ans = 1;
    while(n > 0){
        if(n%2 == 1) ans = ans * x % MOD;
        x = x * x %MOD;
        n = n >> 1;
    }
    return ans;
}

int N = 200010;
int fac[200011];
int inv[200011];



int wb[100001] = {0};

signed main(){
    cin >> h >> w >> a >> b;
    fac[0] = 1;
    inv[0] = 1;
    for(int i = 1;i <= N;i++){
        fac[i] = fac[i-1]*i%MOD;
        inv[i] = bitpow(fac[i],MOD-2)%MOD;
    }

    rep(i,w-b){
        wb[i] = fac[b+i+1+h-a-2]%MOD*inv[h-a-1]%MOD*inv[b+i]%MOD;
    }

    rep(i,w-b){
        ans += wb[i]*fac[a+w-b-i-2]%MOD*inv[a-1]%MOD*inv[w-b-i-1]%MOD;
        ans %= MOD;
    }

    cout << ans << endl;
    return 0;
}
// g++ -std=c++14 code1.cpp
// rm -r -f test;oj dl 

Measured memory_bytes: 4096
#include <stdio.h>
int main(){

  int a,b,c,x;
  scanf("%d %d %d",&a,&b,&c);
  if(a > b){
    x = a;
  a = b;
  b = x;
  } 
  if(b > c){
    x = b;
  b = c;
  c = x;
  }
  if(a > b){
    x = a;
  a = b;
  b = x;
  }
  printf("%d %d %d\n",a,b,c);
  return 0;
}

Measured memory_bytes: 596
#include <bits/stdc++.h>
using namespace std;
#define mp(a,b) make_pair(a,b)
#define ff first
#define setp(a) setprecision(a)<<fixed
#define ss second
#define fori(v) for(ll i=0; i<v; i++)
#define forj(v) for(ll j=0; j<v; j++)
#define fork(v) for(ll k=0; k<v; k++)
#define forl(v) for(ll l=0; l<v; l++)
#define fort(v) for(ll t=0; t<v; t++)
#define forz(v) for(ll z=0; z<v; z++)
#define forx(v) for(ll x=0; x<v; x++)
#define fory(v) for(ll y=0; y<v; y++)
#define ll long long 
#define double long double
#define MAX (int)(pow(10,4) + 10)
#define pb(a) push_back(a)
const ll INF = 0x3f3f3f3f;
const ll inf = pow(10,18);
ll modulo = pow(10,9)+7;

bool J(vector<ll>& a, vector<ll>& b){
	return a[0] + a[1] < b[0] + b[1];
}





void deal(){
	ll n ;
	cin>>n;
	vector<vector<ll> > all;
	vector<ll> dp(MAX,0);
	fori(n){
		ll w,s, v;
		cin>>w>>s>>v;
		all.pb(vector<ll>({w,s,v}));
	}
	sort(all.begin(), all.end(), J);
	ll mx =  0;
	for(auto el : all){
		ll w = el[0], s = el[1], v = el[2];
		for(ll i = s; i>-1; i--){
			mx = max( mx, dp[i] + v);
			if(i+w <MAX)
				dp[i+w] = max(dp[i+w], dp[i] + v);
		}
	}
	cout<<mx;
}



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























Measured memory_bytes: 384
#include<iostream>
#include<fstream>
#include<stdio.h>
#include<string>
#include<vector>
#include<map>
#include<math.h>
#include<algorithm>
#include<iomanip>
#include<set>
#include<utility>

using namespace std;



class Increase {
public:
  long long n, flowMax = 10000000000;
  vector<vector<long long>> p;
  vector<int> parent;
  Increase(int _n, vector<vector<long long>> _p) {
    n = _n;
    p = _p;
    parent.resize(n);
  }
  long long dfs(int id, int from, long long flow) {
    if(parent[id] != id) return 0;
    parent[id] = from;
    if(id == n - 1) return flow;
    for(int i = 0; i < n; i++) if(p[id][i] > 0) {
      int next = dfs(i, id, min(flow, p[id][i]));
      if(next > 0) return next;
    }
    return 0;
  }
  long long solve() {
    long long ret = 0, flow;
    for(int i = 0; i < n; i++) parent[i] = i;

    while((flow = dfs(0, -1, flowMax)) > 0) {
      int now = n - 1;
      ret += flow;
      while(parent[now] >= 0) {
        p[parent[now]][now] -= flow;
        p[now][parent[now]] += flow;
        now = parent[now];
      }
      for(int i = 0; i < n; i++) parent[i] = i;
    }
    return ret;
  }
};


int main() {
  int n;
  cin >> n;
  vector<long long> a(n);
  for(int i = 0; i < n; i++) cin >> a[i];
  long long sum = 0;
  for(int i = 0; i < n; i++) if(a[i] > 0) sum += a[i];
  vector<vector<long long>> p(n + 2);
  for(int i = 0; i < n + 2; i++) p[i].resize(n + 2);
  for(int i = 0; i < n; i++) {
    if(a[i] <= 0) p[0][i + 1] = -a[i];
    else p[i + 1][n + 1] = a[i];
  }
  for(int i = 1; i < n + 1; i++) {
    for(int j = 2 * i; j < n + 1; j += i) p[i][j] = 10000000000;
  }

  Increase inc(n + 2, p);
  cout << sum - inc.solve() << endl;

  return 0;
}


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

#define REP(i,num) for(int i=0;i<(num);++i)
#define ALL(c) c.begin(),c.end()
#define PRINTALL(c) for(auto& x:c){cout<<x<<' ';}cout<<endl;
#define PAIRCOMP(c,comp) [](const pair<ll,ll>& lhs,const pair<ll,ll>& rhs){return lhs.c comp rhs.c;}

constexpr int atcoder_mod = 1e9+7;

using namespace std;
using ll = long long;

template<typename T=int>
T in(){T x; cin >> x; return (x);}
template<typename T=int,typename C=vector<T>>
C vecin(int N){C x(N);REP(i,N){x[i]=in<T>();}return move(x);}

void vout(){cout << endl;}
template<typename Head,typename... Tail>
void vout(Head&& h,Tail&&... t){cout << ' ' << h;vout(forward<Tail>(t)...);}
void out(){cout << endl;}
template<typename Head,typename... Tail>
void out(Head&& h,Tail&&... t){cout << h;vout(forward<Tail>(t)...);}

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

	int N=in();
	list<int> L;
	
	REP(i,N){
		string s = in<string>();
		if(s=="insert"){
			int v = in();
			L.push_front(v);
		}
		else if(s=="deleteFirst"){
			L.pop_front();
		}
		else if(s=="deleteLast"){
			L.pop_back();
		}
		else{
			int v = in();
			auto res = find(ALL(L),v);
			if(res!=L.end()) L.erase(res);
		}
	}

	int num=0;
	int size=L.size();
	for(auto& x:L){
		cout << x;
		if(num<size-1) cout << ' ';
		else cout << endl;
		num++;
	}

	return 0;
}



Measured memory_bytes: 34384
n=int(input())
c=0
a=list(map(int,input().split()))
for i in range(n):
    m=i
    for j in range(i,n):
        if a[m]>a[j]:m=j
    if i!=m:a[m],a[i]=a[i],a[m];c+=1
print(*a)
print(c)

Measured memory_bytes: 7632
import sys

read = sys.stdin.buffer.read
input = sys.stdin.buffer.readline
inputs = sys.stdin.buffer.readlines

#mod=10**9+7
# rstrip().decode('utf-8')
# map(int,input().split())
#import numpy as np


def main():
	h,n=map(int,input().split())
	A=list(map(int,input().split()))
	ans="Yes"
	
	if h>sum(A):
		ans="No"
	
	print(ans)
	
	

if __name__ == "__main__":
	main()


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

int binarySearch(int n, int s[], int t) {
	int i = 0;
	int j = n - 1;
	while (i <= j) {
		int mid = i + (j - i) / 2;
		if (s[mid] == t) {
			return 1;
		}
		if (s[mid] < t) {
			i = mid + 1;
		}
		else {
			j = mid - 1;
		}
	}
	return 0;
}

int main() {
	int n, q, s[100000], t, ans = 0;
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> s[i];
	}
	cin >> q;
	for (int i = 0; i < q;i++) {
		cin >> t;
		ans += binarySearch(n, s, t);
	}
	cout << ans << endl;
	return 0;
}


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

#define vi vector<int>
#define vl vector<long>
#define vvi vector<vector<int>>
#define vvl vector<vector<long>>
#define pint pair<int, int>
#define plong pair<long, long>

int main() {
    double n, m, d;
    cin>>n>>m>>d;
    double ans = 0;
    if(d == 0) ans = (m-1)/n;
    else ans = (m-1)* 2*(n-d)/(n*n);
    cout << setprecision(10) << ans << endl;
}

Measured memory_bytes: 256
using System;

class Program {
  static void Main() {
    int n = int.Parse(Console.ReadLine());
    int k = int.Parse(Console.ReadLine());
    int x = int.Parse(Console.ReadLine());
    int y = int.Parse(Console.ReadLine());
    if (n <= k) {
      Console.WriteLine(x * n);
    } else {
      Console.WriteLine(x * k + y * (n - k));
    }
  }
}

Measured memory_bytes: 11092
#include <iostream>

int main() {
	int x, y;
	std::cin >> x >> y;
	if(y & 1)
		std::cout << "No";
	else if((x << 1) > y)
		std::cout << "No";
	else if((x << 2) < y)
		std::cout << "No";
	else
		std::cout << "Yes";
	return 0;
}

Measured memory_bytes: 3636
#include <bits/stdc++.h>
    using namespace std;
    typedef long long lint;
    typedef pair<int,int> pint;
    typedef vector<int> vint;
    #define rep(i, n) for(int i = 0; i < n; i++)
    #define rep2(elem, vec) for(auto elem: vec)
    #define SORT(V) sort((V).begin(),(V).end())
    #define RSORT(V) sort((V).rbegin(), (V).rend())
    lint gcd(int a,int b){return b?gcd(b,a%b):a;}
    lint lcm(int a,int b){return a*b/gcd(a,b);}
    lint comb(int a,int b){return b?comb(a-1,b-1)*a/b:1;}
    int dx[4] ={1,0,-1,0},dy[4] = {0,1,0,-1};
    int MOD = 1e9+7;

int main(){
    lint N,K;
    cin >> N >> K;
    vint H(N);
    rep(i,N)cin >> H[i];
    SORT(H);
    lint S = 0;
    rep(i,K)if(!H.empty())H.pop_back();
    rep2(j,H)S+=j;
    cout << S;
    return 0;
}

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

#define ar array
#define ff first
#define ss second
#define eb emplace_back
#define mp make_pair
#define pb push_back
#define ppb pop_back
#define all(a) a.begin(), a.end()
#define f0(i, n) for(int i = 0; i < n; ++i)
#define fo(i, k, n) for(int i = k; i < n; ++i)
#define rf0(n, i) for(int i = n-1; ~i; --i)
#define rfo(n, k, i) for(int i = n-1; i >= k; --i)
#define Im_speed ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0)

typedef long double ld;
typedef long long ll;
typedef unsigned long long ull;

//ifstream f("date.in");
//ofstream g("date.out");

const int nax = 1e9 + 7;
const int mod = 1e9 + 7;
const int inf = (1 << 30);
const ld PI = 3.1415926535897932384626433832795;

int main() {
    Im_speed;

    ll n;
    cin >> n;
    vector<ll> a(n);
    f0(i, n) {
        cin >> a[i];
    }
    ll money = 1000;
    ll stock = 0;
    ll ans = 1000;

    ll index = 1;
    while(index < n) {
        while(index < n && a[index-1] >= a[index])  ++index;
        stock = money / a[index-1];
        money -= stock * a[index-1];
//        cout << a[index-1] << ' ' << stock << ' ' << money << '\n';

        while(index < n && a[index-1] < a[index])  ++index;
        money += stock * a[index-1];
        stock = 0;

        ans = max(ans, money);
        money = ans;
//        cout << a[index-1] << ' ' << stock << ' ' << money << '\n';
    }

    if(a[n-2] >= a[n-1]) {
        money += stock * a[n-1];
        ans = max(ans, money);
    }
    cout << ans;
}


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

int main() {
  int N,T;
  cin >> N >> T;
  vector<int> c(N);
  vector<int> t(N);
  int COST = 9999;
   for (int i = 0; i < N; i++) {
    cin >> c.at(i) >> t.at(i);
     if (t.at(i) <= T)
       COST = min(COST,c.at(i));
   }
  if (COST != 9999)
    cout << COST << endl;
  else 
    cout << "TLE" << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
#define REP(i,s,n) for(int i=s; i<n; ++i)
#define rep(i,n) REP(i,0,n)
#define SORT(c) sort((c).begin(),(c).end())
#define IINF INT_MAX
#define LLINF LLONG_MAX
#define DEBUG false
 
typedef long long ll;
typedef pair<int, int> ii;

int main() {
	
	int n;
	cin >> n;
	map<int, int> mp;
	rep(i, n){
		int tmp;
		cin >> tmp;
		mp[tmp]++;
	}
	
	int ans = n;
	int cnt = 0;
	for(auto it : mp){
		if(it.second >= 2){
			if(it.second % 2 == 0){
				ans -= (it.second - 2);
				cnt++;
			}
			else{
				ans -= (it.second - 1);
			}
		}
		
		//cout << it.second << endl;
	}
	
	ans -= (cnt%2 == 0 ? cnt : cnt + 1);
	
	cout << ans << endl;
	
	return 0;
}

Measured memory_bytes: 4992
//ABC122-C
//Reference: editorial.
#include<iostream>
#include<string.h>
#include<vector>
#include<stdio.h>
using namespace std;

int main(){
  int N,Q;
  string S;
  
  cin>>N>>Q;
  cin>>S;
  vector<int> l,r,t;
  for(int i=0; i<Q; i++){
    int l_temp,r_temp;
    cin >> l_temp >> r_temp;
    l.push_back(l_temp);
    r.push_back(r_temp);
  }
  t.resize(N+1);
  t[0] = 0;
  for(int i=0; i<N; i++){
    int temp = 0;
    if(S[i+1] == 'C' && S[i] == 'A') temp =1;
    t[i+1] = t[i] + temp;
  }
  for(int i=0; i<Q; i++){
    //Note that string starts from index 0, r and l starts from 1
    int result = t[r[i]-1] - t[l[i]-1];
    cout<<result<<endl;
  }
  
  /*TLE
  for(int k=0; k<Q; k++){
    int result=0;
    for(int i = l[k] ;i<r[k]; i++){

      char c1,c2;
      c1= S[i-1];
      c2 = S[i];
   
      if(c1== 'A' &&c2 =='C') result++;
      //cout<<c1<<endl;
    }
    cout<<result<<endl;
  }
  */
}


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

int main(){
    int n;
    cin>>n;
    vector<int> Dp(3,0);
    for(int i=0; i<n; ++i){
        vector<int> A(3), Dp_new(3,0);
        cin>>A[0]>>A[1]>>A[2];
        for(int j=0; j<3; ++j){
            for(int k=0; k<3; ++k){
                if(j!=k) Dp_new[k] = max(Dp_new[k], Dp[j]+A[k]);
            }
        }
        Dp=Dp_new;
    }
    cout<<max(max(Dp[0],Dp[1]),Dp[2])<<"\n";
}

Measured memory_bytes: 3536
#include <bits/stdc++.h>
using longlong=long long;

int main(){
    std::cin.tie(nullptr);std::cin.sync_with_stdio(false);
    int a, b, c;
    std::cin >> a >> b >> c;
    std::cout << std::max({a,b,c})-std::min({a,b,c}) << std::endl;
}

Measured memory_bytes: 256
L, R = map(int, input().split())
ans = 10**20

if R-L < 2019:
    ans = 10**20

    for i in range(L, R):
        n = i % 2019
        for j in range(i+1, R+1):
            ans = min(ans, n * j % 2019)
else:
    ans = 0
print(ans)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
int main(){
  string s;
  cin>>s;
  bool ok=true;
  for(int i=0;i<s.size();i+=2){
    if(s.at(i)=='L'){
      ok = false;
    }
  }
  for(int i=1;i<s.size();i+=2){
    if(s.at(i)=='R'){
      ok = false;
    }
  }
  if(ok){
    cout<<"Yes"<<endl;
  }
  else{
    cout<<"No"<<endl;
  }
  return 0;
}


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

#define watch(x) cerr << (#x) << ": " << (x) << endl
#define int long long

const int mod = 1000000007;
const int lmod = 13;

void add(vector<vector<int>>& dp, int i, int num) {
    for(int index = 0; index < lmod; ++index) {
        int nxt = (index+num)%lmod;
        dp[i+1][nxt] += dp[i][index];
        dp[i+1][nxt] %= mod;
    }
}

int32_t main() {

    string s; cin >> s;
    int n = s.length();
    reverse(s.begin(), s.end());
    vector<vector<int>> dp(n+1, vector<int>(lmod, 0));
    dp[0][0] = 1;

    int cur = 1;
    
    for(int i = 0; i < n; ++i) {
        char c = s[i];
        if(c == '?') {
            for(int dig = 0; dig < 10; ++dig) {
                int num = (cur*dig)%lmod;
                add(dp, i, num);
            }
        } else {
            int dig = c-'0';
            int num = (cur*dig)%mod;
            add(dp, i, num);
        }
        cur = (cur*10)%lmod;
    }

    cout << dp[n][5] << endl;
    
    return 0;
}


Measured memory_bytes: 13696
(defvar char-list 
        (loop :as char 
              :across (read-line)
              :collect char))
(defvar tale (last char-list))
(defvar qs (read))
(defvar reversep nil)

(defun enqueue (N)
  (rplacd tale (list N))
  (setf tale (cdr tale)))

(defun add-char (end-p char)
  (if (or (and reversep end-p)
          (and (null reversep)
               (null end-p)))
      (push char char-list)
      (enqueue char)))

(defun do-query (q)
  (case q
    (1 (setf reversep (not reversep)))
    (2 (add-char (= 2 (read)) (read-char)))))

  (loop :repeat qs :do (do-query (read)))
  (format t "~{~A~^~}" (if reversep (reverse char-list) char-list))

Measured memory_bytes: 66176
#include<bits/stdc++.h>
using namespace std;
int main(){
  stack<int> n;
  int a,b;
  char c[100];
  while(scanf("%s",c) != EOF){
    if(c[0]=='+'){
      a=n.top();
      n.pop();
      b=n.top();
      n.pop();
      n.push(a+b);
    }else if(c[0]=='-'){
      a=n.top();
      n.pop();
      b=n.top();
      n.pop();
      n.push(b-a);
    }else if(c[0]=='*'){
      a=n.top();
      n.pop();
      b=n.top();
      n.pop();
      n.push(a*b);
    }else{
      n.push(atoi(c));
    }
  }
  cout<<n.top()<<endl;
  return 0;
  }



Measured memory_bytes: 3164
#全然わからん
a, b, c = map(int, input().split())

m = max(a, b, c)
ans = 0
if 3 * m % 2 == (a + b + c) % 2 :
    ans = (3 * m - (a + b + c)) // 2
else:
    ans = (3 * (m + 1) - (a + b + c)) // 2
print(ans)

Measured memory_bytes: 3060
#include <stdio.h>

char map[18][18];

void bomb(int x, int y)
{
	int i;
	
	map[y][x] = '0';
	for (i = -3; i <= 3; i++){
		if (0 <= x + i && map[y][x + i] == '1' && x + i < 8){
			bomb(x + i, y);
		}
		if (0 <= y + i && map[y + i][x] == '1' && y + i < 8){
			bomb(x, y + i);
		}
	}
}

int main(void)
{
	int n, x, y;
	int i, j;
	
	scanf("%d", &n);
	for (i = 0; i < n; i++){
		for (j = 0; j < 8; j++){
			scanf("%s", map[j]);
		}
		
		scanf("%d %d", &x, &y);
		bomb(x - 1, y - 1);
		
		printf("Data %d:\n", i + 1);
		
		for (j = 0; j < 8; j++){
			printf("%s\n", map[j]);
		}
	}
	return (0);
}

Measured memory_bytes: 608
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vll>;
using vc = vector<char>;
using vvc = vector<vc>;
using pll = pair<ll, ll>;
using vpll = vector<pll>;
const ll INF = 1LL << 60;
const ll MOD = 1e9 + 7;
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define debug(x) cerr << #x << ": " << x << endl;
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;}

int main() {
    ll N, M; cin >> N >> M;
    ll tot = 0;
    rep(i, M) {
        ll a;
        cin >> a;
        tot += a;
    }

    if(tot <= N) cout << N - tot << endl;
    else cout << -1 << endl;
}


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

#define ll long long
#define fw(p) for(int w=0;w<(p);w++)
#define fx(p) for(int x=0;x<(p);x++)
#define fy(p) for(int y=0;y<(p);y++)
#define fz(p) for(int z=0;z<(p);z++)
#define fyg(p,g) for(int y=(g);y<(p);y++)
#define fzg(p,g) for(int z=(g);z<(p);z++)
#define ce(d) cout<<d<<endl;
#define vecp(p) int aa;cin>>aa;(p).push_back(aa);
#define vecpl(p) long long aa;cin>>aa;(p).push_back(aa);
#define vecps(p) string aa;cin>>aa;(p).push_back(aa);
#define vecp2(p) cin>>aa;(p).push_back(aa);
#define vecpl2(p) long long a	b;cin>>ab;(p).push_back(ab);
#define vecps2(p) string ab;cin>>ab;(p).push_back(ab);
#define sorts(c) sort((c).begin(),(c).end());
#define reverses(c) reverse((c).begin(),(c).end());
#define vec(b) vector<int> (b);
#define vecl(b) vector<long long> (b);
#define vecs(b) vector<string> (b);
#define pb(b,a) (b).push_back((a));
#define doublece(a,b) cout<<(a)<<' '<<(b)<<endl;
#define pairs(s) vector<pair<int,int>> (s);
#define pairsp(s) int aa,bb;cin>>aa>>bb;(s).push_back(make_pair(aa,bb));
#define MOD 1000000007
#define cey ce("Yes")
#define cen ce("No")
#define ceY ce("YES")
#define ceN ce("NO")

int main()
{
	int N;
	cin >> N;
	vec(A);
	map<int, int> K;
	fx(N) {
		vecp(A);
		K[A[x]]++;
	}

	sorts(A);
	if (A[0]==A[N-1]) {
		if (A[0]*2<=N||A[0]==N-1) {
			cey;
		}
		else {
			cen;
		}
	}
	else {
		if (A[N-1] - A[0] > 1 || A[N-1]!=A[N-2]) {
			cen;
		}
		else {
			int k = K[A[0]];
			if (N-k>=(A[N-1]-k)*2 && (A[N - 1] - k)>0) {
				cey;
			}
			else {
				cen;
			}
		}
	}
    return 0;
}



Measured memory_bytes: 5368
#include <bits/stdc++.h>
using namespace std;
#define lli long long int
#define rep(i, n) ;for (int i = 0;i < (int)(n);i++)
#define rep2(i, s, n) ;for (int i = s; i < (int)(n);i++)
#define ALL(vec)  (vec).begin(),(vec).end()
#define pi 3.1415926535897932384626433832795
#define MAX_INF 9223372036854775807
#define MIN_INF (922337203685477587+1)
#define sosuu 1000000007



int main() {
  lli X, K, D;
  cin >> X >> K >> D;
  if(abs(X)/D>=K){
  cout << abs(X)-D*K << endl;
    return 0;
  }
  else{
  K-=abs(X)/D;
    X=abs(X)%D;
    if(K%2==0){
    cout << X << endl;
    }
    else{
    cout << abs(X-D) << endl;
    }
  }
}

Measured memory_bytes: 3628
#include<stdio.h>
#include<math.h>
#include<stdlib.h>
#include<string.h>
#define max(x,y)(x>y?x:y)
#define min(x,y)(x>y?y:x)
#define MOD (int)1e9+7
int dx4[]={1,0,-1,0};
int dy4[]={0,-1,0,1};
typedef long long int ll;
typedef unsigned long long int ull;
ll gcd(ll x,ll y){if(!y)return x;return gcd(y,x%y);}
ll lcm(ll x,ll y){return x/gcd(x,y)*y;}
void swap(ll *x,ll *y){ll tmp=*x;*x=*y;*y=tmp;}
int asc_cmp(const void* X,const void* Y){ll x=*(int*)X,y=*(int*)Y;if(x<y)return -1;else if(x==y)return 0;else return 1;}
int desc_cmp(const void* X,const void* Y){ll x=*(int*)X,y=*(int*)Y;if(x<y)return 1;else if(x==y)return 0;else return -1;}
typedef struct pair_{
    int x;
    int y;
}pair_t;

int main(){
    ull h,w;scanf("%llu %llu",&h,&w);
    ull s=h*w;
    if(w==1||h==1){
        printf("1\n");
        return 0;
    }
    if(s%2){
        printf("%llu\n",s/2+1);
    }else{
        printf("%llu\n",s/2);
    }
}

Measured memory_bytes: 128
using System;

namespace AtCoder
{
    class Program
    {
        static void Main()
        {
            long n = long.Parse(Console.ReadLine());
            long[] Luca = new long[n + 1];
            Luca[0] = 2;
            Luca[1] = 1;
            for (int i = 2; i <= n; i++)
            {
                Luca[i] = Luca[i - 1] + Luca[i - 2];
            }
            Console.WriteLine(Luca[n]);
        }
    }
}

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

using namespace std;

int n;
int a[100001];
int main() {
  cin >> n;

  for(int i = 0; i < n; i++) {
    cin >> a[i];
  }
  int i = 0;
  int ans = 0;
  while(i < n) {
    if(i == n - 1) { ans++; break; }
    while(i < n - 1 && a[i] == a[i+1]) i++;
    bool ok = false;
    if(a[i] < a[i+1]) ok = true;
    while(ok && a[i] <= a[i+1]) i++;
    while(!ok && a[i] >= a[i+1]) i++;
    // cout << i <<"   "<<a[i]<<endl;
    ans++;
    i++;
  }
  cout << ans << endl;
}
  


Measured memory_bytes: 768
import std.stdio, std.conv, std.string, std.array, std.math, std.regex, std.range, std.ascii;
import std.typecons, std.functional;
import std.algorithm, std.container;

void main()
{
    long A = scanElem;
    long B = scanElem;
    long cost;
    for(int i =0 ;i < 2;i++)
    {
    if(A<B){
        cost += B;
        B--;
    }else{
        cost += A;
        A--;
    }
    }
    writeln(cost);
}

class UnionFind{
    UnionFind parent = null;

    void merge(UnionFind a)
    {
        if(same(a)) return;
        a.root.parent = this.root;
    }
    UnionFind root()
    {
        if(parent is null)return this;
        return parent = parent.root;
    }
    bool same(UnionFind a)
    {
        return this.root == a.root;
    }
}

void scanValues(TList...)(ref TList list)
{
    auto lit = readln.splitter;
    foreach (ref e; list)
    {
        e = lit.fornt.to!(typeof(e));
        lit.popFront;
    }
}

T[] scanArray(T = long)()
{
    return readln.split.to!(long[]);
}

void scanStructs(T)(ref T[] t, size_t n)
{
    t.length = n;
    foreach (ref e; t)
    {
        auto line = readln.split;
        foreach (i, ref v; e.tupleof)
        {
            v = line[i].to!(typeof(v));
        }
    }
}

T scanElem(T = long)()
{
    char[] res;
    int c = ' ';
    while (isWhite(c) && c != -1)
    {
        c = getchar;
    }
    while (!isWhite(c) && c != -1)
    {
        res ~= cast(char) c;
        c = getchar;
    }
    return res.strip.to!T;
}

template fold(fun...) if (fun.length >= 1)
{
    auto fold(R, S...)(R r, S seed)
    {
        static if (S.length < 2)
        {
            return reduce!fun(seed, r);
        }
        else
        {
            import std.typecons : tuple;

            return reduce!fun(tuple(seed), r);
        }
    }
}

struct Factor
{
    long n;
    long c;
}

Factor[] factors(long n)
{
    Factor[] res;
    for (long i = 2; i ^^ 2 <= n; i++)
    {
        if (n % i != 0)
            continue;

        int c;
        while (n % i == 0)
        {
            n = n / i;
            c++;
        }
        res ~= Factor(i, c);
    }
    if (n != 1)
        res ~= Factor(n, 1);

    return res;
}
long[] primes(long n)
{
    if(n<2)return [];
    auto table = new long[n+1];
    long[] res;
    for(int i = 2;i<=n;i++)
    {
        if(table[i]==-1) continue;
        for(int a = i;a<table.length;a+=i)
        {
            table[a] = -1;
        }
        res ~= i;
    }
    return res;
}
bool isPrime(long n)
{
    if (n <= 1)
        return false;
    if (n == 2)
        return true;
    if (n % 2 == 0)
        return false;
    for (long i = 3; i ^^ 2 <= n; i += 2)
        if (n % i == 0)
            return false;
    return true;
}

Measured memory_bytes: 256