akhauriyash/Code-Regression huggingface dataset:
#include <iostream> // cout, endl, cin
#include <cmath> //sqrt pow
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // dequef
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#define rep(i,n) for(int i = 0; i < n; i++)
#define vi vector<int>
#define vvi vector<vi>
#define pii pair<int, int>
#define all(a) (a).begin(), (a).end()
#define mod 1000000007
using ll = long long;
using namespace std;
int main(){
  int n;
  cin >> n;
  vector<ll> a(n), rui(n);
  rep(i, n) cin >> a[i];
  rep(i, n) rui[i] = a[i];
  for(int i = n - 2; i >= 0; i--){
    rui[i] += rui[i + 1];
    rui[i] %= mod;
  }
  ll ans = 0;
  rep(i, n - 1){
    ans += (a[i] * rui[i + 1]) % mod;
    ans %= mod;
  }
  cout << ans << endl;
}

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

using Size = int;
using Vertex = int;
using Weight = long long;
struct Edge {Vertex from, to; Weight weight;};
using Graph = vector<vector<Edge>>;

Vertex farthest(const Graph& G, Vertex v) {
  vector<Weight> d(G.size());
  function<Vertex(Vertex, Vertex)> dfs = [&](Vertex cur, Vertex pre) {
    auto res = cur;
    for(const auto& e: G[cur]) if(e.to != pre) {
      auto nex = dfs(e.to, e.from);
      auto w = e.weight + d[e.to];
      if(w <= d[cur]) continue;
      d[cur] = w;
      res = nex;
    }
    return res;
  };
  return dfs(v, -1);
}

vector<Vertex> path(auto G, auto b, auto e) {
  vector<Vertex> res;
  function<bool(Vertex, Vertex)> dfs = [&](Vertex cur, Vertex pre) {
    res.emplace_back(cur);
    if(cur == e) return true;
    for(auto e: G[cur]) if(e.to != pre) if(dfs(e.to, e.from)) return true;
    res.pop_back();
    return false;
  };
  dfs(b, -1);
  return res;
}

vector<int> leg(auto G) {
  auto u = farthest(G, 0);
  auto v = farthest(G, u);
  auto p = path(G, u, v);
  vector<int> res;
  for(auto i: p) {
    res.emplace_back(G[i].size() - 2);
    if(i==u || i==v) res.back() += 1;
  }
  return res;
}

vector<int> build(auto v) {
  vector<int> res;
  auto i = 1;
  for(auto n: v) {
    auto d = i++;
    while(n--) res.emplace_back(i++);
    res.emplace_back(d);
  }
  return res;
}

vector<int> solve(auto G) {
  auto deg = leg(G);
  if(accumulate(begin(deg), end(deg), 0) + deg.size() != G.size()) return {-1};
  auto a = build(deg);
  reverse(begin(deg), end(deg));
  auto b = build(deg);
  return min(a, b);
}

int main() {
  int N;
  cin >> N;
  Graph G(N);
  for(auto i=1; i<N; ++i) {
    int v, w;
    cin >> v >> w;
    --v; --w;
    G[v].push_back({v, w, 1});
    G[w].push_back({w, v, 1});
  }

  auto P = solve(G);
  for(auto i: P) cout << (i==P.front() ? "" : " ") << i;
  cout << endl;
}


Measured memory_bytes: 37616
#[allow(unused_imports)]
use std::char::*;
#[allow(unused_imports)]
use std::cmp::*;
#[allow(unused_imports)]
use std::collections::*;

#[allow(unused_macros)]
macro_rules! debug {($($a:expr),*) => {println!(concat!($(stringify!($a), " = {:?}, "),*), $($a),*);}}
#[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" ) } ; }

#[derive(PartialEq, PartialOrd)]
pub struct Total<T>(pub T);
impl<T: PartialEq> Eq for Total<T> {}
impl<T: PartialOrd> Ord for Total<T> { fn cmp(&self, other: &Total<T>) -> std::cmp::Ordering { self.0.partial_cmp(&other.0).unwrap() }}

#[allow(dead_code)]
const MAX:usize = 100006;
#[allow(dead_code)]
const INF_U32:u32 = 1 << 31;
#[allow(dead_code)]
const INF_I32:i32 = 1 << 30;
#[allow(dead_code)]
const INF_U64:u64 = 1 << 63;
#[allow(dead_code)]
const INF_I64:i64 = 1 << 62;
#[allow(dead_code)]
const MOD:i64 = 1e9 as i64 + 7;


fn main() {
    input!{n:usize,s:chars};
    let mut cnt = 0;
    let mut ans = 0;
    for i in 0..n {
        cnt += match s[i] { 'I' => 1, 'D' => -1, _ => 0};
        ans = max(ans, cnt);
    }
    println!("{}", ans);
}


Measured memory_bytes: 4352
#include <iostream>
#include <string>
#include <unordered_map>
#include <stdio.h>
#include <list>
#include <vector>
#include <algorithm>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; ++i)
typedef long long ll;

int main()
{
	int n;
	cin >> n;
	unordered_map<string , bool> hash;
	rep(i,n)
	{
		string s;
		cin>>s;string e;cin>>e;
		if(s=="insert")
		{
			
			hash[e]=true;
		}
		else
		{
			if(hash[e]==true)
			{
				cout<<"yes"<<endl;
			}
			else
			{
				cout<<"no"<<endl;
			}
		}
	}
	return 0;
}


Measured memory_bytes: 49748
#include <cstdio>
#include <vector>
using namespace std;

int n, m;

void solve(){
  vector<int> v;
  for(int i=1; i<=n; ++i){
    v.push_back(i);
  }
  while(v.size()!=1){
    for(int j=1; j<=m; ++j){
      int k=v[0];
      v.erase(v.begin());
      if(j!=m)
	v.push_back(k);
    }
  }
  printf("%d\n", v[0]);
}

int main(){
  while(scanf("%d %d", &n, &m), n){
    solve();
  }
}

