akhauriyash/Code-Regression huggingface dataset:
#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 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 = 1e18;
const int INF = 1001001001;
#define dame { puts("NO"); return 0;}
#define yn {puts("YES");}else{puts("NO");}
const int MX = 200005;
typedef v(string) vs;



int main() {
  int h,w,a,b;
  scanf("%d%d%d%d",&h,&w,&a,&b);
  vs ans(h,string(w,'.'));
  int cnt = 0;
  if (h&1) {
    int x = min(a,w/2);
    a -= x;
    rep(i,x) ans.back()[w-2-i*2] = '<';
    rep(i,x) ans.back()[w-1-i*2] = '>';
    --h; ++cnt;
  }
  if (w&1) {
    int x = min(h/2,b);
    b -= x;
    rep(i,x) ans[i*2].back() = '^';
    rep(i,x) ans[i*2+1].back() = 'v';
    --w; ++cnt;
  }
  int tot = a+b;
  if (a&1) tot++;
  if (b&1) tot++;
  if ((a&1) && (b&1) && cnt == 2) {
    ans[h-1][0] = '^';
    ans[h][0] = 'v';
    --b; --a;
    ans[h-2][0] = '<';
    ans[h-2][1] = '>';
    tot -= 2;
  }
  if (tot*2 > h*w) dame;
  rep(i,h/2)rep(j,w/2) {
    if (ans[i*2][j*2] != '.') continue;
    if (a) {
      ans[i*2][j*2] = '<';
      ans[i*2][j*2+1] = '>';
      --a;
      if (a) {
        ans[i*2+1][j*2] = '<';
        ans[i*2+1][j*2+1] = '>';
        --a;
      }
    } else if (b) {
      ans[i*2][j*2] = '^';
      ans[i*2+1][j*2] = 'v';
      --b;
      if (b) {
        ans[i*2][j*2+1] = '^';
        ans[i*2+1][j*2+1] = 'v';
        --b;
      }
    }
  }

  cout<<"YES"<<endl;
  for (string s : ans) cout<<s<<endl;
  return 0;
}






















Measured memory_bytes: 2304
n, m = map(int, input().split())
a = []
for i in range(m):
	a.append([int(n) for n in input().split()])
	a[i].append(i)
a = sorted(a)
b = []
counter = 0
counter1 = 1
for i in range(m):
	c = ""
	if a[i][0] < 100000:
		getlen = len(str(a[i][0]))
		c = "0" * (6 - getlen) + str(a[i][0])
	else:
		c = str(a[i][0])
	if i == 0:
		c += "000001"
		counter = a[0][0]
	elif a[i][0] == counter:
		getlen = len(str(counter1 + 1))
		c += "0" * (6 - getlen) + str(counter1 + 1)
		counter1 += 1
	else:
		counter1 = 1
		c += "000001"
		counter = a[i][0]
	a[i].append(c)

for i in range(m):
	a[i][2], a[i][0] = a[i][0], a[i][2]
a = sorted(a)
for i in range(m):
	print(a[i][3])

Measured memory_bytes: 32372
class Node:
    def __init__(self):
        self.key, self.left, self.right, self.parent = 0, None, None, None

class BST:
    def __init__(self):
        self.root = None
    
    def insert(self, key):
        x, y = self.root, None
        z = Node()
        z.key = key
        while x != None:
            y = x
            if z.key < x.key:
                x = x.left
            else:
                x = x.right
        z.parent = y
        if y == None:
            self.root = z
        elif z.key < y.key:
            y.left = z
        else:
            y.right = z
    
    def find(self, key):
        r = self.root
        while r != None:
            if key == r.key:
                break
            elif key < r.key:
                r = r.left
            else:
                r = r.right
        return r
    
    def preOrder(self, r = -1):
        if r == -1: r = self.root
        if r == None:   return
        print("", r.key, end = '')
        self.preOrder(r.left)
        self.preOrder(r.right)
    
    def inOrder(self, r = -1):
        if r == -1: r = self.root
        if r == None:   return
        self.inOrder(r.left)
        print("", r.key, end = '')
        self.inOrder(r.right)

tree = BST()
for _ in range(int(input())):
    s = input()
    if s[0] == 'i':
        tree.insert(int(s[7:]))
    elif s[0] == 'p':
        tree.inOrder()
        print("")
        tree.preOrder()
        print("")
    else:
        print(['no', 'yes'][tree.find(int(s[5:])) != None])


Measured memory_bytes: 85436
#include <iostream>
#include <algorithm>
#include <cmath>
#include <string>
#include <array>
#include <vector>
#include <functional>
#include <numeric>
#include <limits>
#include <utility>
using namespace std;
typedef long long longlong;
typedef long long LL;

