akhauriyash/Code-Regression huggingface dataset:
// 27
#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
#define fors(_, x, n, s) for (int _ = x; _ < n; _ += s)
#define forn(_, x, n) fors(_, x, n, 1)
#define rep(_, n) forn(_, 0, n)
#define forrs(_, x, n, s) for (int _ = x; _ > n; _ -= s)
#define forrn(_, x, n) forrs(_, x, n, 1)
#define rrep(_, n) forrn(_, n - 1, -1)
#define fi first
#define se second
#define pb push_back
#define pairii pair<int, int>
#define all(x) x.begin(), x.end()
#define len(x) int(x.size())
#define lli __int128_t
#define li long long int
#define ld long double
#ifdef LOCAL
#define debug(e) cerr << "\033[48;5;196m\033[38;5;15m" << e << "\033[0m";
#else
#define debug(e)
#endif
// 4
template <class A, class B>
ostream &operator<<(ostream &o, const pair<A, B> &p) {
  return o << "(" << p.fi << " " << p.se << ")";
}
// 8
template <class T>
ostream &operator<<(ostream &o, const vector<T> &v) {
  rep(i, (int)v.size()) o << setw(7) << left << v[i];
  return o << endl;
}
// 5
template <class A, class B>
ostream &operator<<(ostream &o, const map<A, B> &m) {
  for (auto &kv : m) o << kv;
  return o;
}
// 3
void _main(int tc) {
  int n;
  li x;
  cin >> n >> x;
  vector<li> a(n);
  rep(i, n) { cin >> a[i]; }
  li cnt = 0;
  rep(i, n - 1) {
    li diff = a[i] + a[i + 1] - x;
    if (diff > 0) {
      cnt += diff;
      if (a[i + 1] < diff) {
        diff -= a[i + 1];
        a[i + 1] = 0;
      } else {
        a[i + 1] -= diff;
        diff = 0;
      }
      a[i] -= diff;
    }
  }
  debug(a << endl);
  cout << cnt << endl;
}
// 7
int main() {
  ios_base::sync_with_stdio(0), cin.tie(0);
  _main(0), exit(0);
  int tc;
  cin >> tc;
  rep(i, tc) _main(i + 1);
}

Measured memory_bytes: 1024
#include <stdio.h>
#include <limits.h>
#include <stdlib.h>
typedef struct{
    
    long int a;
    long int b;
    
}NUMBER;

int compare(const void *a, const void *b)
{
   NUMBER aNum = *(NUMBER*)a;
   NUMBER bNum = *(NUMBER*)b;

    int tmp1=aNum.a;
    int tmp2=bNum.a;

    return tmp1-tmp2;
}

int main(void)
{
    long int n, k, i, j=0;
    scanf("%ld%ld", &n, &k);
    NUMBER array[10*10*10*10*10];
    for(i=0;i<n;i++){
        scanf("%ld%ld", &array[i].a, &array[i].b);
    }

    qsort(array, n, sizeof(NUMBER), compare);
    for(i=0;i<n;i++){
        j=j+array[i].b;
        if(j>=k) break;
    }

    printf("%ld\n", array[i].a);
   
    return 0;
}

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

int main() {
	int a,b,c;
    cin >> a >> b >> c;
    int s = a+b;
    int t = a+c;
    int u = b+c;
    if(s < t && s < u){
      cout << s << endl;
    }
    else if(t < s && t < u){
      cout << t << endl;
    }
    else{
      cout << u << endl;
    }
}


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

using namespace std;

int main(void) {
  
  string S;
  string T;

  cin >> S;
  cin >> T;

  int size = T.size();
  if (T.substr(0,size-1) == S) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }

}


Measured memory_bytes: 3632
import scala.math._

object Main extends App {
  val scanner = new java.util.Scanner(System.in)

  val inputs = Iterator.continually {
    val n = scanner.nextInt()
    val sn = (1 to n).map { _ =>
      scanner.nextInt()
    }

    (n, sn)
  }.takeWhile(_._1 != 0)

  val outputs = inputs.map {
    case (n, sn) =>
      val m = sn.sum.toDouble / n
      val alpha2 = sn.foldLeft(0.0) { (acc, s) =>
        acc + pow(s - m, 2) / n
      }
      sqrt(alpha2)
  }

  outputs.foreach(println)
}

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

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

const long long INF = 1LL << 60; // 十分大きい値とする

// 入力と，メモ用の DP テーブル
int N;
vector<long long> h;
vector<long long> dp;

long long rec(int i) {
    // DP の値が更新されていたらそのままリターン
    if (dp[i] < INF) return dp[i];

    // 足場 0 のコストは 0
    if (i == 0) return 0;

    // i-1, i-2 それぞれ試す
    long long res = INF;
    chmin(res, rec(i-1) + abs(h[i] - h[i - 1])); // 足場 i-1 から来た場合
    if (i > 1) chmin(res, rec(i-2) + abs(h[i] - h[i - 2])); // 足場 i-2 から来た場合

    // 結果をメモしながら、返す
    return dp[i] = res;
}

int main() {
    // 入力受け取り
    cin >> N;
    h.resize(N);
    for (int i = 0; i < N; ++i) cin >> h[i];

    // 初期化 (最小化問題なので INF に初期化)
    dp.assign(N, INF);

    // 答え
    cout << rec(N-1) << endl;
}


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

int main(){
    int N;
    cin>>N;
    vector<int> V(N);
    for(int i=0;i<N;i++){
        cin>>V[i];
    }
    sort(V.begin(), V.end());
    V.erase(unique(V.begin(), V.end()), V.end());
    int ans = V.size();
    if((N-ans)%2)ans--;
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 888
#include <iostream>

using namespace std;

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

	int sum = 0;
	for (int i = 1; i <= n; i++) {
		sum += i;
		if (sum >= n) {
			cout << i << endl;
			return 0;
		}
	}

	return 0;
}

Measured memory_bytes: 256
import Data.List
import qualified Data.ByteString.Char8
 
(|>) :: a -> (a -> b) -> b
infixl 1 |>
x |> f = f x
 
($>) :: (Functor m) => m a -> (a -> b) -> m b
infixl 1 $>
x $> f = fmap f x

calc :: [Int] -> Int
calc xs
    | len >= num = len - num
    | otherwise  = len
    where len = length xs
          num = head xs

main = do
    getLine
    ax <- getLine $> words $> map read :: IO [Int]
    ax |> sort |> group |> map calc |> sum |> print

Measured memory_bytes: 39548
import java.util.*;
import java.util.stream.Collectors;

public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int N = scanner.nextInt();
        List<Integer> values = new ArrayList<>();
        for (int i=0; i<N; i++) {
            values.add(scanner.nextInt());
        }

        values = values.stream().distinct().collect(Collectors.toList());
        System.out.println(values.size());
    }
}

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

int main()
{
	int n;
	cin >> n;
	long long max = 0;
	vector<long long> av(n);
	for (auto& a : av) {
		cin >> a;
		if (max < a) {
			max = a;
		}
	}

	long long halfMax = max / 2;

	long long ret = 0;
	long long diff = max;
	for (auto& a : av) {
		long long temp = abs(halfMax - a);
		if (temp < diff) {
			if (a == max) {
				continue;
			}
			diff = temp;
			ret = a;
		}
	}

	cout << max << " " << ret << endl;

	return 0;
}