Measured memory_bytes: 1064
#include<iostream>
using namespace std;
typedef long long ll;
int main()
{
	ll a;
	while(cin>>a)
	{
		ll ans;
		if(a%2==0)
		ans=a/2*(a-1);
		else ans=(a-1)/2*a;
		cout<<ans<<endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include <iostream>

int main() {
	long n, m;
	std::cin >> n >> m;

	long cnt = 0;

	if (n * 2 <= m) {
		std::cout << n + (m - n * 2) / 4 << std::endl;
	}
	else {
		std::cout << m / 2 << std::endl;

	}



}

Measured memory_bytes: 256
import java.io.*;
import java.text.*;
import java.util.*;
 
public class Main {
	static Scanner sc = new Scanner(System.in);
	public static void main(String[] args) {
		int array[]= new int[5];
		int pos = 0;
		int low = 9;
		for (int i = 0; i < 5; i++) {
			array[i] = sc.nextInt();
			int target = array[i] % 10;
			if (target!= 0 && low > target) {
				low = target;
				pos = i;
			}
		}
		
		int sum = 0;
		for (int i = 0; i < 5; i++) {
			if (i != pos) {
				sum += array[i];
			}
			if ((sum % 10) != 0) {
				sum = (10 - (sum % 10)) + sum ;
			}
		}
		sum += array[pos];
		System.out.println(sum);
	}
}

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

int main()
{
  int a,b,k;
  bool c=false;
  cin >> k;
  cin >> a >> b; 
  for( ; a<=b; a++)
  {
    if(a%k==0)
    {
    	c=true;
    }
  }
  if(c)
  cout << "OK" << endl;
  else
  cout << "NG" << endl ;
}


Measured memory_bytes: 3592
#include<iostream>
#include<cstdio>
#include<cmath>
#include<algorithm>
#include<cstring>
#define ll long long
#define re register
using namespace std;
struct ios{
	template <typename ty> inline ios& operator >> (ty &x)
	{
		register int f=1;x=0;register char c=getchar();
		for(;c<'0'||c>'9';c=getchar()) if(c=='-') f=-1;
		for(;c>='0'&&c<='9';c=getchar()) x=(x<<1)+(x<<3)+(c^48);
		x*=f;return *this;
	}
	template <typename ty>  inline ios& operator << (ty x)
	{
		if(x<0) x=-x,putchar('-');
		if(x>9) *this << x/10;
		putchar(x%10+48);
		return *this;
	}
	inline ios& operator << (char c){putchar(c);return *this;}
}io;
char s[200000];
int a[200000];
int b[200000];
int main()
{
	scanf("%s",s+1);
	int n = strlen(s+1);
	for(int i=1;i<=n;i++) 
	{
		if(s[i]=='R') a[i] = a[i-1]+1;
//		printf("%d ",a[i]);
	}
	for(int i=n;i>=1;i--) 
	{
		if(s[i]=='L') b[i] = b[i+1]+1;
	}	
//	puts("");
//	for(int i=1;i<=n;i++) printf("%d ",b[i]);puts("");
	for(int i=1;i<=n;i++)
	{
		if(s[i]=='R' && s[i+1]=='L')
		{
			int tot = a[i]+b[i+1];
			if(tot%2==0)
				printf("%d %d ",tot/2,tot/2);
			else if((a[i]-1)%2==0) 
				printf("%d %d ",tot/2+1,tot/2);
			else
				printf("%d %d ",tot/2,tot/2+1);
			i++;
		}
		else printf("0 ");
	}
}

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

int main()
{
	string b;

	cin >> b;

	if (b == "A") {
		cout << "T" << endl;
	}

	else if(b == "T") {
		cout << "A" << endl;
	}

	else if (b == "C") {
		cout << "G" << endl;
	}

	else {
		cout << "C" << endl;
	}

	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
const ll MAX=1000000000000000000;
int main() {
  int n; cin >> n;
  ll a, x=1;
  bool b=false;
  for(int i=0; i<n; i++){
    cin >> a;
    if(a==0) {cout << "0"; return 0;}
    if(x>MAX/a) {b=true; continue;}
    else x*=a;
  }
  if(b) cout << "-1";
  else cout << x;
  return 0;
}

Measured memory_bytes: 3620
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define ll long long
#define ld long double
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
using P=pair<long long,long long>;
#define rep(i,n) for(long long i=0; i<(long long)n; i++)
#define req(i,n) for(long long i=n-1; i>=0; i--)
#define range(i,a,b) for(long long i=a; i<b; i++)
#define all(x) (x).begin(), (x).end()
#define sz(x) ((long long)(x).size())
#define COUT(x) cout << x << endl
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define onBoard(y,x) (y>=0 && y<h && x>=0 && x<w)
#define pri_que priority_queue
#define vint vector<int>
#define vvint vector<vector<int>>
#define vi vector<int>
#define vvi vector<vector<int>>
#define vs vector<string>
#define vvc vector<vector<char>>
#define vc vector<char>
#define vp vector<pair<int,int>>
#define vb vector<bool>
#define vvb vector<vector<bool>>
#define show(x) cout<<#x<<"="<<x<<endl;
#define SUM(x) accumulate(x.begin(),x.end(),0)
#define MAX(x) *max_element(x.begin(),x.end())
#define MIN(x) *min_element(x.begin(),x.end())
#define couty cout<<"Yes"<<endl
#define coutn cout<<"No"<<endl
#define coutY cout<<"YES"<<endl
#define coutN cout<<"NO"<<endl
#define yn(x) cout<<(x?"Yes":"No")<<endl
#define YN(x) cout<<(x?"YES":"NO")<<endl
long long gcd(long long a,long long b){return b?gcd(b,a%b):a;}
long long lcm(long long a, long long b){return a/gcd(a,b)*b;}
const long long dx[8]={1,0,-1,0,1,-1,-1,1};
const long long dy[8]={0,1,0,-1,1,1,-1,-1};
const long long INF = 1e15;
const long long MOD = 1e9+7;

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

    int n; cin >> n;
    vi x(n),y(n),z(n),w(n);
    rep(i,n){
        cin >> x[i] >> y[i];
        z[i]=x[i]+y[i];
        w[i]=x[i]-y[i];
    }

    cout<<max(MAX(z)-MIN(z),MAX(w)-MIN(w))<<endl;





}

Measured memory_bytes: 9492
package main

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

var sc = bufio.NewScanner(os.Stdin)

func scanInt() int {
	sc.Scan()
	num, e := strconv.Atoi(sc.Text())
	if e != nil {
		log.Fatal(e)
	}
	return num
}

func bubbleSort(target []int) ([]int, int) {
	flag := true
	counter := 0
	for flag {
		flag = false
		for i := len(target) - 1; i > 0; i-- {
			if target[i] < target[i-1] {
				tmp := target[i]
				target[i] = target[i-1]
				target[i-1] = tmp
				counter++
				flag = true
			}
		}
	}
	return target, counter
}

func printSlice(s []int) {
	for i := 0; i < len(s); i++ {
		fmt.Print(s[i])
		if i != len(s)-1 {
			fmt.Print(" ")
		}
	}
	fmt.Print("\n")
}

func main() {
	N := scanInt()
	var target []int
	sc.Scan()
	str := strings.Split(sc.Text(), " ")
	for i := 0; i < N; i++ {
		strInt, _ := strconv.Atoi(str[i])
		target = append(target, strInt)
	}
	sorted, counter := bubbleSort(target)
	printSlice(sorted)
	fmt.Println(counter)
}


Measured memory_bytes: 1188
def main():
    n = int(input())
    A = [int(e) for e in input().split()]

    B = [0] * n
    for i in range(n, 0, -1):
        s = 0
        for j in range(n // i):
            s += B[i * (j + 1) - 1]

        if s % 2 != A[i - 1]:
            B[i - 1] = 1

    print(B.count(1))

    if B.count(1) != 0:
        print(' '.join([str(i + 1) for i in range(n) if B[i] == 1]))


if __name__ == '__main__':
    main()


Measured memory_bytes: 70620
import math

def f(n):
    if n==1:
        return 1
    return n*f(n-1)

N,M = map(int, input().split())

if abs(N-M)>=2:
    print(0)
elif abs(N-M)==1:
    print(math.factorial(N)*math.factorial(M)%(10**9+7))
else:
    print((2*math.factorial(N)*math.factorial(M))%(10**9+7))  

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

int main(){
	int N, L, i, sum = 0, ans = 100000000;
	scanf("%d%d", &N, &L);
	for(i = 0; i < N; i++){
		sum += L + i;
	}
	for(i = 0; i < N; i++){
		if(abs(sum - ans) > abs(sum - (sum - (L + i)))){
			ans = sum - (L + i);
		}
	}
	printf("%d\n", ans);
	return 0;
}

Measured memory_bytes: 256
/*
 * 2515.cc: Seishun 18 Kippu 2013
 */

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>
 
using namespace std;

/* constant */

const int MAX_N = 10;

/* typedef */

typedef vector<int> vi;
typedef vector<string> vs;

/* global variables */

string stts[MAX_N], stns[MAX_N], arts[MAX_N], arns[MAX_N];

/* subroutines */

inline int hm2min(string &s) {
  return
    (((s[0] - '0') * 10 + (s[1] - '0')) * 60 +
     (s[3] - '0') * 10 + (s[4] - '0'));
}

/* main */

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

  for (int i = 0; i < n; i++)
    cin >> stts[i] >> stns[i] >> arts[i] >> arns[i];

  vs ansns;
  vi ansts;

  for (int i = 1; i < n; i++) {
    int art = hm2min(arts[i - 1]);
    int stt = hm2min(stts[i]);
    int tm = stt - art;
    //printf("%d: %d (%d - %d)\n", i, tm, art, stt);
    if (tm >= t) {
      ansns.push_back(stns[i]);
      ansts.push_back(tm);
    }
  }

  printf("%lu\n", ansns.size());
  for (int i = 0; i < ansns.size(); i++) {
    cout << ansns[i];
    printf(" %d\n", ansts[i]);
  }

  return 0;
}

Measured memory_bytes: 1248
#include <map>
#include <set>
#include <list>
#include <cmath>
#include <queue>
#include <stack>
#include <cstdio>
#include <string>
#include <vector>
#include <complex>
#include <cstdlib>
#include <cstring>
#include <numeric>
#include <sstream>
#include <iostream>
#include <algorithm>
#include <functional>
  
#define mp       make_pair
#define pb       push_back
#define all(x)   (x).begin(),(x).end()
#define rep(i,n) for(int i=0;i<(n);i++)
  
using namespace std;
  
typedef    long long          ll;
typedef    unsigned long long ull;
typedef    vector<bool>       vb;
typedef    vector<int>        vi;
typedef    vector<vb>         vvb;
typedef    vector<vi>         vvi;
typedef    pair<int,int>      pii;
  
const int INF=1<<29;
const double EPS=1e-9;
  
const int dx[]={1,0,-1,0,1,1,-1,-1},dy[]={0,-1,0,1,1,-1,-1,1};


int main() {
  int N, H;
  cin >> N >> H;
  priority_queue<pair<int,int>> q;
  for(int i = 0; i < N; i++) {
    int a, b;
    cin >> a >> b;
    q.push(mp(a, H));
    q.push(mp(b, 1));
  }

  int ans = 0;
  while(H > 0) {
    pair<int,int> p = q.top(); q.pop();
    int c = min(p.second, (H - 1) / p.first + 1);
    H -= p.first * c;
    ans += c;
  }

  cout << ans << endl;

  return 0;
}

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

int main() {
  int n, T;
  cin >> n >> T;
  int r = 10000;
  for (int i = 0; i < n; ++i) {
    int c, t;
    cin >> c >> t;
    if (t <= T && c < r)
      r = c;
  }
  if (r == 10000)
    cout << "TLE\n";
  else
    cout << r << "\n";
  return 0;
}


Measured memory_bytes: 256
def ABC162C(a,b):#ユークリッドの互除法#最大公倍数
    p=a*b
    while b != 0:
        a %= b
        if a == 0:break
        b %= a
    return p//max(a,b)

n=int(input())
a=list()
for i in range(n):
    a.append(int(input()))
p=a[-1]
for i in a[:-1]:
    p=ABC162C(p,i)
print(p)

Measured memory_bytes: 3060
x=int(input())
if x>=400 and x<=599:
  print(8)
elif x>=600 and x<=799:
  print(7)
elif x>=800 and x<=999:
  print(6)
elif x>=1000 and x<=1199:
  print(5)
elif x>=1200 and x<=1399:
  print(4)
elif x>=1400 and x<=1599:
  print(3)
elif x>=1600 and x<=1799:
  print(2)
elif x>=1800 and x<=1999:
  print(1)

Measured memory_bytes: 9132
#include<iostream>
#include<vector>
#include<string>
#include<cstdio>
using namespace std;
int ans;
int n;
int s;

void count_ans(int k,int C,int j){
    if(k==n){
        if(C==s){
            ans++;
        }
    }else{
        for(int i=j+1;i<10;i++){
            count_ans(k+1,C+i,i);
        }
    }

}


int main(){
    while(cin>>n>>s,(n!=0)||(s!=0)){
        ans=0;
        count_ans(0,0,-1);
        cout<<ans<<endl;
    }
}


Measured memory_bytes: 3084
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>
#include <iterator>
#include <cmath>
#include <set>
#include <deque> 
#include <string>


using namespace std;


const long long MOD = 1000000000 + 7;

long long n;
long long f[2010];	//0--none, 1--zero, 2--nine, 3--all

int main()
{
	scanf("%lld", &n);
	
	f[0] = 1;
	
	for (int i = 1 ; i <= n ; i++) {
		int pLast = i - 3;
		long long sum = 0;
		while (pLast >= 0) {
			sum = (sum + f[pLast]) % MOD;
			pLast--;
		}
		f[i] = sum;
	}
	
	long long ans = f[n] % MOD;
	printf("%lld\n", ans);

	return 0;
}




Measured memory_bytes: 1744
N,M=map(int,input().split())
X=list(map(int,input().split()))
X.sort()
Xdist=[]
for i in range(M-1):
    Xdist.append(X[i+1]-X[i])
Xdist.sort(reverse=True)
if N>=M:print(0)
else:print(sum(Xdist[N-1:]))

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

#define all(x) (x).begin(), (x).end()
#define sz(x) (int)(x).size()

typedef long long ll;
typedef array<int, 3> tri;
typedef long double ld;

template <class T> istream& operator>>(istream& I, vector<T>& v) {for (T &e: v) I >> e; return I;}
template <class T> ostream& operator<<(ostream &O, const vector<T>& v) {for (const T &e: v) O << e << ' '; return O;}



void _main() {
        vector<int> a(3); cin >> a;
        sort(all(a));
        int k; cin >> k;
        cout << a[0] + a[1] + (a[2] * (1 << k));
}



signed main() {
        ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
//        freopen("input.txt", "r", stdin);
        int _t = 1;
//        cin >> _t;
        while (_t--) _main();
        return 0;
}


Measured memory_bytes: 3564
#include "bits/stdc++.h"
#define ll long long
#define rep2(i,a,b) for(int i=a;i<=b;++i)
#define rep(i,n) for(int i=0;i<n;i++)
#define pii pair<int,int>
#define tii tuple<int,int,int>
#define pq priority_queue<int>
#define pqg priority_queue<int,vector<int>,greater<int>>
#define pb push_back
#define edge(v,a,b) v[a].pb(b);v[b].pb(a);
ll int MOD=1e9+7;
#define INF 2*1e9
#define N 310000 
using namespace std;
string alphabet("abcdefghijklmnopqrstuvwxyz");

ll int gcd(ll a,ll b){
    if(a==0) return b;
    if(a>b) return gcd(b,a);
    return gcd(b%a,a);
}
main(){
    int t;
    cin>>t;
    while(t){
        ll a,b,c,d;
        cin>>a>>b>>c>>d;
        ll g=gcd(b,d);
        ll l=c+1;
        if(l%g<a%g){
            l+=(a%g-l%g);
        }
        else if(l%g>a%g){
            l+=(g+a%g-l%g);
        }
        ll s=min(l,l-b+d);
        if(a<b){
            cout<<"No"<<endl;t--;continue;
        }
        if(d<b){
            cout<<"No"<<endl;t--;continue;
        }
        if(a-b<=c&&d==b){
            cout<<"Yes"<<endl;t--;continue;
        }
        if(s<b){
            cout<<"No"<<endl;
        }
        else cout<<"Yes"<<endl;
        t--;
    }
}



Measured memory_bytes: 256
from fractions import gcd
N=int(input())
A=list(map(int,input().split()))

MOD=10**9+7
def lcm(a,b): return a*b//gcd(a,b)

LCM=A[:]
num=N
while num>1:
    for i in range(1,num,2):
        LCM[i//2]=lcm(LCM[i-1],LCM[i])
    if num&1:
        LCM[num//2]=LCM[num-1]
    num=(num+1)//2

ans=0
l=LCM[0]%MOD
for a in A:
    ans+=l*pow(a,MOD-2,MOD)
    ans%=MOD

print(ans)

Measured memory_bytes: 70744
import java.util.*;
import java.awt.*;
import static java.lang.System.*;
import static java.lang.Math.*;
public class Main {
    static int mod=1000000007;
    public static void main(String[]$) {
        Scanner sc = new Scanner(in);
        int n=sc.nextInt();
        long[] c=new long[5];
        for (int i = 0; i < n; i++) {
            char p=sc.next().charAt(0);
            switch (p){
                case 'M':c[0]++;break;
                case 'A':c[1]++;break;
                case 'R':c[2]++;break;
                case 'C':c[3]++;break;
                case 'H':c[4]++;break;
                default:break;
            }
        }
        long ans=0;
        for (int i = 0; i < 3; i++) {
            for (int j = i+1; j < 4; j++) {
                for (int k = j+1; k < 5; k++) {
                    ans+=c[i]*c[j]*c[k];
                }
            }
        }
        out.println(ans);
    }
}

Measured memory_bytes: 44344
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <cmath>
#include <algorithm>
#include <vector>
#include <numeric>
#include <queue>
#include <stack>
#include <map> 
#include <set>
#include <string>
#include <functional>
#include <list>
#include <random>
#include <time.h>
#include <iomanip>
#include <assert.h>
#include <numeric>
#include <new>
#define BIT(nr) (1ULL << (nr))
#define int long long
#define ll long long
#define double long double
#define mod 1000000007
#define MAXN (int)1e+5 * 2+1
#define LL_MAX 9223372036854775807	//ない環境用
#define LL_HALFMAX 9223372036854775807 / 2	//ない環境用
#define MIN -(9223372036854775807 / 2)
#define REP(i,a,n) for(int i=(a); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define FOR(it,c) for(__typeof((c).begin()) it=(c).begin(); it!=(c).end(); ++it)
#define ALLOF(c) (c).begin(), (c).end()
#define REPS(i,x) for(int i=1;i<=(int)(x);i++)
#define RREP(i,x) for(int i=((int)(x)-1);i>=0;i--)
#define RREPS(i,x) for(int i=((int)(x));i>0;i--)
#define repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define mp make_pair
template<typename T1, typename T2> inline void chmin(T1 & a, T2 b) { if (a > b) a = b; }
template<typename T1, typename T2> inline void chmax(T1& a, T2 b) { if (a < b) a = b; }

using rh_type = unsigned long long;

template <rh_type MOD = 0>
struct rolling_hash {
	int n;
	rh_type base;
	std::vector<rh_type> pow, hash;

	rolling_hash() {}

	template <typename Array>
	rolling_hash(const Array &s, rh_type b_ = 10007) {
		set(s, b_);
	}

	template <typename Array>
	void set(const Array &s, rh_type b_ = 10007) {
		n = s.size();
		base = b_;
		pow.resize(n + 1);
		pow[0] = 1;
		hash.resize(n + 1);
		hash[0] = 0;
		for (int i = 0; i < n; ++i) {
			if (MOD == 0) {
				pow[i + 1] = pow[i] * base;
				hash[i + 1] = s[i] + hash[i] * base;
			}
			else {
				pow[i + 1] = pow[i] * base % MOD;
				hash[i + 1] = (s[i] + hash[i] * base) % MOD;
			}
		}
	}

	rh_type get(int r) const { return hash[r]; }

	rh_type get(int l, int r) const {
		if (MOD == 0) {
			return get(r) - get(l) * pow[r - l];
		}
		else {
			return (get(r) - get(l) * pow[r - l] % MOD + MOD) % MOD;
		}
	}
};

// 1000000007, 1000000009, 1000000021, ...
using RH = rolling_hash<10123457689>;

using namespace std;

// 汎用的な二分探索のテンプレ(めぐる式)
int binary_search(function<bool(int)> isOk, int ng, int ok) {

	/* ok と ng のどちらが大きいかわからないことを考慮 */
	while (abs(ok - ng) > 1) {
		int mid = (ok + ng) / 2;

		if (isOk(mid)) ok = mid;
		else ng = mid;
	}
	return ok;
}

signed main() {
	int N;
	cin >> N;
	string S;
	cin >> S;

	RH hs(S, 114514);
	//RH hs2(S, 1919810);

	auto isOk = [&](int len) -> bool {
		map<string, vector<int>> ma;

		rep(i, N - len + 1) {
			string st = S.substr(i, len);
			ma[st].push_back(i);
		}

		for (auto p : ma) {
			int f = p.second[0];
			int l = p.second.back();

			if (f + len <= l) {
				return true;
			}
		}
		return false;
	};

	cout << binary_search(isOk, N, 0) << "\n";

	return 0;
}


Measured memory_bytes: 6784
#include<cstdio>
using namespace std;
int main(){
  int h,w;
  char s[101][101];
  scanf("%d %d",&h,&w);
  for(int i=0;i<h;i++){
    scanf("%s",s[i]);
    printf("%s\n",s[i]);
    printf("%s\n",s[i]);
  }
}

Measured memory_bytes: 128
import java.util.*;
import java.lang.Math;
class Main
{
    static int maxX;
    static int maxY;
    static int maxLength;
    final static int startX=0;
    final static int startY=0;
    
    public static void main(String[] args)
    {
	int dx,dy,length;
	int currentX,currentY;
	Scanner sc=new Scanner(System.in);
	int attend=sc.nextInt();
	for(int i=0;i<attend;i++){
	    currentX=startX;
	    currentY=startY;
	    maxLength=0;maxX=0;maxY=0;
	    while(true){
		dx=sc.nextInt();
		dy=sc.nextInt();
		currentX+=dx;
		currentY+=dy;
		if(dx==startX&&dy==startY)break;

		length=currentX*currentX+currentY*currentY;

		if(maxLength==length){
		    if(maxX<currentX){
			maxX=currentX;
			maxY=currentY;
		    }
		}
		else if(maxLength<length){
		    maxLength=length;
		    maxX=currentX;
		    maxY=currentY;
		}
	    }
	    System.out.println(maxX+" "+maxY);
	}
	
    }
    
}

Measured memory_bytes: 12000
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using vi = vector<int>;    using vvi = vector<vi>;
using vb = vector<bool>;   using vvb = vector<vb>;
using vl = vector<ll>;     using vvl = vector<vl>;
using vd = vector<double>; using vvd = vector<vd>;

#define REP(i,n) for(ll i=0, i##_len=(ll)(n); i<i##_len; ++i)
#define ALL(c) (c).begin(), (c).end()
#define FOR(i,s,n) for(ll i=s, i##_len=(ll)(n); i<i##_len; ++i)
#define TEN(x) ((ll)1e##x)
const ll mod = TEN(9) + 7;



int main() {
#ifdef INPUT_FROM_FILE
	ifstream cin("sample.in");
	ofstream cout("sample.out");
#endif
	cin.tie(0);
	ios_base::sync_with_stdio(false);
	cout << fixed << setprecision(50);
	string s; cin >> s;
	REP(i, s.size()) {
		cout << s[i];
		if (i == 3) {
			cout << " ";
		}
	}
	cout << endl;

	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <map>
#include <queue>
#include <stack>
#include <algorithm>
#include <list>
#include <set>
#include <cmath>
#include <cstring>
#include <stdio.h>
#include <string.h>
#include <sstream>
#include <stdlib.h>
#include <vector>
#include <iomanip>
#include <ctime>
#include <deque>
#include <bitset>
#include <functional>
#include <numeric>
#include <utility>
#include <cstdlib>
#include <cassert>

#define el_cucuy ios_base::sync_with_stdio(0), cout.tie(0); cin.tie(0);
#define llong long long
#define pb push_back
#define bpc __builtin_popcount
#define pii pair <int, int>
#define f first
#define s second

const llong mxn = 4 * 1e5 + 3;
const llong mod = 1e9 + 7;
const llong inf = 1e18 + 9;

using namespace std;

//int dx[]= {1,0,-1,0}; int dy[]= {0,1,0,-1}; //4 Direction
//int dx[]={1,1,0,-1,-1,-1,0,1}; int dy[]={0,1,1,1,0,-1,-1,-1};//8 direction
//int dx[]={2,1,-1,-2,-2,-1,1,2}; int dy[]={1,2,2,1,-1,-2,-2,-1};//Knight Direction
//int dx[]={-1,-1,+0,+1,+1,+0}; int dy[]={-1,+1,+2,+1,-1,-2}; //Hexagonal Direction

llong n, m, a[mxn], dp[3001][3001], sum[mxn];

int main(){
    ///freopen("input.txt", "r", stdin);
    ///freopen("output.txt", "w", stdout);
    cin >> n;
    for (int i = 1; i <= n; i ++){
        cin >> a[i];
        dp[i][i] = a[i];
    }
    for (int sz = 2; sz <= n; sz ++){
        for (int l = 1; l <= n - sz + 1; l ++){
            llong r = l + sz - 1;
            dp[l][r] = max(a[l] - dp[l + 1][r], a[r] - dp[l][r - 1]);
        }
    }
    cout << dp[1][n];
    return 0;
}


Measured memory_bytes: 71936
#include<bits/stdc++.h>
#define MAX 2001
using namespace std;
int K[MAX] = {};
int N,X,Y,ans;
int main ()
{
    cin>>N>>X>>Y;
    for(int i=1;i<=N;i++) 
	{
        for(int j=i+1;j<=N;j++)
		{
            int k = min(min(abs(j-i), abs(X-i) + 1 + abs(j-Y)), abs(Y-i) + 1 + abs(j-X)); 
            K[k]++;
        }
    }
    for(int i=1;i<N;i++) {
        cout<<K[i]<<"\n";
    }
    return 0;
}

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

int main() {
    int n;
    cin >> n;
    int r[n];
    rep(i,0,n) cin >> r[i];
    int maxr = -2000000000,minr = r[0];
    rep(i,1,n){
        maxr = max(maxr, r[i]-minr);
        minr = min(minr,r[i]);
    }
    cout << maxr << endl;
    return 0;
}


Measured memory_bytes: 3856
n = int(input())
s = list(map(lambda x:int(x), input().split()))
q = int(input())
t = list(map(lambda x:int(x), input().split()))
c = 0

for i in t:
    left = 0
    right = n
    mid = lambda x,y:(x + y)/2
    while left < right:
        if s[int(mid(left,right))] == i:
            c += 1
            break
        elif s[int(mid(left,right))] > i:
            right = int(mid(left,right))
        else:
            left = int(mid(left,right)) + 1

print(c)

Measured memory_bytes: 18808
package main

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

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

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

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

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

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

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

	a := scanInt()
	b := scanInt()
	_ = scanInt()
	k := scanInt()

	fmt.Fprintln(wr, min(k, a)-max(k-a-b, 0))

}


Measured memory_bytes: 1760
#include<bits/stdc++.h>
#include<string>
#include<vector>
using namespace std;
typedef pair<int, int>P;
typedef long long ll;
#define rep(i,n)for(ll i=0;i<n;++i)
#define exrep(i, a, b) for(ll i = a; i <= b; i++)
#define out(x) cout << x << endl
#define exout(x) printf("%.10f\n", x)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define pb push_back
#define re0 return 0
const ll mod = 1000000007;
const ll INF = 1e16;
const ll MAX_N = 100010;
//max=({});
//条件式が真ならwhileの中身を回し続ける
//printf("%d\n", ans);

//pairの入力
//vector<pair<ll, ll>>work(n);
//rep(i, n) {
//	ll a, b;
//	cin >> a >> b;
//	work[i] = make_pair(a, b);
//for(auto p:mp)(mapの探索)
//printf("%.10f\n",なんちゃら)
//最大公約数
ll gcd(ll x, ll y) {
	return y ? gcd(y, x % y) : x;
}

ll lcm(ll x, ll y) {
	if (x == 0 || y == 0)return 0;
	return (x / gcd(x, y) * y);
}

//素因数分解
map<ll, ll>ins;
void facterize(ll n) {
	ll a = 2;
	while (n >= a * a) {
		if (n % a == 0) {
			ins[a]++;
			ins[a] = ins[a] % 1000000007;
			n /= a;
		}
		else {
			a++;
		}
	}
	ins[n]++;
}

int keta(int x) {
	int y = 0;
	while (x > 0) {
		y++;
		x /= 10;
	}
	return y;
}

ll dx[4] = { 0,0,-1,1 };
ll dy[4] = { -1,1,0,0 };
ll dp[1010][1010];

//long longしか使わない
int main() {
	string s, t;
	cin >> s >> t;
	bool flag = true;
	ll n = s.length();
	rep(i, n) {
		if (s[i] != t[i])flag = false;
	}
	if (flag)puts("Yes");
	else {
		puts("No");
	}
	return 0;
}


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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define reps(i, n, m) for (int i = (int)(n); i <= (int)(m); i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define rALL(obj) (obj).rbegin(), (obj).rend()
#define intpow(a, n) (int)pow((long double) a, (long double) n)
#define int long long

int cnt['Z'];
signed main(){
    int n; string s;
    cin >> n >> s;
    rep(i,n) cnt[s[i]]++;
    long long ans = cnt['R'] * cnt['G'] * cnt['B'];
    
    reps(i,0,n-2)reps(k,i+1,n-1){
        if((i+k) % 2 != 0 || s[i]==s[k]) continue;
        int j = (i+k)/2;
        if(s[i] != s[j] && s[j] != s[k]) ans--;
    }
    
    cout << ans << endl;
}

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

void solve(std::string S, std::string T, long long A, long long B, std::string U)
{
    if (U == S)
    {
        cout << (A - 1) << " " << B << endl;
    }
    else
    {
        cout << A << " " << (B - 1) << endl;
    }
}

// Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main()
{
    std::string S;
    std::cin >> S;
    std::string T;
    std::cin >> T;
    long long A;
    scanf("%lld", &A);
    long long B;
    scanf("%lld", &B);
    std::string U;
    std::cin >> U;
    solve(S, T, A, B, U);
    return 0;
}


Measured memory_bytes: 256
using System;
 
class Solver {
    public Solver() {}
    public static int Main() {
        new Solver().solve();
        return 0;
    }
 
    public void solve() {
        long x;
        x = long.Parse(Console.ReadLine());
        int ans = (int)(Math.Ceiling(Math.Sqrt(2 * x + 0.25) - 0.5));
        Console.WriteLine(ans);
    }
}


Measured memory_bytes: 13140
import math
x=int(input())

stop=False
#(a,b)==(+,-)
for a in range(int(math.pow(10**9,1/5))+1):
    for b in range(int(math.pow(10**9,1/5))+1):
        if a**5-(-b)**5==x:
            print(a,-b)
            stop=True
            break
    if stop:
        break
else:
    #(a,b)==(+,+)
    a_range_num=int(math.pow(10**9+(math.pow(2,1/4)*10**2)**5,1/5))
    for b in range(int(math.pow(10**9,1/4))+1):
        for a in range(b,a_range_num+1):
            if a**5-b**5==x:
                print(a,b)
                stop=True
                break
        if stop:
            break

Measured memory_bytes: 9420
#include <bits/stdc++.h>
#define long long long int
using namespace std;

// @author: pashka

vector<vector<pair<int, int>>> g;
vector<int> res;

void dfs(int x, int p, int c) {
    int k = 0;
    for (auto e : g[x]) {
        int y = e.first;
        if (y == p) continue;
        if (k == c) k++;
        res[e.second] = k;
        dfs(y, x, k);
        k++;
    }
}

int main() {
    ios::sync_with_stdio(false);
    
    int n;
    cin >> n;
    g.resize(n);
    for (int i = 0; i < n - 1; i++) {
        int x, y;
        cin >> x >> y;
        x--; y--;
        g[x].push_back({y, i});
        g[y].push_back({x, i});
    }
    
    res.resize(n - 1);
    dfs(0, -1, -1);
    int mx = 0;
    for (int i : res) mx = max(mx, i);
    cout << mx + 1 << "\n";
    for (int i : res) cout << i + 1 << "\n";
    
    return 0;
}

Measured memory_bytes: 8320
#include<iostream>

using namespace std;

int main()
{
    long long H,W;
    
    cin >> H >> W;
    if(H==1|| W==1){
        cout << 1;
    }else if ((H*W)%2 == 0){
        cout << H*W/2;
    }else{
        cout << H*W/2 + 1;
    }

    
    return 0;
}

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

using namespace std;
using ll = long long;
using ld = long double;

//#define int long long
//signed main(){
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n;
    cin >> n;
    vector<int> a(n);
    for(int i = 0; i < n; i++) {
        cin >> a[i];
    }

    int rabs=INT32_MAX;
    int ridx;
    int ncnt=0;
    for(int i = 0; i < n; i++) {
        if(a[i]<0){
            ncnt++;
            a[i]*=-1;
        }
        if(a[i]<rabs){
            rabs=a[i];
            ridx=i;
        }
    }

    ll ans=0;
    for(int i = 0; i < n; i++) {
        ans+=a[i];
    }
    if(ncnt%2==0) cout << ans << "\n";
    else          cout << ans-2*a[ridx] << "\n";

    return 0;
}

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

#define LL long long
#define RG register

using namespace std;
template<class T> T gi() {
	T x = 0; bool f = 0; char c = getchar();
	while (c != '-' && (c < '0' || c > '9')) c = getchar();
	if (c == '-') f = 1, c = getchar();
	while (c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar();
	return f ? -x : x;
}
const int N = 1e5 + 10;
int a[N], b[N], c[N], n;
struct node {
	int t[N << 8];
#define lson (o << 1)
#define rson (o << 1 | 1)
	void clear () { memset(t, 0, sizeof(t)); }
	void Modify(int o, int l, int r, int p) {
		t[o]++;
		if (l == r) return ;
		int mid = (l + r) >> 1;
		if (p <= mid) Modify(lson, l, mid, p);
		else Modify(rson, mid + 1, r, p);
	}
	int query(int o, int l, int r, int p) {
		if (l == r) return 0;
		int mid = (l + r) >> 1;
		if (p <= mid) return query(lson, l, mid, p);
		else return t[lson] + query(rson, mid + 1, r, p);
	}
} T;
LL check(int x) {
	T.clear();
	for (int i = 1; i <= n; i++)
		c[i] = c[i - 1] + (a[i] < x ? 1 : -1);
	LL res = 0;
	T.Modify(1, 0, 2 * N, N);
	for (int i = 1; i <= n; i++) {
		res += T.query(1, 0, 2 * N, c[i] + N);
		T.Modify(1, 0, 2 * N, c[i] + N);
	}
	return res;
}
int main() {
	//freopen(".in", "r", stdin);
	//freopen(".out", "w", stdout);
	n = gi<int>(); int m = n;
	for (int i = 1; i <= n; i++) a[i] = gi<int>(), b[i] = a[i];
	sort(b + 1, b + 1 + m); m = unique(b + 1, b + 1 + m) - b - 1;
	int l = 1, r = m;
	while (l <= r) {
		int mid = (l + r) >> 1;
		if (check(b[mid]) >= 1ll * (n + 1) * n / 4 + 1) r = mid - 1;
		else l = mid + 1;
	}
	printf("%d\n", b[l - 1]);
	return 0;
}


Measured memory_bytes: 101376
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
 
using namespace __gnu_pbds;
using namespace std;

typedef long long int ll;
typedef unsigned long long int ull;
typedef long double ld;
typedef pair <ll, ll> pll;
typedef pair <int, int> pii;

typedef tree <ll, null_type, less <ll>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
// order_of_key(val): returns the number of values less than val
// find_by_order(k): returns an iterator to the kth largest element (0-based)

#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define all(a) a.begin(), a.end()
#define sz(a) (ll)(a.size())
#define endl "\n"

template <class Ch, class Tr, class Container>
basic_ostream <Ch, Tr> & operator << (basic_ostream <Ch, Tr> & os, Container const& x) 
{
    os << "{ ";
    for(auto& y : x) 
    {
        os << y << " ";
    }
    return os << "}";
}

template <class X, class Y>
ostream & operator << (ostream & os, pair <X, Y> const& p) 
{
    return os << "[" << p.ff << ", " << p.ss << "]";
}

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

    return gcd(b, a%b);
}

ll modexp(ll a, ll b, ll c)
{   
    a%=c;

    ll ans = 1;

    while(b)
    {
        if(b&1)
        {
            ans = (ans*a)%c;
        }

        a = (a*a)%c;
        b >>= 1;
    }

    return ans;
}

ll nxt()
{
    ll x;
    cin >> x;
    return x;
}

const ll L = 1e5+5;

void solve()
{
    ll a, b, c, k;
    cin >> a >> b >> c >> k;

    if(a >= k)
    {
        cout << k << endl;
    }

    else if(a + b >= k)
    {
        cout << a << endl;
    }

    else 
    {
        cout << a - (k - a - b) << endl;
    }
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);
    
    ll T = 1;
    // T = nxt();

    while(T--)
    {
        solve();
    }

    return 0;
}

Measured memory_bytes: 3612
import itertools
N = input()

for i in list(itertools.product(["+","-"],repeat=3)):
    cnt = 0
    X = N[cnt]
    for j in i:
        X += j
        cnt += 1
        X += N[cnt]
        
    Y = eval(X)
    if Y == 7:
        X += "=7"
        print(X)
        quit()

Measured memory_bytes: 38384
// Original macro is in https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
macro_rules! input {
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = || -> 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)*}
    };
}
 
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)*}
    };
    
    ($next:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}
 
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, [$t:tt]) => {
        {
            let len = read_value!($next, usize);
            (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")
    };
}

// for adhoc read (ex. https://atcoder.jp/contests/abc112/tasks/abc112_a)
#[allow(dead_code)]
fn read_line() -> String {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).unwrap();
    s.trim().to_string()
}