int main(void) {
	LL n, i, j, ans10 = 0, ans = 0, mi = 101;
	cin >> n;
	vector<LL> s(n);
	for (i = 0; i < n; i++) {
		cin >> s[i];
		if (s[i] % 10 == 0) {
			ans10 += s[i];
		}
		else {
			mi = min(mi, s[i]);
			ans += s[i];
		}
	}
	ans += ans10;
	if (ans%10==0&&mi < 101)ans -= mi;
	if (ans % 10 == 0) {
		cout << 0 << endl;
	}
	else {
		cout << ans << endl;
	}

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
typedef long long ll;
typedef long double ld;
const int INF=1e9,MOD=1e9+7,ohara=1e6+10;
const ll LINF=1e18;
using namespace std;

#define rep(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define rrep(i,a,b) for(int i=(a);i<(b);i++)
#define rrrep(i,a,b) for(int i=(a);i>=(b);i--)
#define all(v) (v).begin(), (v).end()
#define Size(n) (n).size()
#define Cout(x) cout<<(x)<<endl

ll n,cnt,ans,a,b,c,d,tmp,tmpp,m,h,w,x,y,sum,pos,k;
ld doua;
int dy[]={1,0,-1,0};
int dx[]={0,1,0,-1};
//int dy[]={-1,0,1,-1,1,-1,0,1};
//int dx[]={-1,-1,-1,0,0,1,1,1};
string alph("abcdefghijklmnopqrstuvwxyz"),s;
bool fl;
struct edge{int to,cost;};

//-------------------------↓↓↓↓↓↓------------------------

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

    cin>>a>>b;
    while(1){
        if(a<=b)ans++;
        else break;
        a*=2;
    }
    Cout(ans);
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
char a[1001][1001];
int dp[1001][1001];
int n,m;
int DP(int i,int j){
    if (i==n-1 && j==m-1)return 0;
    if (i>=n || j>=m)return 0;
    if (dp[i][j]!=-1)return dp[i][j];
    int ret=1e9;
    if (i+1<n){
        ret=min(ret, DP(i+1,j)+(a[i][j]!=a[i+1][j]));
    }
    if (j+1<m){
        ret=min(ret, DP(i,j+1)+(a[i][j]!=a[i][j+1]));
    }
    return dp[i][j]=ret;
}
int main()
{
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    memset(dp,-1,sizeof(dp));
    cin>>n>>m;
    for (int i=0;i<n;i++){
        for (int j=0;j<m;j++){
            cin>>a[i][j];
        }
    }
    int ans = DP(0,0)+(a[0][0]=='#');
    cout<<ans/2 + ans%2<<endl;
}

Measured memory_bytes: 4352
import java.util.*;
public class Main {
	static Scanner sc = new Scanner(System.in);
	static int t, y, h, n;
	static double r;
	public static void main(String[] args) {
		while(read()){
		}
	}
	static boolean read(){
		t = sc.nextInt();
		y = sc.nextInt();
		h = sc.nextInt();
		if( t == 0 && y == 0 && h == 0)return false;
		n = sc.nextInt();
		//System.out.println("t = "+t+" y = "+y+" h = "+h+" n = "+n);
		for(int i = 0; i < n; i++){
			r = sc.nextInt();
			//System.out.println("r = "+r);
			solve();
		}
		return true;
	}
	static void solve(){
		double r1 = Math.sqrt(y*y + t*t)/2;
		double r2 = Math.sqrt(y*y + h*h)/2;
		double r3 = Math.sqrt(h*h + t*t)/2;
		double minR = Math.min(r1, Math.min(r2, r3));
		//System.out.println("r1 = "+r1+" r2 = "+r2+" r3 = "+r3);
		//System.out.println("minR = "+ minR);
		if( r > minR){
			System.out.println("OK");
		}else{
			System.out.println("NA");
		}
	}

}

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

int main(){
    using namespace std;
    unsigned long N;
    cin >> N;
    puts([](unsigned long N) -> bool{
        for(unsigned long i = 1; i <= 9; ++i){
            if(N % i == 0 && N / i < 10)return true;
        }
        return false;
    }(N) ? "Yes" : "No");
    return 0;
}

Measured memory_bytes: 256
#[allow(unused_macros)]
macro_rules ! input { ( source = $ s : expr , $ ( $ r : tt ) * ) => { let mut iter = $ s . split_whitespace ( ) ; let mut next = || { iter . next ( ) . unwrap ( ) } ; input_inner ! { next , $ ( $ r ) * } } ; ( $ ( $ r : tt ) * ) => { let stdin = std :: io :: stdin ( ) ; let mut bytes = std :: io :: Read :: bytes ( std :: io :: BufReader :: new ( stdin . lock ( ) ) ) ; let mut next = move || -> String { bytes . by_ref ( ) . map ( | r | r . unwrap ( ) as char ) . skip_while ( | c | c . is_whitespace ( ) ) . take_while ( | c |! c . is_whitespace ( ) ) . collect ( ) } ; input_inner ! { next , $ ( $ r ) * } } ; }
#[allow(unused_macros)]
macro_rules ! input_inner { ( $ next : expr ) => { } ; ( $ next : expr , ) => { } ; ( $ next : expr , $ var : ident : $ t : tt $ ( $ r : tt ) * ) => { let $ var = read_value ! ( $ next , $ t ) ; input_inner ! { $ next $ ( $ r ) * } } ; }
#[allow(unused_macros)]
macro_rules ! read_value { ( $ next : expr , ( $ ( $ t : tt ) ,* ) ) => { ( $ ( read_value ! ( $ next , $ t ) ) ,* ) } ; ( $ next : expr , [ $ t : tt ; $ len : expr ] ) => { ( 0 ..$ len ) . map ( | _ | read_value ! ( $ next , $ t ) ) . collect ::< Vec < _ >> ( ) } ; ( $ next : expr , chars ) => { read_value ! ( $ next , String ) . chars ( ) . collect ::< Vec < char >> ( ) } ; ( $ next : expr , usize1 ) => { read_value ! ( $ next , usize ) - 1 } ; ( $ next : expr , $ t : ty ) => { $ next ( ) . parse ::<$ t > ( ) . expect ( "Parse error" ) } ; }

fn main() {
    input! {
        s: chars
    }
    let cnt = count(&s);
    println!("{}", cnt.get(&'1').unwrap_or(&0));
}

#[allow(dead_code)]
fn count<T: Eq + std::hash::Hash + Clone>(slice: &[T]) -> std::collections::HashMap<T, usize> {
    let mut hmap = std::collections::HashMap::new();
    for item in slice {
        *hmap.entry(item.clone()).or_insert(0) += 1;
    }
    hmap
}

Measured memory_bytes: 4352
#include <iostream>
#include <fstream>
#include <set>
#include <map>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <stack>
#include <functional>
#include <algorithm>
#include <climits>
#include <cmath>
#include <iomanip>
using namespace std;
#define ll long long int
#define rep(i,n) for( int i = 0; i < n; i++ )
#define rrep(i,n) for( int i = n; i >= 0; i-- )
#define REP(i,s,t) for( int i = s; i <= t; i++ )
#define RREP(i,s,t) for( int i = s; i >= t; i-- )
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define INF 2000000000
#define mod 1000000007
#define INF2 1000000000000000000


int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    string S; cin >> S;
    ll ans = 0;
    int black = 0;
    rep(i, S.length()) {
        if(S[i] == 'B') black++;
        else ans += black;
    }
    cout << ans << endl;

    return 0;
}
// BBW
// BWB
// WBB

Measured memory_bytes: 3720
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {
	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String str = br.readLine();
		Boolean isEnd = str == null;
		int count;
		while (!isEnd) {
			int n = Integer.parseInt(str);
			count = 0;
			for (int a = 0; a <= 9; a++) {
				if (n - a < 0) {
					break;
				}
				for (int b = 0; b <= 9; b++) {
					if (n - a - b < 0) {
						break;
					}
					for (int c = 0; c <= 9; c++) {
						if (n - a - b - c < 0) {
							break;
						} else if (n - a - b - c > 9) {
							continue;
						} else {
							count++;
						}
					}
				}
			}
			System.out.println(count);
			str = br.readLine();
			isEnd = str == null;
		}
	}

}

Measured memory_bytes: 23916
import math as m

A, B, H, M = map(int, input().split())

angle = abs((H * 60 + M) * 0.5 - M * 6)

ans = (A ** 2 + B ** 2 - 2 * A * B * m.cos(m.radians(angle))) ** 0.5
print(ans)

Measured memory_bytes: 9492
import * as fs from "fs";

const N = fs
  .readFileSync("/dev/stdin", "utf8")
  .split("\n")[0];

// inputで受け取り配列化する
const input = fs
  .readFileSync("/dev/stdin", "utf8")
  .split("\n")[1]
  .split(" ")
  .map(Number);