Measured memory_bytes: 1024
#include<stdio.h>
int main(){
  double d[8];
  int i;
  while(scanf("%lf",&d[0])!=EOF){
    for(i=1;i<8;i++)scanf("%lf",&d[i]);
    if((d[0]<=d[4]&&d[4]<=d[2]||d[4]<=d[0]&&d[0]<=d[6])&&
       (d[1]<=d[5]&&d[5]<=d[3]||d[5]<=d[1]&&d[1]<=d[7])){
      printf("YES\n");
    }
    else printf("NO\n");
  }
  return 0;
}

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

#define rep(i,n) for(int i=0; i<(n); i++)
#define reps(i,x,n) for(int i=x; i<(n); i++)
#define rrep(i,n) for(int i=(n)-1; i>=0; i--)
#define all(X) (X).begin(),(X).end()
#define X first
#define Y second
#define pb push_back
#define eb emplace_back

using namespace std;
typedef long long int ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }

template<class A, size_t N, class T> void Fill(A (&a)[N], const T &v){ fill( (T*)a, (T*)(a+N), v ); }

const ll INF = 1e9+7;


int main(){
	//ios_base::sync_with_stdio(false);
	ll K, A, B, ans=0;
	
	cin >> K >> A >> B;

	if( K <= A ){
		cout << 1 << endl;
		return 0;
	}

	if( A <= B ){
		cout << -1 << endl;
		return 0;
	}

	ll len = K-A;
	ll df = A-B;
	ll count = (len-1) / df + 1;
	ans = count * 2 + 1;

	cout << ans << endl;

	return 0;
}



Measured memory_bytes: 256
import sys
stdin = sys.stdin
mod = 10**9 + 7

ns = lambda: stdin.readline().rstrip()
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
sa = lambda h: [list(map(int, stdin.readline().split())) for i in range(h)]

a, b = na()
if b ==1:
        print(0)