#[allow(dead_code)]
fn gcd(a: i64, b: i64) -> i64 {
    if b == 0 {
        a
    } else {
        gcd(b, a % b)
    }
}

#[allow(dead_code)]
fn lcm(a: i64, b: i64) -> i64 {
    a*b / gcd(a, b)
}

use std::cmp;
fn main() {
    input! { n: usize, a: [i64;n+1], mut b: [i64; n] }

    let mut cnt = 0;
    for i in 0..n+1 {

        if i == 0 {
            cnt += cmp::min(a[0], b[0]);
            b[0] -= cnt;
        } else if i < n {
            cnt += cmp::min(a[i], b[i-1]+b[i]);
            if a[i] > b[i-1] {
                b[i] -= cmp::min(a[i]-b[i-1], b[i]);
            }
        } else {
            cnt += cmp::min(a[i], b[i-1]);
        }
    }
    println!("{}", cnt);
}


Measured memory_bytes: 6396
n=int(input())  
v=list(map(int, input().split()))
odd = []
even = []
for i in range(n):
  if i % 2 ==0:
    odd.append(v[i])
  else:
    even.append(v[i])
#集計
from collections import Counter
oddc=Counter(odd)
evenc=Counter(even)
od = oddc.most_common(2)
ev = evenc.most_common(2)
if od[0][0] != ev[0][0]:
  m = od[0][1] + ev[0][1]