input.sort(function(a, b) {return b - a});
let ans = 0;

for(let i = 0; i < N; ++i) {
  for(let j = 0; j < i; ++j) {
    for(let k = 0; k < j; ++k) {
      if((input[i] != input[j])
        && (input[j] != input[k])
        && (input[i] + input[j] > input[k]) ){
      	ans++;
      }
	}
  }
}

console.log(ans);

Measured memory_bytes: 32356
#include<algorithm>
#include<bitset>
#include<cmath>
#include<complex>
#include<deque>
#include<functional>
#include<iomanip>
#include<iostream>
#include<iterator>
#include<map>
#include<numeric>
#include<queue>
#include<set>
#include<stack>
#include<string>
#include<unordered_map>
#include<unordered_set>
#include<utility>
#include<vector>

using namespace std;
typedef long long ll;

#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=(ll)(b);i--)
#define ALL(x) (x).begin(),(x).end()
#define SIZE(x) ((ll)(x).size())
#define MAX(x) *max_element(ALL(x))
#define MIN(x) *min_element(ALL(x))
#define D()
#define INF 1000000000000
#define MOD 10000007
#define MAXR 100000
#define PB push_back
#define MP make_pair
#define F first
#define S second
#define INITA(a,i,j,v) for(ll k=i;k<=j;k++){a[k]=v;}

int main() {
    int n; cin >> n;
    int a[100001]; INITA(a, 0, 100000, 0);
    REP(i, n) {
        cin >> a[i+1];
    }
    int res = 0;
    REP(i, n) {
        if (a[a[i+1]] == i+1) {
            res++;
        }
    }
    cout << res / 2 << endl;
    return 0;
}

Measured memory_bytes: 640
#[allow(unused_imports)]
use std::cmp::{min,max};

fn main() {
    let n = read_i64() as usize;
    let xs = read_vec_i64();
    let ys = {
        let mut ys = vec![];
        for (i,&x) in xs.iter().enumerate() {
            ys.push((x,i));
        }
        ys.sort();
        ys
    };
    let (a,_) = ys[n/2-1];
    let (b,_) = ys[n/2];
    for x in xs {
        if x <= a {
            println!("{}", b);
        }
        else {
            println!("{}", a);
        }
    }
}

#[allow(dead_code)]
fn read_line() -> String {
    let mut ret = String::new();
    std::io::stdin().read_line(&mut ret).ok();
    ret.pop();
    return ret;
}

#[allow(dead_code)]
fn read_i64() -> i64 {
    let ss = read_line();
    return ss.parse::<i64>().unwrap();
}

#[allow(dead_code)]
fn read_vec_i64() -> Vec<i64> {
    let mut res = vec![];
    let ss = read_line();
    for ts in ss.split_whitespace() {
        let x = ts.parse::<i64>().unwrap();
        res.push(x);
    }
    return res;
}


Measured memory_bytes: 13032
#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(){
    string a,b,c;
    cin >> a >> b >> c ;
    cout << a.at(0) << b.at(0) << c.at(0) << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
  ll N,K;
  ll h;
  ll cnt=0;
  cin>>N>>K;
  for(int i=0;i<N;i++){
    cin>>h;
    if(h>=K) cnt++;
  }
  cout<<cnt<<endl;
}


Measured memory_bytes: 256
/*
      author  : nishi5451
      created : 15.08.2020 00:36:19
*/

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


int main(){
    string s;
    cin >> s;
    int l = 10*(s[0]-'0')+(s[1]-'0');
    int r = 10*(s[2]-'0')+(s[3]-'0');
    if(1<=r && r<=12 && 1<=l && l<=12){
        cout << "AMBIGUOUS" << endl;
    }
    else if(1<=l && l<=12){
        cout << "MMYY" << endl;
    }
    else if(1<=r && r<=12){
        cout << "YYMM" << endl;
    }
    else {
        cout << "NA" << endl;
    }
    return 0;
}

Measured memory_bytes: 3624
#include<stdio.h>

long henkan(long a,long b);

int main(void){
    int a,i=0;
    long b[100];
    scanf("%d",&a);
    for(i=0;i<a;i++)scanf("%ld",&b[i]);
    long ans=b[0];
      for(i=0;i<a;i++){
        ans=henkan(ans,b[i]);
      }
    
    printf("%ld\n",ans);
    return 0;
}
    
    long henkan(long a,long b){
    long c,d,i,x,y;
    
        x=a;
        y=b;

    if(a<b){
        c=a;
        a=b;
        b=c;
    }

    d=a%b;
    while(d!=0){
        a=b;
        b=d;
        d=a%b;
    }
        return x/b*y;
    }

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
typedef vector<int> vi;
typedef vector<vector<long long> > vvll;
typedef vector<pair<int, int> > vpii;
typedef pair<int, int> pii;
typedef long long ll;
typedef pair<ll, ll> pll;
#define INF 1000000000000000LL
#define MOD 1000000007
#define EPSILON 0.00001
#define f first
#define s second
#define pb push_back
#define mp make_pair
#define p_q priority_queue
 
#define FOR(i, a, b) for (int i=(a); i<=(b); i++)
#define F0R(i, a) for (int i=0; i<(a); i++)
#define RFOR(i, a, b) for (int i=(a); i >= b; i--)
 
#define MN 200005
ll l;
int n;
ll x[MN];

ll dist(int a, int b){ //from a to b, ccw
    ll d = x[b]-x[a];
    return (d+l)%l;
}

ll lps[MN];
ll rps[MN];


ll cv(int a, int k, bool il){
    if(il){
        return lps[a]-lps[a-k];
    } else{
        return rps[a]-rps[a+k];
    }
}

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

    cin >> l >> n;
    FOR(i, 1, n){
        cin >> x[i];
    }

    FOR(i, 1, n){
        lps[i] = lps[i-1]+dist(0, i);
        //cout << lps[i] << " ";
    }
    //cout << "\n";
    RFOR(i, n, 1){
        rps[i] = rps[i+1]+dist(i, 0);
        //cout << rps[i] << " ";
    }
    //cout << "\n";

    ll ans = 0;

    FOR(i, 1, n){
        int lct = i-1;
        int rct = n-i;
        //int mct = min(lct, rct);

        ll res;
        ll k;

        //lct, rct-1, so end at i from left
        k = min(lct+1, rct);
        res = (cv(i, k, true)+cv(i+1, k, false))*2-dist(0, i);
        ans = max(ans, res);

        k = min(lct, rct+1);
        res = (cv(i, k, false)+cv(i-1, k, true))*2-dist(i, 0);
        ans = max(ans, res);

        k = min(lct, rct);
        res = (cv(i-1, k, true)+cv(i+1, k, false))*2+max(dist(0, i), dist(i, 0));
        ans = max(ans, res);

        /*ll lfsm = lps[i-1]-lps[i-1-mct];
        ll rtsm = rps[i+1]-rps[i+1+mct];
        ll edis = max(dist(0, i), dist(i, 0));

        ll res = (lfsm+rtsm)*2+edis;
        cout << "at " << i << " ans is " << res << "\n";
        //ans = max(ans, res);*/
    }

    cout << ans << "\n";

    return 0;
}


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