elif (b-1)%(a-1)==0:
        print((b-1)//(a-1))
else:
        print((b-1)//(a-1)+1)

Measured memory_bytes: 3064
#include "bits/stdc++.h"
// Begin Header {{{
#define all(x) (x).begin(), (x).end()
#define rep(i, s, n) for (i64 i = (s), i##_limit = (n); i < i##_limit; ++i)
#define repr(i, s, t) for (i64 i = (s), i##_limit = (t); i >= i##_limit; --i)
#define repc(i, s, t) for (i64 i = (s), i##_limit = (t); i <= i##_limit; ++i)
#define var(type, ...) \
    type __VA_ARGS__;  \
    read(__VA_ARGS__);
#ifndef DBG
#define dump(...)
#endif
using namespace std;
using i64 = int_fast64_t;
using pii = pair<i64, i64>;
template <class T, class U>
inline bool chmax(T &a, const U &b) {
    return b > a && (a = b, true);
}
template <class T, class U>
inline bool chmin(T &a, const U &b) {
    return b < a && (a = b, true);
}
constexpr int INF = 0x3f3f3f3f;
constexpr i64 LINF = 0x3f3f3f3f3f3f3f3fLL;

template <class T>
inline vector<T> makeV(const T &initValue, size_t sz) {
    return vector<T>(sz, initValue);
}

template <class T, class... Args>
inline auto makeV(const T &initValue, size_t sz, Args... args) {
    return vector<decltype(makeV<T>(initValue, args...))>(
        sz, makeV<T>(initValue, args...));
}

template <class T>
inline istream &operator>>(istream &is, vector<T> &vec) {
    for (auto &e : vec) is >> e;
    return is;
}

inline void read() {}

template <class Head, class... Tail>
inline void read(Head &head, Tail &... tail) {
    cin >> head;
    read(tail...);
}

inline void print() { cout << "\n"; }

template <class Head, class... Tail>
inline void print(Head &&head, Tail &&... tail) {
    cout << head;
    if (sizeof...(tail)) cout << ' ';
    print(forward<Tail>(tail)...);
}

template <class T>
inline ostream &operator<<(ostream &os, const vector<T> &vec) {
    static constexpr const char *delim[] = {" ", ""};
    for (const auto &e : vec) os << e << delim[&e == &vec.back()];
    return os;
}

template <class Container>
struct Rev {
    Container &x_;
    inline Rev(Container &x) : x_(x) {}
    inline auto begin() { return rbegin(x_); }
    inline auto end() { return rend(x_); }
};
// }}} End Header

signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.setf(ios_base::fixed);
    cout.precision(12);

    var(string, line);
    i64 s = 0;
    for (char c : line) {
        s += c - '0';
    }

    if (s % 9 == 0) {
        print("Yes");
    } else {
        print("No");
    }

    return 0;
}


Measured memory_bytes: 3780
/*{{{*/
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<string>
#include<iostream>
#include<sstream>
#include<set>
#include<map>
#include<queue>
#include<bitset>
#include<vector>
#include<limits.h>
#include<assert.h>
#define SZ(X) ((int)(X).size())
#define ALL(X) (X).begin(), (X).end()
#define REP(I, N) for (int I = 0; I < (N); ++I)
#define REPP(I, A, B) for (int I = (A); I < (B); ++I)
#define FOR(I, A, B) for (int I = (A); I <= (B); ++I)
#define FORS(I, S) for (int I = 0; S[I]; ++I)
#define RS(X) scanf("%s", (X))
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
#define CASET int ___T; scanf("%d", &___T); for(int cs=1;cs<=___T;cs++)
#define MP make_pair
#define PB push_back
#define MS0(X) memset((X), 0, sizeof((X)))
#define MS1(X) memset((X), -1, sizeof((X)))
#define LEN(X) strlen(X)
#define F first
#define S second
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
typedef long double LD;
typedef pair<int,int> PII;
typedef vector<int> VI;
typedef vector<LL> VL;
typedef vector<PII> VPII;
typedef pair<LL,LL> PLL;
typedef vector<PLL> VPLL;
template<class T> void _R(T &x) { cin >> x; }
void _R(int &x) { scanf("%d", &x); }
void _R(LL &x) { scanf("%lld", &x); }
void _R(double &x) { scanf("%lf", &x); }
void _R(char &x) { scanf(" %c", &x); }
void _R(char *x) { scanf("%s", x); }
void R() {}
template<class T, class... U> void R(T &head, U &... tail) { _R(head); R(tail...); }
template<class T> void _W(const T &x) { cout << x; }
void _W(const int &x) { printf("%d", x); }
void _W(const LL &x) { printf("%lld", x); }
void _W(const double &x) { printf("%.16f", x); }
void _W(const char &x) { putchar(x); }
void _W(const char *x) { printf("%s", x); }
template<class T,class U> void _W(const pair<T,U> &x) {_W(x.F); putchar(' '); _W(x.S);}
template<class T> void _W(const vector<T> &x) { for (auto i = x.begin(); i != x.end(); _W(*i++)) if (i != x.cbegin()) putchar(' '); }
void W() {}
template<class T, class... U> void W(const T &head, const U &... tail) { _W(head); putchar(sizeof...(tail) ? ' ' : '\n'); W(tail...); }
#ifdef HOME
 #define DEBUG(...) {printf("# ");printf(__VA_ARGS__);puts("");}
#else
 #define DEBUG(...)
#endif
int MOD = 1e9+7;
void ADD(LL& x,LL v){x=(x+v)%MOD;if(x<0)x+=MOD;}
/*}}}*/
const int SIZE = 1e6+10;
int main(){
    int n,m,x,y; R(n,m,x,y);
    W((n-x)*(m-y));
    return 0;
}


Measured memory_bytes: 256
import java.util.*

fun main(args: Array<String>) {
  val sc = Scanner(System.`in`)
  val a = sc.nextInt()
  val b = sc.nextInt()
  val c = sc.nextInt()
  val x = sc.nextInt()

  println(c(a, b, c, x))
}

private fun c(a: Int, b: Int, c: Int, x: Int): Int {
  var ans = 0
  for (i in 0 .. a) {
    val i500 = i * 500
    for (j in 0 .. b) {
      val j100 = j * 100
      for (k in 0 .. c) {
        val k50 = k * 50
        val sum = i500 + j100 + k50
        if (sum == x) {
          ans++
        }
      }
    }
  }

  return ans
}


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

ll mod = 1000000007;


int main() {
string s; cin >>s;
set<char> S;
rep(i,s.size()){
    S.insert(s[i]);
}
if(S.size()==s.size()) cout << "yes" <<endl;
else cout << "no" <<endl;
}

Measured memory_bytes: 256
//file_name:ABC80_B.cpp
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(),a.end()
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define limit(x,l,r) max(l,min(x,r))
#define lims(x,l,r) (x = max(l,min(x,r)))
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define pb push_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define uni(x) x.erase(unique(rng(x)),x.end())
#define snuke srand((unsigned)clock()+(unsigned)time(NULL));
#define show(x) cout<<#x<<" = "<<x<<endl;
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define newline puts("")
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
typedef long long int ll;
typedef unsigned uint;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
inline int in() { int x; scanf("%d",&x); return x;}
template<typename T>inline istream& operator>>(istream&i,v(T)&v)
{rep(j,sz(v))i>>v[j];return i;}
template<typename T>string join(const v(T)&v)
{stringstream s;rep(i,sz(v))s<<' '<<v[i];return s.str().substr(1);}
template<typename T>inline ostream& operator<<(ostream&o,const v(T)&v)
{if(sz(v))o<<join(v);return o;}
template<typename T1,typename T2>inline istream& operator>>(istream&i,pair<T1,T2>&v)
{return i>>v.fi>>v.se;}
template<typename T1,typename T2>inline ostream& operator<<(ostream&o,const pair<T1,T2>&v)
{return o<<v.fi<<","<<v.se;}
template<typename T>inline ll suma(const v(T)& a) { ll res(0); for (auto&& x : a) res += x; return res;}
const double eps = 1e-10;
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;
#define dame { puts("-1"); return 0;}
#define yn {puts("Yes");}else{puts("No");}
const int MX = 200005;

    // int scan
    /*
    int x;
    scanf("%d",&x);
    int y;
    scanf("%d",&y);
    int z;
    scanf("%d",&z);

    // matrix scan
    /*
    ll a[n] = {};
    rep(i,n){
        scanf("%lld",&a[i]);
    }
    */

    // string scan
    /*
    string s;
    cin >> s;
    */


int main() {
    int n;
    scanf("%d",&n);
    int nn =n;
    int a=0;
    while(n>0){
        a+=n%10;
        n/=10;
    }
    if(nn%a==0)yn;


    return 0;
}



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

int main(){
ll N,M; cin >> N >> M;
  vector<ll> x(N), y(N), z(N);
  for(ll i = 0; i < N; i++){ cin >> x[i] >> y[i] >> z[i];}
  ll ans = -1LL<< 60;
  for(int i = 0; i < (1<<3); i++){
    vector<ll> vec;
    for(ll j = 0; j < N; j++){ ll res = 0;
      if( i >> 2 & 1){ res += x[j];} else { res -= x[j];}
      if( i >> 1 & 1){ res += y[j];} else { res -= y[j];}
      if( i & 1){ res += z[j];} else { res -= z[j];}
          vec.push_back(res);}
    sort(vec.rbegin(),vec.rend()); ll sum = 0;
    for(int k = 0; k < M; k++){ sum += vec[k];}
    ans = max(ans, sum);}
  
  cout << ans << endl; return 0;}
                                  

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

typedef long long ll;
const int maxn=2e5+10;
int n,a[maxn],b;
ll ans;

int main(){
	cin>>n;
	for(int i=1;i<=n;++i){
		cin>>a[i];
		a[i]-=i;
	}
	sort(a+1,a+n+1);
	b=a[n/2+1];
	for(int i=1;i<=n;++i)
		ans+=abs(b-a[i]);
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 1024
from sys import stdin
import sys
#from collections import defaultdict, deque, Counter
#from bisect import bisect_left
#import heapq
#import math
#import numpy as np

sys.setrecursionlimit(10 ** 7)
MIN = -10 ** 9
MOD = 10 ** 9 + 7
INF = float("inf")
IINF = 10 ** 18

s = str(stdin.readline().rstrip())
#l = list(map(int, stdin.readline().rstrip().split()))
#A, B, C = map(int, stdin.readline().rstrip().split())
#S = [list(stdin.buffer.readline().decode().rstrip()) for _ in range(h)]

n = len(s)

count = []
num = []
c = 1
for i in range(n-1):
    if s[i] == "R" and s[i+1] == "L":
        count.append("R")
        num.append(c)
        c = 1
    elif s[i] == "L" and s[i+1] == "R":
        count.append("L")
        num.append(c)
        c = 1
    else:
        c += 1

count.append("L")
num.append(c)

n = len(num)

for i in range(n):
    if count[i] == "R":
        for j in range(1,num[i]):
            print(0,end=" ")
        p = num[i]//2 + num[i]%2
        p += num[i+1]//2
        print(p,end=" ")
    else:
        p = num[i]//2 + num[i]%2
        p += num[i-1]//2
        print(p,end=" ")
        for j in range(1,num[i]):
            print(0,end=" ")


Measured memory_bytes: 5600
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <map>
#include <vector>
#include <queue>
#include <algorithm>

using namespace std;

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

ll mod = 1e9 + 7;


int main(){
	int n;
	int b[99];

	cin >> n;
	for(int i=0;i<n-1;i++) cin >> b[i];

	int a[100];
	for(int i=0;i<n;i++) a[i] = 100000;
	for(int i=0;i<n-1;i++){
		a[i] = min(a[i],b[i]);
		a[i+1] = b[i];
	}

	ll ans = 0;
	for(int i=0;i<n;i++) ans += a[i];
	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
	char a,b,c;
	int sum=700;
	cin>>a>>b>>c;
	if(a=='o') sum=sum+100;
	if(b=='o') sum=sum+100;
	if(c=='o') sum=sum+100;
	cout<<sum<<endl;
	return 0;
}

Measured memory_bytes: 256
data TreeDict k v = TDEmpty
                  | TDNode k v (TreeDict k v) (TreeDict k v)
                  deriving (Show)

addDict :: Ord k => k -> v -> TreeDict k v -> TreeDict k v
addDict k v TDEmpty = TDNode k v TDEmpty TDEmpty
addDict k v (TDNode k' v' l r)
  | k < k'    = TDNode k' v' (addDict k v l) r
  | k > k'    = TDNode k' v' l              (addDict k v r)
  | otherwise = TDNode k' v  l              r

lookup' :: Ord k => k -> TreeDict k v -> Maybe v
lookup' _ TDEmpty = Nothing
lookup' k (TDNode k' v' l r)
  | k < k'    = lookup' k l
  | k > k'    = lookup' k r
  | otherwise = Just v'

toDict :: (Ord a) => a -> a  -> TreeDict a a -> Maybe (TreeDict a a)
toDict k v tree = do
  case lookup' k tree of
    Nothing -> Just $ addDict k v tree
    Just x -> if x == v then Just tree else Nothing

fKeyToDic :: (Ord a) => (a,a) -> TreeDict a a -> Maybe (TreeDict a a)
fKeyToDic x tree = toDict (fst x) (snd x) tree

sKeyToDic :: (Ord a) => (a,a) -> TreeDict a a -> Maybe (TreeDict a a)
sKeyToDic x tree = toDict (snd x) (fst x) tree

tArrayToDic :: (Ord a) => [(a, a)] -> ((a,a) -> TreeDict a a -> Maybe (TreeDict a a)) -> Maybe (TreeDict a a)
tArrayToDic a f = do
  foldl (\acc a -> case acc of
      Just x -> f a x
      Nothing -> Nothing
    ) (Just TDEmpty) a

tArrayToFDic :: (Ord a) => [(a,a)] -> Maybe (TreeDict a a)
tArrayToFDic a = tArrayToDic a fKeyToDic

tArrayToSDic :: (Ord a) => [(a,a)] -> Maybe (TreeDict a a)
tArrayToSDic a = tArrayToDic a sKeyToDic

main :: IO ()
main = do
  x <- getLine
  y <- getLine
  let a = zipWith (\x y -> (x,y)) x y
  putStrLn $ case tArrayToFDic a of
    Just x -> case tArrayToSDic a of
      Just y -> "Yes"
      Nothing -> "No"
    Nothing -> "No"

Measured memory_bytes: 39548
#coding: utf-8
n = int(input())
l = list(map(int,input().split()))
ans = 0

for i in range(1,n-1):
    if l[i-1] < l[i] < l[i+1] or l[i-1] > l[i] > l[i+1] :
        ans += 1
        #print(i)

print(ans)


Measured memory_bytes: 2940
export class Main {
  static main(input): string {
    const s: string = input.split("\n")[0].split(" ")[0];
    const s1: number = Number(s.slice(0, 2));
    const s2: number = Number(s.slice(2, 4));
    const isMonth: (n: number) => boolean = n => 1 <= n && n <= 12;
    return `${
      isMonth(s1) && isMonth(s2) ? "AMBIGUOUS" :
      isMonth(s1)                ? "MMYY" :
      isMonth(s2)                ? "YYMM"
          : "NA"
    }`;
  }
}
console.log(Main.main(require("fs").readFileSync("/dev/stdin", "utf8")));

Measured memory_bytes: 9420
import java.util.*;
import java.io.*;
import java.math.BigInteger;
 
public class Main {
	public static void main(String[] args) {
	Scanner s = new Scanner(System.in);
	String S = s.next();
	
	int max = 0;
	int count = 0;
	for(int i = 0; i < S.length(); i++){
		if(S.charAt(i) == 'R'){
			count++;
			max = Math.max(max, count);
		}else{
			count = 0;
		}
	}

	

	System.out.println(max);

    
  }
}

Measured memory_bytes: 35604
import sys
#import numpy as np
stdin = sys.stdin

ri = lambda: int(rs())
rl = lambda: list(map(int, stdin.readline().split())) # applies to numbers only
rs = lambda: stdin.readline().rstrip()  # ignore trailing spaces

X = ri()
def primes(n):
    is_prime = [True] * (n + 1)
    is_prime[0] = False
    is_prime[1] = False
    for i in range(2, int(n**0.5) + 1):
        if not is_prime[i]:
            continue
        for j in range(i * 2, n + 1, i):
            is_prime[j] = False
    return [i for i in range(n + 1) if is_prime[i]]

l = set(primes(10**6))

while True:
    if X in l:
        print(X)
        exit()
    X += 1

Measured memory_bytes: 14000
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

// 入力
string f[10];
int n, w[10], s[10]; 
// used[i] := i番目を選んだかどうか
bool used[10];
// 今まで見つかった中で一番重心が低いもの
double ans_g;
// 解
vector<int> ans;

// 重さに耐えられるかチェック
bool check(vector<int>& v){
	for(int i=0 ; i < v.size() ; i++ ){
		int weight = 0;
		for(int j=i+1 ; j < v.size() ; j++ ){
			weight += w[v[j]];
		}
		if( s[v[i]] < weight )
			return false;
	}
	return true;
}

// 重心を計算
double gravity(vector<int>& v){
	double a = 0, b = 0;
	for(int i=0 ; i < v.size() ; i++ ){
		a += (i+1) * w[v[i]];
		b += w[v[i]];
	}
	return a / b;
}

// 順列生成して解を探す (最大で 10! 通り)
void solve(){
	vector<int> v(n);
	for(int i=0 ; i < n ; i++ ) v[i] = i;
	// 順列生成してチェック
	do{
		double g = gravity(v);
		// 重心が低い かつ 重さに耐えられるとき
		if( check(v) && g < ans_g ){
			ans_g = g;
			ans = v;
		}
	}while( next_permutation(v.begin(),v.end()) );
}

// 探索
void dfs(vector<int>& v, int num){
	// 重さに耐えられるかチェック, 耐えられないときは探索打ち切り
	if( !check(v) ) return;
	
	if( num == n ){
		double g = gravity(v);
		if( g < ans_g ){ // 重心が低いとき
			ans_g = g;
			ans = v;
		}
		return;
	}
	
	for(int i=0 ; i < n ; i++ ){
		if( used[i] ) continue;
		
		used[i] = true;
		v.push_back( i );
		dfs( v , num+1 );
		v.pop_back();
		used[i] = false;
	}
}

int main(){
	while( cin >> n , n ){
		// 初期化
		for(int i=0 ; i < 10 ; i++ ) used[i] = false;
		
		for(int i=0 ; i < n ; i++ ){
			cin >> f[i] >> w[i] >> s[i];
		}
		
		ans_g = 1e+9;
		vector<int> v;
		//dfs( v , 0 );
		solve();
		
		for(int i=0 ; i < ans.size() ; i++ ){
			cout << f[ans[i]] << endl;
		}
	}
}

Measured memory_bytes: 1216
#include<iostream>
using namespace std;
int main(){
  string s;
  cin >> s;
  int ans = 0;
  for(int i = 0;i<s.size()/2;++i){
    if(s[i]!=s[s.size()-i-1])ans++;
  }
  cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 256
// ALDS1_1_D Maximum Profit
import java.io.*;

class Main {
   public static void main(String[] args) {
      BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

      try {
         int n = Integer.parseInt(br.readLine());
         int[] R = new int[n];
         for (int i = 0; i < n; i++) {
            R[i] = Integer.parseInt(br.readLine());
         }
         System.out.println(max(R, n));
      }
      catch (Exception e) {
         e.printStackTrace();
      }
   }
   static int max(int[] R, int n) {
      int maxv = Integer.MIN_VALUE;
      int minv = R[0];
      for (int j = 1; j < n; j++) {
         maxv = maxv > R[j] - minv ? maxv : R[j] - minv;
         minv = minv < R[j] ? minv : R[j];
      }
      return maxv;
   }
}

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

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

using namespace std;

int main() {
  int n, k;
  cin >> n >> k;
  vector<int> vec(n);
  rep(i, n) cin >> vec[i];
  sort(vec.begin(), vec.end());
  int ans = 0;
  rep(i, k) ans += vec[i];
  cout << ans << endl;
  return 0;
}



Measured memory_bytes: 3620
#include <cstdio>
#include <algorithm>	
#include <iostream>
#include <vector>
#include <queue>
#include <cstring>
#include <cmath>
#define all(x) (x).begin(),(x).end()
using namespace std;
typedef long long LL;
typedef unsigned int uii;
typedef pair<int,int> pii;
typedef unsigned long long uLL; 
typedef vector<int> vii; 
const int maxn = 1e5;
LL a[20][20], d[maxn], vis[maxn][20];

inline int num(int c, int t[]){
	int res = 0;
	for(int i = 0; i < c; ++i){
		res += 1 << t[i];
	}
	return res;
}

int main(int argc, char const *argv[])
{
#ifndef ONLINE_JUDGE
	// freopen("in.txt", "r", stdin);
	// freopen("out.txt", "w", stdout);
#endif
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n;
	cin >> n;
	for(int i = 0; i < n; ++i){
		for(int j = 0; j < n; ++j){
			cin >> a[i][j]; 
		}
	}
	for(int i = 0; i < (1 << n); ++i){
		int b[20], c = 0;
		for(int j = 0; j < n; ++j){
			if(i & (1 << j)){
				b[c++] = j;
			}
		}
		for(int j = 0; j < c; ++j){
			for(int k = j + 1; k < c; ++k){
				d[i] += a[b[j]][b[k]];
			}
		}
	}
	int num = (1 << n) - 1;
	int c = 0;
	for(int i = 1; i <= num; ++i){
		// cout << i << endl;
		for(int j = i; j > 0; j = (j - 1) & i){
			// cout << j << ' ';
			d[i] = max(d[i], d[j] + d[j ^ i]);
			++c;
		}
		// cout << endl;
	}
	cout << d[num] << endl;
	return 0;
}

Measured memory_bytes: 2304
#include<iostream>
#include<cmath>
#include<cstdlib>
#include<string>
#include<cstring>
#include<algorithm>
#include<vector>
#include<map>
#include<iomanip>
#include<queue>
#include<cassert>

using namespace std;

template< typename T>
struct edge { 
   int from, to; 
   T cost; 
   edge(int from, int to, T cost) : from(from), to(to), cost(cost) {}
};

template< typename T>
using EDGE = vector< edge< T > >;

template< typename T>
vector< T > bellman_ford(EDGE< T > &es, int V, int s) {
   const auto INF = numeric_limits< T >::max();
   vector< T > dist(V, INF);
   dist[s] = 0;
   for (int i = 0; i < V - 1; i++) {
      for (auto &e : es) {
         if (dist[e.from] == INF) continue;
         dist[e.to] = min(dist[e.to], dist[e.from] + e.cost);
      }
   }
   for (auto & e : es) {
      if (dist[e.from] == INF) continue;
      if (dist[e.from] + e.cost < dist[e.to]) return vector< T >();
   }
   return dist;
}

const int MAXN = 2501;
bool used1[MAXN];
bool used2[MAXN];
vector<int> G1[MAXN], G2[MAXN];

void bfs1(int s) {
   used1[s] = true;
   queue<int> q;
   q.push(s);
   while (!q.empty()) {
      int cur = q.front();
      q.pop();
      for (auto &g : G1[cur]) {
         if (used1[g]) continue;
         used1[g] = true;
         q.push(g);
      }
   }
}

void bfs2(int s) {
   used2[s] = true;
   queue<int> q;
   q.push(s);
   while (!q.empty()) {
      int cur = q.front();
      q.pop();
      for (auto &g : G2[cur]) {
         if (used2[g]) continue;
         used2[g] = true;
         q.push(g);
      }
   }
}

int main() {
   int N, M, P;
   cin >> N >> M >> P;
   int A[M], B[M], C[M];
   for (int i = 0; i < M; i++) {
      cin >> A[i] >> B[i] >> C[i];
      A[i]--;
      B[i]--;
      C[i] = -1 * (C[i] - P);
      G1[A[i]].push_back(B[i]);
      G2[B[i]].push_back(A[i]);
   }
   memset(used1, false, sizeof(used1)); 
   memset(used2, false, sizeof(used2)); 

   bfs1(0);
   bfs2(N - 1);
   /*
   for (int i = 0; i < N; i++) {
      cout << i << " " << used1[i] << " " << used2[i] << endl;
   }
   */
   EDGE< int > edges;
   
   for (int i = 0; i < M; i++) {
      if (!used1[A[i]]) continue;
      if (!used1[B[i]]) continue;
      if (!used2[A[i]]) continue;
      if (!used2[B[i]]) continue;
      // cout << A[i] << " " << B[i] << " " << C[i] << endl;
      edges.emplace_back(A[i], B[i], C[i]);
   }
   
   auto res = bellman_ford(edges, N, 0);
   if (res.empty()) cout << "-1" << endl;
   else {
      assert(res[N - 1] != numeric_limits<int>::max());
      cout << max(0, -1 * res[N - 1]) << endl;
   }
   return 0;
}


Measured memory_bytes: 768
#include <iostream>
#include <set> 
using namespace std;
set<int> s;
int main(){
	int a,b;
	cin>>a>>b;
	s.insert(a); s.insert(b); 
	if(s.find(3)==s.end()) cout<<3<<endl;
	else if(s.find(2)==s.end()) cout<<2<<endl;
	else cout<<1<<endl;
	return 0;
}

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

namespace IO
{
char gc()
{
#ifdef FREAD
	static char buf[1<<21], *P1 = buf, *P2 = buf;
	if(P1 == P2)
	{
		P1 = buf;
		P2 = buf + fread(buf, 1, 1<<21, stdin);
		if(P1 == P2) return EOF;
	}
	return *(P1++);
#else
	return getchar();
#endif
}
template<typename Tp> bool get1(Tp &x)
{
	bool neg = 0;
	char c = gc();
	while( c != EOF && (c < '0' || c > '9') && c != '-' ) c = gc();
	if(c == '-') c = gc(), neg = 1;
	if(c == EOF) return false;
	x = 0;
	for(; c>='0' && c<='9'; c = gc()) x = x*10 + c - '0';
	if(neg) x = -x;
	return true;
}
template<typename Tp> void printendl(Tp x)
{
	if(x<0)putchar('-'),x=-x;
	static short a[40], sz;
	sz = 0;
	while(x>0)a[sz++]=x%10,x/=10;
	if(sz==0)putchar('0');
	for(int i=sz-1; i>=0; i--)putchar('0'+a[i]);
	puts("");
}
} // namespace IO
using IO::get1;
using IO::printendl;
#define get2(x,y) get1(x) && get1(y)
#define get3(x,y,z) get2(x,y) && get1(z)
#define get4(x,y,z,w) get3(x,y,z) && get1(w)
#define pb push_back
#define mp std::make_pair
#define ff first
#define ss second
typedef long long LL;
typedef unsigned long long uLL;
typedef std::pair<int,int> pii;
const int inf = 0x3f3f3f3f;
const LL Linf = 1ll<<61;

const int maxn = 1000111;

char s[maxn];
int n, suf[maxn];

int check(int x)
{
	if(x < 0 || suf[1] > x) return inf;
	int sum = 0, mn = 0;
	for(int i=1; i<=n; i++)
	{
		if(s[i] == '0') sum++;
		else if(s[i] == '1') sum--;
		else if(sum + suf[i+1] >= x) sum--;
		else sum++;
		if(sum > x) return inf;
		mn = std::min(mn, sum);
	}
	return x - mn;
}

int main()
{
	scanf("%s", s+1);
	n = strlen(s + 1);
	
	int sum = 0, mx = 0;
	for(int i=1; i<=n; i++)
	{
		if(s[i] == '0') sum++;
		else sum--;
		mx = std::max(mx, sum);
	}
	for(int i=n; i>=1; i--) suf[i] = std::max(0, suf[i+1] + (s[i] == '0') - (s[i] != '0'));
	printf("%d\n", std::min(check(mx), check(mx+1)));
	return 0;
}

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

using namespace std;

typedef long long ll;

const int N = 1205;
const int M = 2000000;
const ll inf = 1e18;

struct Edge {
  int v, next;
  ll w;
} g[M];
int cnt = 0, head[N], st, ed, dis[N], cur[N];
void init() {
  memset(head, -1, sizeof(head));
  cnt = 0;
}
void addedge(int u, int v, ll w = 1) {
  g[cnt].v = v, g[cnt].w = w, g[cnt].next = head[u], head[u] = cnt++;
  g[cnt].v = u, g[cnt].w = 0, g[cnt].next = head[v], head[v] = cnt++;
}
bool bfs() {
  memset(dis, -1, sizeof(dis));
  dis[st] = 0;
  std::queue<int> q;
  q.push(st);
  while (!q.empty()) {
    int u = q.front();
    q.pop();
    for (int i = head[u]; ~i; i = g[i].next) {
      int v = g[i].v;
      ll w = g[i].w;
      if (w && dis[v] == -1) {
        dis[v] = dis[u] + 1;
        q.push(v);
        if (v == ed)
          return true;
      }
    }
  }
  return false;
}
ll dfs(int u, ll limit) {
  if (u == ed)
    return limit;
  ll ans = 0;
  for (int &i = cur[u]; ~i; i = g[i].next) {
    int v = g[i].v;
    ll w = g[i].w;
    if (w && dis[v] == dis[u] + 1) {
      ll t = dfs(v, min(limit - ans, w));
      g[i].w -= t;
      g[i ^ 1].w += t;
      ans += t;
      if (ans == limit)
        break;
    }
  }
  if (!ans)
    dis[u] = -1;
  return ans;
}
ll dinic(int n) {
  ll ans = 0;
  while (bfs()) {
    for (int i = 1; i <= n; i++)
      cur[i] = head[i];
    ans += dfs(st, inf);
  }
  return ans;
}

int main(int argc, char *argv[]) {
  int n;
  cin >> n;
  vector<ll> a(n + 1);
  ll sum = 0;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
    sum += a[i];
    a[i] = -a[i];
  }
  st = n + 1, ed = n + 2;
  init();
  ll S = 0;
  for (int i = 1; i <= n; i++) {
    if (a[i] >= 0) {
      addedge(st, i, a[i]);
      S += a[i];
    } else {
      addedge(i, ed, -a[i]);
    }
    for (int j = i + i; j <= n; j += i) {
      addedge(i, j, inf);
    }
  }
  cout << sum + S - dinic(n + 2) << endl;
  return 0;
}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace AtCoder
{
	class Program
	{
		static void Main(string[] args)
		{
			var a = Console.ReadLine();
			var b = Console.ReadLine();

			if (a.CompareTo(b) == 0)
			{
				Console.WriteLine("EQUAL");
			}
			else if(a.Length > b.Length)
			{
				Console.WriteLine("GREATER");
			}
			else if(a.Length < b.Length)
			{
				Console.WriteLine("LESS");
			}
			else if(a.CompareTo(b) > 0)
			{
				Console.WriteLine("GREATER");
			}
			else
			{
				Console.WriteLine("LESS");
			}
		}
	}
}

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

using namespace std;

int main()
{
    string O,E;
    int i,m,n;
    cin>>O>>E;
    m=O.size();
    n=E.size();
    for(i=0;i<m+n;i++){
            if(i%2==0)
            cout<<O[i/2];
            else cout<<E[i/2];
        }

    return 0;
}



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

int main()
{
    int H, W;
    for (;;) {
        cin >> H >> W;
        if ((H == 0) && (W == 0))
            break;
        for (int i = 0; i < H; i++) {
            for (int j = 0; j < W; j++)
                cout << "#";
            cout << endl;
        }
        cout << endl;
    }
    return 0;
}

Measured memory_bytes: 1152
#include <iostream>
#include <set>
#include <string>
#include <algorithm>
#include <math.h>
#include <vector>
#include <map>
using namespace std;

//dp用関数
long long dp_Func(long long h[],long i,long k, long long x[],long long ans[]){
    for(long j=1;j<=k;j++){
        if(i>=j){
            x[j]=ans[i-j]+abs(h[i-j]-h[i]);
        }
    }
    sort(x,x+110);
    ans[i]=x[0];    //配列xの最小値を代入
    return ans[i];
}

int main(){
    
    //入力関係
    long n;
    cin >> n;
    long k;
    cin >> k;
    long long h[110000];
    for(int i=0;i<n;i++){
        cin >> h[i];
    }
    long long ans[110000];
    
    //dp配列の初項,第2項
    ans[0]=0;
    ans[1]=abs(h[0]-h[1]);
    long long x[110];   //i<=kであるようなans[i+1]の候補となる配列

    for(long i=2;i<n;i++){
        for(int i=0;i<110;i++){
            x[i]=11000000000;
        }
        ans[i]=dp_Func(h,i,k,x,ans);
        
    }
    cout << ans[n-1] << endl;
}

Measured memory_bytes: 1792
import sys
input = sys.stdin.buffer.readline

def main():
    N = int(input())
    a = list(map(int,input().split()))
    
    ans = 0
    num = 10**6
    for p in a:
        if p < num:
            ans += 1
            num = p
    
    print(ans)
    
if __name__ == "__main__":
    main()


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

using namespace std;

int main()
{
    int N;
    cin >> N;
    vector<long> A(N);
    multimap<long,long> Am;
    long sum = 0;
    for (long i = 0; i < N; i++)
    {
        cin >> A.at(i);
        sum += A.at(i);
        if (Am.count(A.at(i)) == 0)
        {
            Am.insert(make_pair(A.at(i),1));
        }else
        {
            auto poyo = Am.find(A.at(i));
            poyo-> second = poyo-> second + 1;
        }
    }
    int Q;
    cin >> Q;
    vector<long> B(Q);
    vector<long> C(Q);
    for (int  i = 0; i < Q; i++)
    {
        cin >> B.at(i) >> C.at(i);
    }
    for (int i = 0; i < Q; i++)
    {
        if (Am.find(B.at(i)) != Am.end())
        {
            auto po = Am.find(B.at(i));
            sum = sum - (po-> second)*B.at(i) + (po-> second)*C.at(i);
            if (Am.count(C.at(i)) == 0)
            {
                Am.insert(make_pair(C.at(i),(po-> second)));
            }else
            {
                auto poyo = Am.find(C.at(i));
                poyo-> second = poyo-> second + (po-> second);
            }
            Am.erase(B.at(i));
        }
        cout << sum << endl;
    }
}

Measured memory_bytes: 9504
#include <bits/stdc++.h>
using namespace std;
using ll = long long int;
using ld = long double;
const int INF = 1 << 29;
const ll LINF = 1l << 61;
const ld PI = abs(acos(-1));
#define pq priotity_queue
#define pb push_back
#define mp make_pair
#define rep(i, a, b) for (ll i = (a); i < (b); i++)
#define rrep(i, a, b) for (ll i = (a); i >= (b); i--)
#define cbuf(buf, init) memset(buf, init, sizeof(buf))

template <class T>
constexpr T modp(T x, T y)
{
    return (y + x % y) % y;
}
template <class T>
constexpr T sq(T x)
{
    return x * x;
}
template <class T>
constexpr double divd(T x, T y)
{
    static_cast<double>(x) / static_cast<double>(y);
}

template <class T>
T nextInput()
{
    T t;
    cin >> t;
    return t;
}

#define netint nextInput<ll>()
#define netstr nextInput<string>()

template <class T>
void print(T&& t)
{
    cout << forward<T&&>(t) << endl;
}

void print(double t) { cout << fixed << setprecision(14) << t << endl; }

//

ll H, W, D, A[500][500], Q, L[200000], R[200000];

ll X[100000], Y[100000];
ll dp[100000];

int main()
{
    //
    cin >> H >> W >> D;
    rep(i, 0, H)
    {
        rep(j, 0, W)
        {
            cin >> A[i][j];
            X[A[i][j]] = j;
            Y[A[i][j]] = i;
        }
    }
    cin >> Q;
    rep(i, 0, Q) { cin >> L[i] >> R[i]; }

    rep(i, 0, D + 1) { dp[i] = 0; }
    rep(i, D + 1, 100000)
    {
        dp[i] = dp[i - D] + abs(X[i] - X[i - D]) + abs(Y[i] - Y[i - D]);
    }

    rep(i, 0, Q) { cout << dp[R[i]] - dp[L[i]] << endl; }
}


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

#define int long long

int judge(vector<int>&a2,int k){
	int sz = a2.size();
	int sum = 0;
	int ans = 0;
	for(int i = 0;i < sz;i++){
		sum += a2[i];
		int rem = sz-i-1;
		int op = rem+sz;
		if(op > k) continue;
		ans = max(ans,sum);
	}
	
	// cout<<sz<<endl;
	// for(int i = 0;i < sz;i++){
	// 	cout<<a2[i]<<" ";
	// }
	// cout<<endl<<ans<<endl<<endl;
	
	return ans;
}

signed main() {
	// your code goes here
	int n,k;
	cin>>n>>k;
	int arr[n+2]={0},sum[n+2]={0};
	for(int i = 1;i <= n;i++){
		cin>>arr[i];
		sum[i] = sum[i-1] + arr[i];
	}
	vector<int> a1,a2;
	int s1=0,s2=0;
	int ans = 0;
	for(int i = 0;i < n;i++){
		if(i != 0) {a1.push_back(arr[i]); s1+=arr[i];}
		a2 = a1;
		s2 = s1;
		for(int j = n+1;j > i;j--){
			if(j!=n+1) { a2.push_back(arr[j]); s2+=arr[j];}
			if(a2.size() > k) break;
			sort(a2.begin(),a2.end());
			reverse(a2.begin(),a2.end());
			ans = max(ans,judge(a2,k));
		}
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
    using namespace std;
    using ll=long long;
    constexpr ll mod=1e9+7;
     
    int main()
    {
      int n;
      cin>>n;
      vector<int> a(n);
      for (int i = 0; i < n; ++i)
      {
        cin>>a[i];
      }
      int cnt=0;
      for (int i = 0; i < n; ++i)
      {
        if((i+1)%2==1&&a[i]%2==1) cnt++;
      }
      cout<<cnt<<endl;
    }

Measured memory_bytes: 3576
#!/usr/bin/env python3

N, M = list(map(int, input().split()))
if N == 1 and M != 1:
    ans = 1
elif N != 1 and M == 1:
    ans = 1
else:
    a = ((N + 1) // 2) * ((M + 1) // 2)
    b = (N // 2) * (M // 2)
    ans = a + b
print(ans)


Measured memory_bytes: 3060
#!/usr/bin/env python3.8.3
# -*- coding: utf-8 -*-


def main():
    X = int(input())
    if X < 600:
        ans = 8
    elif X < 800:
        ans = 7
    elif X < 1000:
        ans = 6
    elif X < 1200:
        ans = 5
    elif X < 1400:
        ans = 4
    elif X < 1600:
        ans = 3
    elif X < 1800:
        ans = 2
    else:
        ans = 1

    print(ans)


if __name__ == "__main__":
    main()


Measured memory_bytes: 9084
#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <map>
#include <unordered_map>
#include <utility>
#include <algorithm>
#include <cmath>
#include <array>
#include <bitset>
using namespace std;

typedef long long ll;
const ll mod=1000000007;
#define rep(i,n) for(int i=0;i<n;i++)
#define Rep(i,n) for(int i=1;i<n+1;i++)

void print(vector<int> vec){
    while(!vec.empty()){
        if(vec.front()==1) cout<<"S";
        else cout<<"W";
        vec.erase(vec.begin());
    }
}

int main(){
    int N;
    string s;
    cin>>N>>s;
    vector<int> vec,ans;
    rep(i,s.size()){
        if(s[i]=='o') vec.push_back(1);
        else vec.push_back(-1);
    }

    int a1,a2;
    int a_,b_,c;
    rep(i,2){
        a1=2*i-1;
        rep(j,2){
            a2=2*j-1;
            ans.clear();
            ans.push_back(a1);
            ans.push_back(a2);
            a_=a1;b_=a2;
            rep(k,N-2){
                c=a_*b_*vec[k+1];
                a_=b_;
                b_=c;
                ans.push_back(c);
            }
            if(a_*c*a1==vec[N-1] && c*a1*a2==vec[0]){
                print(ans);
                return 0;
            }
        }
    }
    cout<<-1<<endl;
    return 0;
}

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

struct node{
  struct node *right;
  struct node *left;
  struct node *parent;
  int key;
};
typedef struct node * Node;
#define NIL NULL

Node root;

void insert(int k){
  Node y = NIL;
  Node x = root;
  Node z;

  z = malloc(sizeof(struct node));
  z->key = k;
  z->left = NIL;
  z->right = NIL;

  while(x!=NIL){
    y=x;
    if(z->key < x->key){
      x = x->left;
    }
    else{
      x = x->right;
    }
  }
    z->parent = y;

    if(y==NIL){
      root=z;
    }
    else if(z->key < y->key){
      y->left = z;
    }
    else {
      y->right = z;
    }
  
}

void inorder(Node u){

  if(u != NIL){
    inorder(u->left);
    printf(" %d",u->key);
    inorder(u->right);
  }


}
void preorder(Node u){

  if(u!=NIL){
    printf(" %d",u->key);
    preorder(u->left);
    preorder(u->right);
  }  
}


int main(){
  int n, i, x;
  char com[20];
  scanf("%d", &n);

  for ( i = 0; i < n; i++ ){
    scanf("%s", com);
    if ( com[0] == 'i' ){
      scanf("%d", &x);
      insert(x);
    } else if ( com[0] == 'p' ){
      inorder(root);
      printf("\n");
      preorder(root);
      printf("\n");
    }
  }

  return 0;
}

Measured memory_bytes: 24040
let lines = [];
let reader = require('readline').createInterface({
    input: process.stdin,
    output: process.stdout
});

// 標準入力の読み込み
reader.on('line', function(line) {
    lines.push(line);
});

reader.on('close', function() {
    // 処理の記述
    const n = lines[0];
    const len = lines[1].split(' ');
    let lenInt = [];

    for (let i = 0; i < len.length; i++) {
        lenInt.push(parseInt(len[i]));
    }

    let count = 0;

    for (let i = 0; i < lenInt.length; i++) {
        for (let j = i + 1; j < lenInt.length; j++) {
            for (let k = j + 1; k < lenInt.length; k++) {
                if (lenInt[i] === lenInt[j] || lenInt[j] === lenInt[k] || lenInt[k] === lenInt[i]) {
                    continue;
                }

                const sum = lenInt[i] + lenInt[j] + lenInt[k];
                const max = Math.max(lenInt[i], lenInt[j], lenInt[k]);
                
                if ( max >= sum - max) {
                    continue;
                }

                count++;

            }
        }
    }

    // 表示
    console.log(count);
});

Measured memory_bytes: 33308
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n;cin>>n;
  multiset<int> st;
  for(int i=0;i<n;++i){
    int tmp;cin>>tmp;
      auto it = st.lower_bound(tmp);
      if (it == st.begin()) 
        st.insert(tmp); 
      else { 
        it--; 
        st.erase(it); 
        st.insert(tmp);
        }    
    /*
    for(auto i:st){
      cout<<i<<" ";
    }cout<<endl;
	*/
  }
  cout<<st.size()<<endl;
  return 0;
}


Measured memory_bytes: 4992
#include <bits/stdc++.h>
typedef long long ll;
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;
using namespace std;
 
#define dump(x)  cout << #x << " = " << (x) << endl;
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define POSSIBLE(n) cout << ((n) ? "POSSIBLE" : "IMPOSSIBLE"  ) << endl
#define Possible(n) cout << ((n) ? "Possible" : "Impossible"  ) << endl
#define possible(n) cout << ((n) ? "possible" : "impossible"  ) << endl
 
#define SANKOU(n,a,b) cout << ((n) ? (#a) : (#b) ) << endl
 
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) for(int i=0;i<(n);++i)
#define REPR(i,n) for(int i=n;i>=0;i--)
 
#define FOREACH(x,a) for(auto& (x) : (a) )
 
#define WFA(d,v) REP(k,v)REP(i,v)REP(j,v)d[i][j]=min(d[i][j],d[i][k]+d[k][j])
 
#define SCOUT(x) cout<<(x)<<" "
#define ENDL cout<<endl
 
#define VECCIN(x) for(auto&youso_: (x) )cin>>youso_
#define VECIN2(x,y) REP(i,x.size())cin>>x[i]>>y[i]
#define VECCOUT(x) if(1){for(auto tt=x.begin();tt!=x.end();tt++){if(tt!=x.begin())cout<<" ";cout<<(*tt);}cout<<endl;}
 
#define ALL(obj) (obj).begin(),(obj).end()
 
#define EXIST(n,x) (find(ALL(n),x)!=n.end())
#define UNIQUE(obj) sort(ALL( obj )); obj.erase(unique(ALL(obj)),obj.end())
#define EN(x) if(1){cout<<#x<<endl;return 0;}
#define COUT(x) cout<<(x)<<endl
void CINT(){}
template <class Head,class... Tail>
void CINT(Head&& head,Tail&&... tail){
    cin>>head;
    CINT(move(tail)...);
}
#define CIN(...) int __VA_ARGS__;CINT(__VA_ARGS__)
#define LCIN(...) ll __VA_ARGS__;CINT(__VA_ARGS__)
#define SCIN(...) string __VA_ARGS__;CINT(__VA_ARGS__)
 
template <class T = ll>
T IN(){T x;cin>>x;return (x);}
 
template <class Head>
void VT(Head head){}
template <class Head,class Seco,class... Tail>
void VT(Head&& head,Seco&& seco,Tail&&... tail){
    seco.resize(head);
    VT(head,move(tail)...);
}
void VT2(){}
template <class Head,class... Tail>
void VT2(Head&& head,Tail&&... tail){
  VECCIN(head);
  VT2(move(tail)...);
}
 
template <class Head>
void VT3(Head&& head){}
template <class Head,class Seco,class... Tail>
void VT3(Head&& head,Seco&& seco,Tail&&... tail){
  seco[head]=IN();
  VT3(head,move(tail)...);
}
 
#define VC1(n,...) V __VA_ARGS__;VT(n,__VA_ARGS__);VT2(__VA_ARGS__); //aaabbbccc
#define VC2(n,...) V __VA_ARGS__;VT(n,__VA_ARGS__);REP(i,n)VT3(i,__VA_ARGS__); //abcabcabc
 
//#include <boost/multiprecision/cpp_int.hpp>
//using namespace boost::multiprecision; // cpp_int
 
#define P pair<ll,ll>
#define V vector<ll>
#define M map<ll,ll>
#define S set<ll>
 
#define pb(a) push_back(a)
#define mp make_pair

int main(){

  CIN(h,w);
  REP(i,w+2)cout<<"#";ENDL;
  REP(i,h){
    cout<<"#";
    cout<<IN<string>();
    cout<<"#";
    ENDL;
  }
  REP(i,w+2)cout<<"#";ENDL;

  return 0;
}

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

void solve(){
  string s; cin >> s;
  int ans = 1000000000;
  for(int i = 0; i < s.length() - 2; i++){
    int ten = 100, x = 0;
    for(int j = i; j < i + 3; j++){
      x += (s[j] - '0') * ten;
      ten /= 10;
    }
    ans = min(abs(x - 753), ans);
  }
  cout << ans << endl;
  return;
}

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


Measured memory_bytes: 256