elif len(od)==1 and len(ev)==1:
  m = od[0][1]
elif len(od)==1:
  m = od[0][1] + ev[1][1]
elif len(ev)==1:
  m = ev[0][1] + od[1][1]
else:
  m = max( ev[0][1] + od[1][1],od[0][1] + ev[1][1])

if odd == even and len(od)==1:
  print(n//2)
else:
  print(n-m)
  

Measured memory_bytes: 19040
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;
typedef pair<ll,ll> pll;
const ll mod=1e9+7;
//const ll mod=998244353;
const ll inf=5e18;

int main() {
  ll n,W;
  cin >> n >> W;
  vec w(n),v(n);
  for(ll i=0;i<n;i++) cin >> w[i] >> v[i];
  vec dp(W+1);
  for(ll i=0;i<n;i++) {
    for(ll j=W;j>=0;j--) {
      if(j-w[i]>=0) {
        dp[j]=max(dp[j],dp[j-w[i]]+v[i]);
      }
    }
  }
  cout << dp[W] << endl;
}

Measured memory_bytes: 1024
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <list>
#include <cmath>
#include <iomanip>

using namespace std;

int main() {
    string S;
    cin >> S;

    int ans = S.size();

    for(int i = 0; i < 2; i++) {
        int cnt = 0;

        for (int j = 0; j < S.size(); j++)
        {
            if(j % 2 == 0 && S[j] != (char)(i + '0')) cnt++;
            if(j % 2 == 1 && S[j] == (char)(i + '0')) cnt++;
        }

        ans = min(ans, cnt);
        
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i, n) for(int i=0; i<(n); ++i)
#define REP(i, d, n) for(int i=(d); i<(n); ++i)
#define all(v) v.begin(), v.end()
using P = pair<int, int>;

signed main() {

    int x;
    cin >> x;

    rep(i, 1e3){
        for(int j = 1e3; j >= -1e3; --j){
            int a = pow(i, 5);
            int b = pow(j, 5);
            if(a - b == x){
                cout << i << " " << j << endl;
                return 0;
            }
        }
    }

    return 0;
}


Measured memory_bytes: 4096
#include<iostream>
#include<algorithm>
#include<cstring>
#include<utility>
using namespace std;
int main()
{
	ios_base :: sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	int n, a, b;
	cin >> n >> a >> b;
	char x;
	//scanf("%s", x);
	int to = a+b;
	int passed = 0, overseas = 0;
	for(int i=0; i<n; i++){
		cin >> x;
		if(x=='a'){
			if(passed<to){
				cout << "Yes\n";
				passed++;
			}
			else{
				cout << "No\n";
			}
		}
		else if(x=='b'){
			if(passed<to && overseas<b){
				cout << "Yes\n";
				passed++;
				overseas++;
			}
			else{
				cout << "No\n";
			}
		}
		else{
			cout << "No\n";
		}
	}
	return 0;
}


Measured memory_bytes: 3660
#include <bits/stdc++.h>
#define il inline
#define ri register int
#define pb push_back
#define mp make_pair
#define fir first
#define sec second
#define mid ((l+r)>>1)
#define MAXN 2050
#define MAXM
#define mod
#define inf (1<<30)
#define eps (1e-6)
#define alpha 0.75
#define rep(i, x, y) for(ri i = x; i <= y; ++i)
#define repd(i, x, y) for(ri i = x; i >= y; --i)
#define file(s) freopen(s".in", "r", stdin), freopen(s".out", "w", stdout)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair <int, int> pii;
typedef pair <ll, int> pli;
typedef pair <int, ll> pil;
typedef pair <ll, ll> pll;
template <typename T> il bool chkmin(T &x, T y) {return x > y ? x = y, 1 : 0;}
template <typename T> il bool chkmax(T &x, T y) {return x < y ? x = y, 1 : 0;}
template <typename T> il void read(T &x) {
	char ch = getchar(); int f = 1; x = 0;
	while(ch < '0' || ch > '9') {if(ch == '-') f = -1; ch = getchar();}
	while(ch >= '0' && ch <= '9') x = x*10+ch-'0', ch = getchar();
	x *= f;
}
template <typename T, typename... Args> il void read(T &x, Args &...args) {
	read(x), read(args...);
}
int n, k, ans = 1e9, dep[MAXN];
vector <int> adj[MAXN];
void dfs(int u, int fa) {
	for(auto v: adj[u])
		if(v != fa) dep[v] = dep[u]+1, dfs(v, u);
}
int main() {
	read(n, k); int u, v;
	rep(i, 1, n-1) read(u, v), adj[u].pb(v), adj[v].pb(u);
	int cnt;
	if(k & 1) {
		rep(i, 1, n) {
			for(auto v: adj[i]) {
				dep[i] = dep[v] = cnt = 0, dfs(i, v), dfs(v, i);
//				rep(i, 1, n) cout << dep[i] <<' '; puts("");
				rep(j, 1, n) cnt += dep[j] > (k >> 1);
				chkmin(ans, cnt);
			}
		}
	}
	else {
		rep(i, 1, n) {
			cnt = dep[i] = 0, dfs(i, 0);
			rep(j, 1, n) cnt += dep[j] > (k >> 1);
			chkmin(ans, cnt);
		}
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 512