int main(){
  double L;
  cin >> L;
  
  double a = L/3;
  
  
  
  
  // 小数点以下10桁まで
  cout << fixed << setprecision(10);
 
  cout << a*a*a << endl;
} 

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

int main(){
    int A,B,C,K;
    cin >> A >> B >> C >> K;
    int sum=0;
    bool judge=true;
    if(K<=A){
        sum+=K;
        judge=false;
    }
    else{
        sum+=A;
        K-=A;
    }
    if(judge){
        if(K<=B){
            judge=false;
        }
        else{
            K-=B;
            sum-=K;
        }
    }
    cout << sum << endl;
}

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

using namespace std;

#define ll long long
#define uint unsigned int

const int MAX = 1e5 + 5;

char prime[MAX];
int pref[MAX];

void sieve() {
    memset(prime, 1, sizeof(prime));
    prime[0] = prime[1] = 0;
    for (int i = 2; i < MAX; ++i) {
        if (prime[i] == 1) {
            for (ll j = (ll) i * i; j < MAX; j += i) {
                prime[j] = 0;
            }
        }
    }
}

int main() {
    sieve();
    for (int i = 2; i < MAX; ++i) {
        pref[i] = pref[i - 1];
        if (prime[i] == 1 && prime[(i + 1) / 2] == 1) {
            ++pref[i];
        }
    }

    int q;
    cin >> q;

    while (q --> 0) {
        int L, R;
        cin >> L >> R;
        cout << pref[R] - pref[L - 1] << '\n';
    }

    return 0;
}


Measured memory_bytes: 1152
#!/usr/bin/python3

import os
import sys


def main():
    N = read_int()
    S = inp()
    print(solve(N, S))


def solve(N, S):
    ans = []
    orda = ord('A')
    for ch in S:
        ans.append(chr((ord(ch) - orda + N) % 26 + orda))

    return ''.join(ans)


###############################################################################

DEBUG = 'DEBUG' in os.environ


def inp():
    return sys.stdin.readline().rstrip()


def read_int():
    return int(inp())


def read_ints():
    return [int(e) for e in inp().split()]


def dprint(*value, sep=' ', end='\n'):
    if DEBUG:
        print(*value, sep=sep, end=end)


if __name__ == '__main__':
    main()


Measured memory_bytes: 39792
#include<algorithm>
#include<climits>
#include<cmath>
#include<iomanip>
#include<iostream>
#include<list>
#include<map>
#include<numeric>
#include<queue>
#include<set>
#include<stack>
#include<utility>
#include<vector>

using namespace std;

#define lint long long
#define REP(i, x, n) for(int i = x ; i < n ; i++)
#define rep(i, n) REP(i, 0, n)
#define repr(i, n) for(int i = n - 1 ; i >= 0 ; i--)
#define SORT(c) sort((c).begin(), (c).end())
#define SORT_INV(c) sort((c).begin(), (c).end(), greater<int>())
#define IINF (int)(1e9+10)
#define LLINF (lint)(1e18+10)

int solve(string s, int cnt, char c){
    set<char> st;
    rep(i, s.size()){
        st.insert(s[i]);
    }
    if(!st.count(c)){
        return IINF;
    }
    if(st.size() == 1){
        return cnt;
    }
    rep(i, s.size()-1){
        if(s[i+1] == c){
            s[i] = c;
        }
    }
    s = s.substr(0, s.size() - 1);
    return solve(s, cnt+1, c);
}

int main(){
    string s;
    cin >> s;
    int ans = IINF;
    for(char c = 'a' ; c <= 'z' ; c++){
        ans = min(ans, solve(s, 0, c));
    }
    cout << ans << endl;
    return 0;
}

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

using namespace std;

typedef long long ll;

const int INF = 1e9;

class Die {
public:
  Die(vector<int> numbers) {
    vertical_ = vector<int>(4);
    horizontal_ = vector<int>(4);
    vertical_[0] = numbers[0];
    vertical_[1] = numbers[4];
    vertical_[2] = numbers[5];
    vertical_[3] = numbers[1];
    horizontal_[0] = numbers[0];
    horizontal_[1] = numbers[2];
    horizontal_[2] = numbers[5];
    horizontal_[3] = numbers[3];
  }

  int get_top() const { return vertical_[0]; }
  int get_right() const { return horizontal_[1]; }
  int get_front() const { return vertical_[3]; }
  void rotate_north()
  {
    rotate(vertical_.rbegin(), vertical_.rbegin() + 1, vertical_.rend());
    update(vertical_, horizontal_);
  }
  void rotate_south()
  {
    rotate(vertical_.begin(), vertical_.begin() + 1, vertical_.end());
    update(vertical_, horizontal_);
  }
  void rotate_east()
  {
    rotate(horizontal_.rbegin(), horizontal_.rbegin() + 1, horizontal_.rend());
    update(horizontal_, vertical_);
  }
  void rotate_west()
  {
    rotate(horizontal_.begin(), horizontal_.begin() + 1, horizontal_.end());
    update(horizontal_, vertical_);
  }

  int find_right(int top, int front)
  {
    if (find(horizontal_.begin(), horizontal_.end(), front) != horizontal_.end()) {
      while (get_top() != front) {
        rotate_east();
      }
      rotate_south();
    }
    else {
      while (get_front() != front) {
        rotate_north();
      }
    }

    while (get_top() != top) {
      rotate_east();
    }
    return get_right();
  }

private:
  int top_;
  vector<int> vertical_, horizontal_;

  void update(vector<int>& from, vector<int>& to)
  {
    to[0] = from[0]; to[2] = from[2];
  }

};

int main()
{
  vector<int> digits(6);
  for (int i = 0; i < 6; ++i) {
    fscanf(stdin, "%d", &digits[i]);
  }
  Die die(digits);
  int q;
  fscanf(stdin, "%d", &q);
  for (int i = 0; i < q; ++i) {
    int top, front;
    fscanf(stdin, "%d %d", &top, &front);
    int right = die.find_right(top, front);
    fprintf(stdout, "%d\n", right);
  }
  return 0;
}

Measured memory_bytes: 1216
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
 #define int long long

#define all(X) (X).begin(), (X).end()
#define reset(X) memset(X, 0, sizeof(X))
#define mp(a, b) make_pair(a, b)
#define pb push_back
#define endl '\n'
#define fi first
#define se second



using namespace __gnu_pbds;
using namespace std;
// const int mod=1e9+7;
 const int mod=998244353;
 // const int mod=1e9+9;
const int INF=4e18+10;
// const int INF=1e9+10;
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
template <typename T>
using ordered_multiset = tree<T, null_type, less_equal<T>, rb_tree_tag, tree_order_statistics_node_update>;

#define read(n) int n; cin>>n;
#define readv(x, n) vector<int> x(n); for(auto &i:x) cin>>i;

template<typename T1,typename T2>
void set_min(T1& a, T2 b)
{
    a=min(a, (T1)b);
}


int multiply(int a, int b, int in_mod){return (a*b)%in_mod;}
int mult_identity(int a){return 1;}


auto power(auto a, int b, int in_mod)
{
    auto prod=mult_identity(a);
    auto mult=a%in_mod;
    while(b!=0)
    {
        if(b%2)
        {
            prod=multiply(prod,mult, in_mod);

        }
        mult=multiply(mult, mult,in_mod);
        b/=2;
    }
    return prod;
}
int mod_inv(int q, int in_mod)
{

    return power(q, in_mod-2,in_mod);
}


const int MAXN=1e6+100;
void solve()
{
    int n;
    cin>>n;
    int k;
    cin>>k;
    readv(a,n);
    for(auto &i:a)
        i-=k;

    vector<int> pref(n+1);
    for(int i=1;i<=n;i++)
        pref[i]=pref[i-1]+ a[i-1];

    //count number of inversion
    int ans=0;
    ordered_multiset<int> cnt;
    cnt.insert(0);
    for(int i=1;i<=n;i++)
    {
        ans+=cnt.order_of_key(pref[i]+1);
        cnt.insert(pref[i]);
    }
    cout<<ans<<endl;


}
signed main()

{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    #ifndef ONLINE_JUDGE
    if(fopen("INPUT.txt","r"))
    {
        freopen ("INPUT.txt" , "r" , stdin);
        freopen ("OUTPUT.txt" , "w" , stdout);
    }
    #endif
    auto clk=clock();
    mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
    // -------------------------------------Code starts here---------------------------------------------------------------------

    int t=1;
    // cin>>t;
    for(int test=1;test<=t;test++)
    {
        // cout<<"Case #"<<test<<": ";
        // cout<<endl;
        solve();
        // cout<<endl;

    }

    // -------------------------------------Code ends here------------------------------------------------------------------


    clk = clock() - clk;
    cerr << fixed << setprecision(6) << "Time: " << ((double)clk)/CLOCKS_PER_SEC << "\n";
    return 0;
}


Measured memory_bytes: 15872
import math

def comb(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))
  
N, K = map(int, input().split())
s = (10 ** 9) + 7
n = N - K + 1

if N >= 2 * K -1:
  for i in range(1, K+1):
    S = (i * comb(n, i) * comb(K, i)) // K
    print(S % s)
else:
  for i in range(1, N-K+2):
      S = (i * comb(n, i) * comb(K, i)) // K
      print(S % s)
  for i in range(N-K+2, K+1):
      print(0)

Measured memory_bytes: 63320
program name
    use,intrinsic :: iso_fortran_env
    implicit none
    integer(int64):: n,i,j,k,cnt(5),ans
    character(10),allocatable:: s(:)
    character(5),parameter:: march = 'MARCH'
    character(1):: initial

    read*, n
    allocate(s(n))
    cnt(:) = 0
    do i=1,n
        read*, s(i)
        initial = s(i)(1:1)
        do j=1,5
            if (initial == march(j:j)) then
                cnt(j)=cnt(j)+1
                exit
            end if
        end do
    end do
    ans=0
    do i=1,3
        do j=i+1,4
            do k=j+1,5
                ans=ans+cnt(i)*cnt(j)*cnt(k)
            end do
        end do
    end do
    print'(i0)', ans
contains
subroutine swap(x,y)
    integer(int64):: x,y,t
    t=x;x=y;y=t
end subroutine
end program name

Measured memory_bytes: 1152
import sys
from collections import deque
from collections import defaultdict
import math
sys.setrecursionlimit(20000000)
input = sys.stdin.readline
n,m = map(int,input().split())
a = [int(input()) for i in range(m)]
a = set(a)
mod = 10**9+7
dp = [0]*(n+5)
dp[0] = 1
for i in range(1,n+1):
        if i in a:
                continue
        dp[i] = dp[i-1] + dp[i-2]
        dp[i] %= mod
print(dp[n]%mod)


Measured memory_bytes: 50140
#include<iostream>
#include<cstdio>
using namespace std;
#define MAX 100100
inline int read()
{
	int x=0;bool t=false;char ch=getchar();
	while((ch<'0'||ch>'9')&&ch!='-')ch=getchar();
	if(ch=='-')t=true,ch=getchar();
	while(ch<='9'&&ch>='0')x=x*10+ch-48,ch=getchar();
	return t?-x:x;
}
struct Line{int v,next;}e[MAX<<1];
int h[MAX],cnt=1;
inline void Add(int u,int v){e[cnt]=(Line){v,h[u]};h[u]=cnt++;}
int n,sg[MAX],vis[MAX];
void dfs(int u,int ff)
{
	for(int i=h[u];i;i=e[i].next)
		if(e[i].v!=ff)dfs(e[i].v,u),sg[u]^=sg[e[i].v]+1;
}
int main()
{
	n=read();
	for(int i=1;i<n;++i)
	{
		int u=read(),v=read();
		Add(u,v);Add(v,u);
	}
	dfs(1,0);
	puts(sg[1]?"Alice":"Bob");
	return 0;
}


Measured memory_bytes: 7296
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

/**
 * Exit Survey
 */
public class Main {

	public static void main(String[] args) throws IOException {

		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String line = "";

		while ((line = br.readLine()) != null && !line.isEmpty()) {
			int n = Integer.parseInt(line);
			long sum = 0;
			for (int i = 0; i < n; i++) {
				sum += Integer.parseInt(br.readLine());
			}
			System.out.println(sum / n);
		}
	}
}

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

int main(){
    int x;
    cin>>x;
    int q = x/100;
    int r = x%100;
    if(q==0){
        cout << 0<<endl;
        return 0;
    }
    if(r>q*5){
        cout << 0<<endl;
        return 0;
    }
    else{
        cout << 1<<endl;
        return 0;
    }
}

Measured memory_bytes: 256
import kotlin.math.max

fun main() {
    val (n, m, k) = readLine()!!.split(" ").map { it.toInt() }
    val a = readLine()!!.split(" ").map { it.toInt() }
    val b = readLine()!!.split(" ").map { it.toInt() }

    val sa = Array(n + 1) { 0L }
    for (i in 0 until n) sa[i + 1] = sa[i] + a[i]

    val sb = Array(m + 1) { 0L }
    for (i in 0 until m) sb[i + 1] = sb[i] + b[i]

    var best = -1
    for (ca in 0..n) {

        val rest = k - sa[ca]
        if (rest < 0) continue

        var cb = sb.binarySearch(rest)
        if (cb < 0) cb = -cb - 2

        best = max(best, ca + cb)
    }

    println(best)
}

Measured memory_bytes: 94260
n, k = map(int, input().split())
h = list(map(int, input().split()))
cost = [float('inf') for i in range(n)]
cost[0] = 0
for i in range(1,n):
    for j in range(1, k+1):
        if i >= j:
            cost[i] = min(cost[i], cost[i-j]+abs(h[i]-h[i-j]))

print(cost[n-1])


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

using namespace std;
#define BUF (1000)
#define ll long long 

int n;
int a[3];

int ans = 0;
int odd;

int main(void){

	cin >> a[0] >> a[1] >> a[2];

	sort(a,a+3);

	int mx = a[2];

	ans += (mx-a[0])/2;
	if((mx-a[0])%2==1) odd++;

	ans += (mx-a[1])/2;
	if((mx-a[1])%2==1) odd++;

	//cout << ans << odd;

	if(odd == 1) ans+=2;
	if(odd == 2) ans++;

	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 256
def solve(n, c_str):
    cum_sum_w_left = [0] * (n + 1)
    cum_sum_r_right = [0] * (n + 1)
    # cum_sum_w_left
    cum_sum_w = 0
    for i in range(n):
        if c_str[i] == "W":
            cum_sum_w += 1
        cum_sum_w_left[i + 1] = cum_sum_w
    # cum_sum_r_right
    cum_sum_r = 0
    for i in range(n - 1, -1, -1):
        if c_str[i] == "R":
            cum_sum_r += 1
        cum_sum_r_right[i] = cum_sum_r
    # print(cum_sum_w_left)
    # print(cum_sum_r_right)
    res = n + 1
    for i in range(n + 1):
        res = min(res, max(cum_sum_w_left[i], cum_sum_r_right[i]))
    # print(res)
    return res


def main():
    n = int(input())
    c_str = input()
    res = solve(n, c_str)
    print(res)


def test():
    assert solve(4, "WWRR") == 2
    assert solve(2, "RR") == 0
    assert solve(8, "WRWWRWRR") == 3


if __name__ == "__main__":
    test()
    main()


Measured memory_bytes: 18824
#include<bits/stdc++.h>
typedef long long ll;
typedef unsigned long long ull;
using namespace std;
#define pb push_back
int dy[]={0, 0, 1, -1, 1, 1, -1, -1};
int dx[]={1, -1, 0, 0, 1, -1, -1, 1};

#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define REP(i,n) for (int i=0;i<(n);i++)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)
#define mp make_pair
#define fi first
#define sc second
int n,k,c[11];
bool al[11];
set<int> se;
void search(int d,int s){
    if(d >= k){
        se.insert(s);
        return;
    }
    REP(i,n){
        if(!al[i]){
            al[i] = true;
            int t = s * 10;
            if(c[i] > 9) t *= 10;
            search(d + 1,t + c[i]);
            al[i] = false;
        }
    }
}
bool solve(){
    cin >> n >> k;
    if(n == 0 && k == 0)
        return false;
    se.clear();
    REP(i,n)
        cin >> c[i];
    REP(i,n)
        al[i] = false;

    search(0,0);
    printf("%d\n",se.size());
    return true;
}
int main(){
    while(solve());
    return 0;
}

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

typedef long long ll;
#define REP(i, n, m) for(int i = n; i < m; i++)
#define REPR(i, n, m) for(int i = n; i >= m; i--)
#define LREP(i, n, m) for(ll i = n; i < m; i++)
#define LREPR(i, n, m) for(ll i = n; i >= m; i--)

#define P pair<int, int >


const int INF = 1e9 + 1;
const int MOD = 1e9 + 7;



//---functions---//
int gcd(int a, int b){
    if(a < b) swap(a, b);
    return b?gcd(b, a%b):a;
}

int s2i(string num){stringstream ss; ss << num << flush; int n; ss >> n; return n;}
string i2s(int n){stringstream ss; ss << n << flush; return ss.str();}

bool firstCompare(const P& firstElof, const P& secondElof){
    return firstElof.first < secondElof.first;
}
bool secondCompare(const P& firstElof, const P& secondElof){
    return firstElof.second < secondElof.second;
}
//---------------//
//-----class-----//
class UnionFind{
    public:
        vector<ll> par; //parents
        vector<ll> siz; // sizes of set
        vector<ll> rank; // rank of each element 
    UnionFind(ll n): par(n), siz(n, 1LL), rank(n){
        LREP(i, 0, n) par[i] = i;
    }
    //initialization
    /*
    void init(ll n){
        par.assign(n);
        siz.assign(n, 1LL);
        rank.assign(n);
        LREP(i, 0, n) par[i] = i;
    }
    */

    // find the root of x
    ll find(ll x){
        if(par[x] == x) return x;
        else return par[x] = find(par[x]);
    }

    //Unite two set including x or y
    void unite(ll x, ll y){
        x = find(x);
        y = find(y);
        if(x == y) return;
        if(rank[x] < rank[y]){
            par[x] = y;
            siz[y] += siz[x];
        }else{
            par[y] = x;
            siz[x] += siz[y];
            if(rank[x] == rank[y]) rank[x]++;
        }
    }

    //Do x and y belong to the same set?
    bool issame(ll x, ll y){
        return find(x) == find(y);
    }

};

int count_happyer(string s, int l, int r){
    int count = 0;
    REP(i, 0, s.size()){
        if(i - 1 >= 0 && s[i] == 'L' && s[i-1] == 'L') ++count;
        else if(i <= (s.size() - 2) && s[i] == 'R' && s[i+1] == 'R') ++count;
    }
    return count;
}
int N, K;
int main(){
    cin.tie(0);
    cout.tie(0);
    ios::sync_with_stdio(false);
    cin >> N >> K;
    string S;
    cin >> S;
    int happyer = count_happyer(S, 0, N - 1);
    int un_happyer = N - happyer;
    //cout << "happer : " << happyer << ", unhapper : " << un_happyer << '\n';
    cout << min(2 * K, un_happyer - 1) + happyer << '\n'; 

}


Measured memory_bytes: 512
#[macro_export]
macro_rules !read_value {($iter :expr ,($($t :tt ) ,*) ) =>{($(read_value !($iter ,$t ) ) ,*) } ;($iter :expr ,[$t :tt ;$len :expr ] ) =>{(0 ..$len ) .map (|_ |read_value !($iter ,$t ) ) .collect ::<Vec <_ >>() } ;($iter :expr ,{$t :tt =>$f :expr } ) =>{$f (read_value !($iter ,$t ) ) } ;($iter :expr ,chars ) =>{read_value !($iter ,String ) .chars () .collect ::<Vec <char >>() } ;($iter :expr ,usize1 ) =>{read_value !($iter ,usize ) -1 } ;($iter :expr ,$t :ty ) =>{$iter .next () .unwrap () .parse ::<$t >() .unwrap () } ;}
#[macro_export]
macro_rules !input_inner {($iter :expr ) =>{} ;($iter :expr ,) =>{} ;($iter :expr ,mut $var :ident :$t :tt $($r :tt ) *) =>{let mut $var =read_value !($iter ,$t ) ;input_inner !{$iter $($r ) *} } ;($iter :expr ,mut $var :ident $($r :tt ) *) =>{input_inner !{$iter ,mut $var :usize $($r ) *} } ;($iter :expr ,$var :ident :$t :tt $($r :tt ) *) =>{let $var =read_value !($iter ,$t ) ;input_inner !{$iter $($r ) *} } ;($iter :expr ,$var :ident $($r :tt ) *) =>{input_inner !{$iter ,$var :usize $($r ) *} } ;}
#[macro_export]
macro_rules !input {(source =$s :expr ,$($r :tt ) *) =>{let mut iter =$s .split_whitespace () ;input_inner !{iter ,$($r ) *} } ;(iter =$iter :ident ,$($r :tt ) *) =>{let s ={use std ::io ::Read ;let mut s =String ::new () ;std ::io ::stdin () .read_to_string (&mut s ) .unwrap () ;s } ;let mut $iter =s .split_whitespace () ;input_inner !{$iter ,$($r ) *} } ;($($r :tt ) *) =>{let s ={use std ::io ::Read ;let mut s =String ::new () ;std ::io ::stdin () .read_to_string (&mut s ) .unwrap () ;s } ;let mut iter =s .split_whitespace () ;input_inner !{iter ,$($r ) *} } ;}
fn main() {
    #[allow(unused_imports)]
    use std::io::Write as _;
    let __out = std::io::stdout();
    #[allow(unused_mut, unused_variables)]
    let mut __out = std::io::BufWriter::new(__out.lock());
    #[allow(unused_macros)]
    macro_rules !print {($($arg :tt ) *) =>(::std ::write !(__out ,$($arg ) *) .unwrap () ) }
    #[allow(unused_macros)]
    macro_rules !println {($($arg :tt ) *) =>(::std ::writeln !(__out ,$($arg ) *) .unwrap () ) }
    #[allow(unused_macros)]
    macro_rules! echo {
        ($iter :expr ) => {
            echo!($iter, "\n")
        };
        ($iter :expr ,$sep :expr ) => {
            let mut iter = $iter;
            if let Some(item) = iter.next() {
                print!("{}", item);
            }
            for item in iter {
                print!("{}{}", $sep, item);
            }
            println!();
        };
    }
    input!(n);
    let mut ans = n * (n + 1) / 2;
    for i in 2..=n {
        for j in (i..=n).step_by(i) {
            ans += j;
        }
    }
    println!("{}", ans);
}


Measured memory_bytes: 2140
#include<bits/stdc++.h>
#include<string>
using namespace std;
int main()
{
    int a,b,c;
    cin>>a>>b>>c;
    if(a==b && b==c){cout<<1;}
    else if(a==b || a==c || b==c){cout<<2;}
    else{cout<<3;}

}


Measured memory_bytes: 3572
import std.algorithm;
import std.array;
import std.conv;
import std.math;
import std.range;
import std.stdio;
import std.string;
import std.typecons;

alias T = Tuple!(int, int);

void main() {
  immutable n = readln.strip.to!int;
  long res;
  int[4] c;
  foreach (qid; 0 .. n) {
    auto s = readln.strip;
    int t1 = (s.back == 'A') ? 1 : 0;
    int t2 = (s.front == 'B') ? 1 : 0;
    foreach (i; 1 .. s.length) {
      if (s[i-1] == 'A' && s[i] == 'B') ++res;
    }
    c[t1 * 2 + t2]++;
  }
  while (c[2]) {
    c[2]--;
    if (c[1]) {
      c[1]--;
      res++;
    }
    if (c[3]) {
      res += c[3];
      c[3] = 0;
    }
  }
  if (c[3]) {
    res += c[3] - 1;
    if (c[1]) {
      c[1]--;
      res++;
    }
  }
  writeln (res);
}



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

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

#define sf scanf
#define pf printf
#define pb push_back
#define mp make_pair
#define PI ( acos(-1.0) )
#define mod 1000000007LL
#define IN freopen("C.in","r",stdin)
#define OUT freopen("output.txt","w",stdout)
#define FOR(i,a,b) for(i=a ; i<=b ; i++)
#define DBG pf("Hi\n")
#define INF 1000000000
#define i64 long long int
#define eps (1e-8)
#define xx first
#define yy second
#define ln 17
#define off 2

using namespace __gnu_pbds;
using namespace std ;

typedef tree< i64, null_type, less<i64>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
typedef pair<i64, i64> pii;

#define maxn 1005

vector <int> Do( int n , deque<int> dqAns )
{
    vector <int> ans ;
    deque<int> dq ;
    for(int i=1 ; i<=n ; i++) dq.push_back(i) ;
    while( dq.front() != dqAns.front() )
    {
        ans.pb(1) ;
        dq.pop_front() ;
    }
    while( dq.back() != dqAns.back() )
    {
        ans.pb( (int)dq.size() ) ;
        dq.pop_back() ;
    }

    if( dq.size() == 1 ) return ans ;

    while( dq.size() > 1 )
    {
        if( dq[2] == dqAns[1] )
        {
            ans.pb( 2 ) ;
            dq.pop_front() ;
            dq.pop_front() ;
            dqAns.pop_front() ;
            continue ;
        }
        else{
            ans.pb( 3 ) ;
            dq.pop_front() ;
            dq.pop_front() ;
            dq.pop_front() ;
            dq.push_front( dqAns.front() ) ;
        }
    }
    return ans ;
}

i64 a[maxn] ;
i64 dp[maxn] ;
int Next[maxn] ;

int main()
{
    int n ;

    scanf("%d",&n) ;

    for(int i=1 ; i<=n ; i++)
    {
        scanf("%lld",&a[i]) ;
    }

    for(int i=1 ; i<=n ; i++)
    {
        dp[i] = a[i] ;
        Next[i] = i ;
        for(int j=i-2 ; j>=1 ; j-=2)
        {
            if( dp[j] + a[i] > dp[i] )
            {
                dp[i] = dp[j] + a[i] ;
                Next[i] = j ;
            }
        }
    }

    i64 ans = a[1] ;
    int idx = 1 ;

    for(int i=1 ; i<=n ; i++)
    {
        if( dp[i] > ans )
        {
            ans = dp[i] ;
            idx = i ;
        }
    }

    deque <int> dq ;

    while( 1 )
    {
        dq.push_front( idx ) ;
        if( Next[idx] == idx ) break ;
        idx = Next[idx] ;
    }

    printf("%lld\n",ans) ;
 //   for(int i=0 ; i<dq.size() ; i++) printf("%d ",dq[i]) ;
 //   printf("\n") ;

    vector <int> res = Do(n,dq) ;
    printf("%d\n" , (int)res.size() ) ;

    for( auto val : res ) printf("%d\n",val) ;

    return 0 ;
}


Measured memory_bytes: 256
/**************************
*                         *
*  Nothing Is Impossible  *
*                         *
**************************/
#include <algorithm>
#include <pthread.h>
#include <iostream>
#include <fstream>
#include <ctype.h>
#include <string>
#include <vector>
#include <thread>
#include <math.h>
#include <queue>
#include <stack>
#include <tuple>
#include <cmath>
#include <set>
#include <map>
#define GetRand(Min, Max) ((rand()%(int)(((Max) + 1)-(Min))) + (Min))
#define Rep(i, min, max) for(int64_t i = min; i < max; ++i)
#define PB push_back
#define MP make_pair
typedef long long ll;
typedef long double ld;
using namespace std;

void solve(){
	ll a,b,c,k;	cin >> a >> b >> c >> k;
	ll ans = 0;
	if(k > 0){
		ans += (a>k?k:a);
		k -= (a>k?k:a);
	}
	if(k > 0){
		k -= (b>k?k:b);
	}
	if(k > 0){
		ans -= (c>k?k:c);
		k -= (c>k?k:c);
	}
	cout << ans << endl;
}

int main(){
    ios::sync_with_stdio(NULL);
    cin.tie(NULL); cout.tie(NULL);
    int t = 1;
    //int t;  cin >> t;
    while(t--){
        solve();
    }
    return 0;
}

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

int main() {
    std::map<char, char> mp;
    mp['A'] = 'T';
    mp['C'] = 'G';
    mp['T'] = 'A';
    mp['G'] = 'C';

    
    char c;
    
    cin >> c;
    cout << mp[c] << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <set>
#include <algorithm>
#include <array>
#include <complex>
#include <utility>
#include <map>
int needleX[4] = { -1,0,1,0 };
int needleY[4] = { 0,1,0,-1 };

int main(void) {
    int h, w, n;
    std::cin >> n;
    std::vector<int> c(n),S(n),F(n);
    for(int i=0;i<n-1;i++){
        std::cin >> c[i] >> S[i] >> F[i];
    }
    for(int i=0;i<n;i++){
        int t=0;
        for(int j=i;j<n-1;j++){
            if(t<S[j]){
                t=S[j];
            }else if(t%F[j]==0){
                
            }else{
                t=t+F[j]-(t%F[j]);
            }
            t+=c[j];
        }
        std::cout << t << std::endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
using namespace  std;
int a, b,c, d;
int main() {
	cin >> a >> b>>c>>d;
	if ((((a - b <= d && a - b >= 0) || (b - a <= d && b - a >= 0)) && ((b - c <= d && b - c >= 0) || (c - b <= d && c - b >= 0))) || ((a - c <= d && a - c >= 0) || (c - a <= d && c - a >= 0))) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}
	int x; cin >> x;
	return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <map>
#include <vector>

using namespace std;

int main() {
  vector<vector<int>> c(3, vector<int>(3, 0));
  for (int i = 0; i < 3; i++) {
    for (int j = 0; j < 3; j++) {
      cin >> c[j][i];
    }
  }

  for (int a0 = 0; a0 <= 100; a0++) {
    for (int b0 = 0; b0 <= 100; b0++) {
      int a[3], b[3];
      int a1 = c[1][0] - b0;
      int a2 = c[2][0] - b0;
      int b1 = c[0][1] - a0;
      int b2 = c[0][2] - a0;
      a[0] = a0;
      a[1] = a1;
      a[2] = a2;
      b[0] = b0;
      b[1] = b1;
      b[2] = b2;
      bool is_ok = true;
      for (int i = 0; i < 3; i++) {
        for (int j = 0; j < 3; j++) {
          if (a[i] + b[j] != c[i][j]) {
            is_ok = false;
          }
        }
      }
      if (is_ok) {
        cout << "Yes" << endl;
        return 0;
      }
    }
  }

  cout << "No" << endl;

  return 0;
}

Measured memory_bytes: 256
N = int(input())
cordinates = [list(map(int, input().split())) for i in range(N)]

for t, x, y in cordinates:
    # x+yは時刻t毎に偶奇が入れ替わる
    if (x+y) > t or ((x+y) % 2 != t % 2):
        print('No')
        exit()
print('Yes')

Measured memory_bytes: 27300
import collections
N,C,K=map(int,input().split())
T=[int(input()) for i in range(N)]
T.sort()

count=1
cus=0
pre=T[0]
for t in T:
    if C>cus and pre+K>=t:
        cus+=1
    else:
        cus=1
        pre=t
        count+=1
print(count)


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

int main()
{
  int K, A, B, l=0;
  cin>>K;
  cin>>A>>B;
  for(int i=A; i<=B; i++)
  {
    if(i%K==0)
    {
      cout<<"OK";
      break;
    }
    else
      l++;
  }
  if(l==(B-A+1))
    cout<<"NG";
  return 0;
}

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

int main(){
  int n,k;
  string s;

  cin >> n >> s >> k;

  for(int i = 0; i < n;i++){
    if(s[i] == s[k-1]){
      cout << s[i];
    }
    else{
      cout << "*";
    }
  }

  cout << endl;

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <math.h>
#define _GLIBCXX_DEBUG
using namespace std;
int main() {
  
  vector<int> vec(3);
  cin>>vec[0]>>vec[1]>>vec[2];
  
  sort(vec.begin(),vec.end());
  
  if(vec[0]+vec[1]==vec[2]){
    cout<<"Yes"<<endl;
  }
  else{
    cout<<"No"<<endl;
  }
}

Measured memory_bytes: 3596
from math import ceil

n, k = map(int, input().split())
a = [int(x) for x in input().split()]

left = 0
right = max(a)

while right - left > 1:
    length = (right + left) // 2
    totcut = 0
    for i in range(n):
        totcut += ceil(a[i]/length) - 1
        if totcut > k:
            left = length
            break
    else:
        right = length
print(right)


Measured memory_bytes: 94356