akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>

using namespace std;

int A, B, M, a[100000], b[100000], x[100000], y[100000], c[100000];
int ans = INT_MAX;
int mia = INT_MAX, mib = INT_MAX;

int main(){
	cin >> A >> B >> M;
	for(int i = 0; i < A; ++i){
		cin >> a[i];
		mia = min(mia, a[i]);
	}
	for(int i = 0; i < B; ++i){
		cin >> b[i];
		mib = min(mib, b[i]);
	}
	ans = min(ans, mia+mib);
	for(int i = 0; i < M; ++i) cin >> x[i] >> y[i] >> c[i];
	for(int i = 0; i < M; ++i){
		ans = min(ans, a[x[i]-1]+b[y[i]-1]-c[i]);
	}
	cout << ans << endl;
}

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

#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define lb lower_bound
#define ub upper_bound

typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<ll> vll;
//template<class T> using oset=tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
const ll mod=1000000007;
ll powmod(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}

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

  	int w, a , b;
  	cin >> w >> a >> b;
  	if(a > b) swap(a, b);
  	cout << max(0, b - (a + w)) << endl;
	return 0;
}


Measured memory_bytes: 256
# -*- coding: utf-8 -*-
# B

import sys
from collections import defaultdict, deque
from heapq import heappush, heappop
import math
import bisect
input = sys.stdin.readline

# 再起回数上限変更
# sys.setrecursionlimit(1000000)

s = input()[:-1]
t = input()[:-1]
num = len(t)
ans = 1000

for i in range(len(s)-len(t)+1):
    val = 0
    for idx, t_ in enumerate(t):
        if s[i + idx] != t_:
            val += 1
    ans = min(ans, val)

print(ans)



Measured memory_bytes: 68156
# B - ATCoder
# https://atcoder.jp/contests/abc122/tasks/abc122_b

S = raw_input()
num = 0
max_num = 0

for s_id in range(len(S)):
    if S[s_id] == 'A' or S[s_id] == 'T' or S[s_id] == 'C' or S[s_id] == 'G':
        num += 1
    else:
        if num != 0 and max_num < num:
            max_num = num
            num = 0

    if s_id == len(S) - 1 and num != 0 and max_num < num:
        max_num = num

print '{}'.format(max_num)


Measured memory_bytes: 2568
package main

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

var sc = bufio.NewScanner(os.Stdin)

func main() {
	sc.Split(bufio.ScanWords)
	a := readInt()
	b := readInt()
	c := readInt()
	answer := c - (a - b)
	if answer < 0 {
		fmt.Println(0)
	} else {
		fmt.Println(answer)
	}
}

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

func readInt() int {
	i, e := strconv.Atoi(read())
	if e != nil {
		panic(e)
	}
	return i
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
int main()
  {int X; cin >> X;
  for (long long A = -128; A <= 128; ++A)
    for (long long B = -128; B <= 128; ++B)
      if (A * A * A * A * A - B * B * B * B * B == X) {cout << A << " " << B << endl; return 0;}}

Measured memory_bytes: 3624
#![allow(unused_imports)]
use std::cmp::*;
use std::collections::*;
use itertools::Itertools;
use proconio::{input, marker::*, fastout};
use superslice::*;

#[fastout()]
fn main() {
    input! {
        n: usize, m: usize,
    }
    let mut edges = vec![Vec::new(); n];
    for _ in 0..m {
        input! {node1: Usize1, node2: Usize1}
        edges[node1].push(node2);
        edges[node2].push(node1);
    }
    let mut marks = vec![n+1; n];
    marks[0] = 0;
    let mut q = VecDeque::new();
    for &node in &edges[0] {
        q.push_back(node);
        marks[node] = 0;
    }

    while let Some(node) = q.pop_front() {
        for &next in &edges[node] {
            if marks[next] == n+1 {
                q.push_back(next);
                marks[next] = node;
            }
        }
    }
    println!("Yes");
    for i in 1..n {
        println!("{}", marks[i]+1);
    }
}


Measured memory_bytes: 14032
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <complex>
#include <queue>
#include <set>
#include <map>
#include <assert.h>
 
using namespace std;
 
#define REP(i,a,b) for(int i=a;i<(int)b;i++)
#define rep(i,n) REP(i,0,n)
 
typedef long long ll;
 
double const EPS = 1e-8;
typedef vector<double> vec;
typedef vector<vec> mat;
 
vec gauss_jordan(mat const& A, vec const& b) {
  int n = A.size();
  mat B(n, vec(n+1));
  rep(i, n) rep(j, n) B[i][j] = A[i][j];
  rep(i, n) B[i][n] = b[i];
 
  rep(i, n) {
    int pivot = i;
    REP(j, i, n) {
      if(abs(B[j][i]) > abs(B[pivot][i])) { pivot = j; }
    }
    swap(B[i], B[pivot]);
 
    if(abs(B[i][i]) < EPS) { return vec(); }
 
    REP(j, i+1, n+1) B[i][j] /= B[i][i];
    rep(j, n) {
      if(i != j) {
        REP(k, i+1, n+1) B[j][k] -= B[j][i] * B[i][k];
      }
    }
  }
 
  vec x(n);
  rep(i, n) x[i] = B[i][n];
  return x;
}
 
 
int D;
 
int main() {
 
  for(; cin >> D && D;) {
    double v[D+3]; rep(i, D+3) cin >> v[i];
    map<vector<long long>, int> counter;
    rep(i, D+3) {
      REP(j, i+1, D+3) {
        mat A(D+1, vec(D+1));
        int p = 0;
        vec b;
        rep(x, D+3) {
          if(x == i || x == j) { continue; }
          rep(l, D+1) {
            A[p][l] = pow(double(x), D-l);
          }
          p++;
          b.push_back(v[x]);
        }
 
        auto s = gauss_jordan(A, b);
        vector<long long> ss(D+1);
        int sz = s.size(); rep(ii, sz) {
          ss[ii] = ceil(s[ii]*10);
        }
        auto tt = ss;
        ss.push_back(i); tt.push_back(j);
        counter[ss]++; counter[tt]++;
      }
    }
    for(auto e: counter) {
      /*
      rep(i, e.first.size()) {
        cout << e.first[i] << endl;
      }
      cout << endl;
      */
      if(e.second >= D+2) {
        cout << e.first.back() << endl;
        goto exit;
      }
    }
    assert(false);
  exit:;
  }
 
  return 0;
}

Measured memory_bytes: 1336
#include <bits/stdc++.h>
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int A, B;
  cin >> A >> B;
  
  if (B%A==0) {
  cout << A + B << endl;
	}
else {
  cout << B-A << endl;
	}
}

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

int main(void) {
	int num, i = 0, buf = 0, ans = 200000;
	string s;
	cin >> num >> s;
	vector<int> b(num + 1, 0), w(num + 1, 0);
	while (i < num) {
		if (s[i] == '#')
			buf++;
		b[++i] = buf;
	}
	buf = 0;
	while (i > 0) {
		if (s[i] == '.')
			buf++;
		w[--i] = buf;
	}
	for (i = 0; i <= num; i++)
		ans = min(ans, b[i] + w[i]);
	cout << ans << "\n";
	return 0;
}

Measured memory_bytes: 2180
#include<iostream>
#include<vector>
#include<algorithm>
#include<cctype>
#include<utility>
#include<string>
#include<cmath>

#define REP(n) for(int i = 0;i < n;i++)
#define LLREP(n) for(long long int  i = 0;i < n;i++)
typedef long long int ll;
using namespace std;
#define MAX_A 100005

int main(){

    int a,b;
    cin >> a >> b;

    if(b >= a){
        cout << a << endl;
    }else{
        cout << a-1 << endl;
    }

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_int.hpp>

using boost::multiprecision::cpp_int;
using namespace std;

#if __has_include("print.hpp")
  #include "print.hpp"
#endif

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define ALL(x) (x).begin(), (x).end()
#define RALL(x) (x).rbegin(), (x).rend()
#define MOD 1000000007

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

typedef long long ll;
typedef pair<ll, ll> p;


int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  vector<int> v(n);
  int count = 0;
  for (int i = 0; i < n; ++i) {
    cin >> v[i];
    if((i+1) % 2 == 1 && v[i] % 2 == 1) count++;
  }
  cout << count << endl;
}


Measured memory_bytes: 3608
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;

int main(int argc, char* argv[]){
    int a, b, c;
    cin >> a >> b >> c;
    int mx = max(a, max(b, c));
    int mn = min(a, min(b, c));

    cout << abs(mx-mn) << endl;
}



Measured memory_bytes: 256
#include <iostream>
//#include <iomanip>
//#include <string>
#include <vector>
#include <algorithm>
//#include <utility>
//#include <set>
//#include <map>
//#include <queue>
//#include <deque>
//#include <bitset>
//#include <math.h>
using namespace std ;
using ll = long long ;
//using ld = long double ;
using vll = vector<ll> ;
//using vvll = vector<vll> ;
//using vc = vector<char> ;
//using vvc = vector<vc> ;
//using vb = vector<bool> ;
//using vvb = vector<vb> ;
//using pll = pair<ll,ll> ;
#define all(v) v.begin(),v.end()
ll mod = 1000000007 ;
//long double pie = acos(-1) ;
//ll INF = 1000000000000 ;

//void yorn(bool a){if(a) cout << "Yes" << endl ; else cout << "No" << endl ;}
//void YorN(bool a){if(a) cout << "YES" << endl ; else cout << "NO" << endl ;}
//ll gcd(long long a,long long b){if(b==0) return a ; return gcd(b,a%b) ;}
//ll lcm(long long a,long long b){return a/gcd(a,b)*b ;}
//ll sa(long long a,long long b){if(a>b) return a-b ; return b-a ;}
//void mysort(vector<long long> &a){sort(a.begin(),a.end()) ;}
//void myrev(vector<long long> &a){reverse(a.begin(),a.end()) ;}
//void fix_cout(){cout << fixed << setprecision(20) ;}

int main(){
	ll n ; cin >> n ;
	cout << n/11*2+(n%11==0?0:(n%11>6)+1) << endl ;
}


Measured memory_bytes: 256
def calc_at(H):
    # 2の0~n乗まで足す
    num = 0
    n = 0
    while True:
        n_beki2 = 2 ** n
        if H < n_beki2:
            break
        num += n_beki2
        n += 1
    return num


H = int(input())
print(calc_at(H))


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

int main(){
    int N, Y;
    cin >> N >> Y;
    bool counter = true;
    for (int i = 0; i <= N; ++i){
        if (counter == false) break;

        for (int j = 0; j <= N; ++j){
            if (i + j <= N && 10000 * i + 5000 * j + 1000 * (N - i - j) == Y){
                cout << i << " " << j << " " << N - i - j << endl;
                counter = false;
                break;
            }
        }
    }

    if (counter) cout << "-1 -1 -1" << endl;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String result = "Yes";
        char[] s = sc.next().toCharArray();
        for(int i = 0; i < s.length; i++) {
            if((i % 2 == 0 && s[i] == 'L') || (i % 2 == 1 && s[i] == 'R')) result = "No";
        }
        System.out.println(result);
    }
}


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

#define INF 900000000
#define LINF 9000000000000000000

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

int n, m1, m2;
int a[40], b[40], c[40];
int dp[41][401][401];

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

	cin >> n >> m1 >> m2;
	for (int i = 0; i <= n; i++) cin >> a[i] >> b[i] >> c[i];

	for (int i = 0; i <= 40; i++) for (int j = 0; j < 401; j++) for (int k = 0; k < 401; k++)
		dp[i][j][k] = INF;

	dp[0][0][0] = 0;
	for (int i = 0; i < n; i++) {
		for (int j = 0; j <= 400; j++) {
			for (int k = 0; k <= 400; k++) {
				if (dp[i][j][k] == INF) continue;
				dp[i+1][j][k] = min(dp[i+1][j][k], dp[i][j][k]);
				dp[i+1][j+a[i]][k+b[i]] = min(dp[i][j][k]+c[i], dp[i+1][j+a[i]][k+b[i]]);
			}
		}
	}

	int ans = INF;
	for (int j = 1; j <= 400; j++) {
		for (int k = 1; k <= 400; k++) {
			if (j*m2 == k*m1) {
				ans = min(ans, dp[n][j][k]);
			}
		}
	}

	if (ans == INF) ans = -1;
	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 25984
#ifndef _GLIBCXX_NO_ASSERT
#include <cassert>
#endif
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>

#if __cplusplus >= 201103L
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cwchar>
#include <cwctype>
#endif

// C++
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>

#if __cplusplus >= 201103L
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#endif


using namespace std;

// #define int long long
struct Fast {Fast(){std::cin.tie(0);ios::sync_with_stdio(false);}} fast;

inline bool inside(int y, int x, int H, int W) {return y >= 0 && x >= 0 && y < H && x < W;}
int gcd(int a,int b){return b?gcd(b,a%b):a;}
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};

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

signed main() {
    Fast();

    int n, m;
    cin >> n >> m;
    vector<int> cnt(m);

    for(int i=0; i<n; i++){
        int k;
        cin >> k;
        while(k--){
            int a;
            cin >> a;
            cnt[a-1]++;
        }
    }


    int ans = 0;
    for(int i=0; i<m; i++)
        ans += (cnt[i] == n ? 1 : 0);

    cout << ans << endl;

    return 0;
}



Measured memory_bytes: 504
var Multiply = {
  start: 1,
  end: 10,
  equation: function(multiplicand) {
    for(i=1; i<this.end; i++) {
      console.log(multiplicand + "x" + i + "=" + multiplicand*i);
    }
  },
  solve: function() {
    for(multiplicand=1; multiplicand < this.end; multiplicand++) {
      this.equation(multiplicand);
    }
    return;
  }
}
Multiply.solve();

Measured memory_bytes: 15392
#include <iostream> // cout, endl, cin
#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> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <cmath>
#include <iomanip>
#include <ctype.h>
#include <bitset>
#include <boost/multiprecision/cpp_int.hpp>
#include <boost/multiprecision/cpp_dec_float.hpp>

using namespace std;
using ll = long long;
using PAIR = pair<int, int>;
using PAIRLL = pair<ll, ll>;
using vi = vector<int>;
using vvi = vector<vi>;

namespace mp = boost::multiprecision;
using Bint = mp::cpp_int;
using boost::multiprecision::cpp_dec_float_100;

#define rep(i,N) for(ll i=0;i<(ll)N;++i)

ll GCD(ll x, ll y) {
    if (y == 0) return x;
    else return GCD(y, x % y);
}

ll LCM(ll x, ll y) {
    return x / GCD(x, y) * y;
}

bool my_compare(pair<string, int> a, pair<string, int> b) {
    if (a.first != b.first) {
        return a.first < b.first;
    }

    if (a.second != b.second) {
        return a.second > b.second;
    }
    else {
        return true;
    }
}

int main()
{
    ll N, K;
    cin >> N >> K;

    vector<ll> A(N+1);

    for (ll i = 1; i <= N; ++i) cin >> A[i];

    vector<ll> T(N+1), S(N+1);

    for (ll i = 1; i <= N; ++i) {
        T[i] = A[i];
    }

    T[0] = 1;
    S[0] = 1;

    for (ll i = 1; i <= N; ++i) {
        T[i] = A[T[i - 1]];
        S[i] = T[i];
    }

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

    ll x=0;

    rep(i,N+1) {
        if (S[i] == S[i + 1]) {
            x = S[i];
            break;
        }
    }

    deque<ll> deq;

    int k = 0;

    rep(i,N+1) {
        if (T[i] == x) { 
            deq.push_back(i);
            ++k;
        }
        if (k == 2) { break; }
    }

    ll p = deq[0], q = deq[1];

    if (K >= p) {
        if ((K - p + 1) % (q - p) == 0) { cout << T[q - 1] << endl; }
        else { cout << T[(K - p + 1) % (q - p) + p - 1] << endl; }
    }
    else {
        cout << T[K] << endl;
    }
}

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

int main() {
  string s;
  cin >> s;
  if ((s[2] == s[3]) && (s[4] == s[5])) {
    cout << "Yes" << endl;
  } else cout << "No" << endl;
  return 0;
}

Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define all(x) (x).begin(),(x).end()
#define ln '\n'
const long long MOD = 1000000007LL;
//const long long MOD = 998244353LL;
typedef long long ll;
typedef unsigned long long ull; 
typedef pair<int, int> pii;
typedef pair<long long, long long> pll;
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; }
///////////////////////////////////////////////////////////////////////////////////////////////////

int mov[101010][50];

int main() {
    ios::sync_with_stdio(false); cin.tie(nullptr);
	int N; cin >> N;
	vector<ll> x(N);
	rep(i,N) cin >> x[i];
	ll L; cin >> L;

	rep(i,N-1) {
		int k = upper_bound(all(x),x[i]+L) - x.begin();
		mov[i][0] = k-1;
	}
	mov[N-1][0] = N;
	rep(k,40) {
		rep(i,N) {
			mov[i][k+1] = mov[i][k] == N ? N : mov[mov[i][k]][k];
		}
	}

	int Q; cin >> Q;
	while (Q--) {
		int a,b; cin >> a >> b;
		--a; --b;
		if (a > b) swap(a,b);
		int ans = 0;
		int cur = a;
		while (cur < b) {
			for (int k = 40; k >= 0; --k) {
				if (mov[cur][k] <= b) {
					ans += 1<<k;
					cur = mov[cur][k];
					break;
				}
				if (k==0 && mov[cur][k] > b) {
					cur = b;
					ans++;
				}
			}
		}
		cout << ans << ln;
	}
}


Measured memory_bytes: 21120
from math import cos, radians, sqrt

a, b, h, m = map(int, input().split())

minutes_in_hour = 60
minutes_in_12h = 12*60

mins = 60*h + m

ang_hour = 360 * mins / minutes_in_12h
ang_min = 360 * m / minutes_in_hour

ang_betw = radians( (ang_hour - ang_min + 360) % 360)

c = sqrt(a*a + b*b - 2 * b *a * cos(ang_betw))
print(c)


Measured memory_bytes: 62468
/*  -*- coding: utf-8 -*-
 *
 * e.cc: E - Knapsack 2
 */

#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 = 100;
const int MAX_V = 1000;
const int MAX_NV = MAX_N * MAX_V;
const int INF = 1 << 30;

/* typedef */

/* global variables */

int dp[MAX_NV + 1];

/* subroutines */

/* main */

int main() {
  int n, w;
  scanf("%d%d", &n, &w);

  fill(dp, dp + MAX_NV + 1, INF);
  dp[0] = 0;

  for (int i = 0; i < n; i++) {
    int wi, vi;
    scanf("%d%d", &wi, &vi);

    for (int j = MAX_NV - vi; j >= 0; j--)
      if (dp[j] < INF) {
	int d = dp[j] + wi;
	if (d <= w && dp[j + vi] > d) dp[j + vi] = d;
      }
  }

  int maxv = MAX_NV;
  while (maxv > 0 && dp[maxv] >= INF) maxv--;
  printf("%d\n", maxv);
  return 0;
}


Measured memory_bytes: 640
#include<bits/stdc++.h>
#define range(i,a,b) for(int i = (a); i < (b); i++)
#define rep(i,b) for(int i = 0; i < (b); i++)
#define all(a) (a).begin(), (a).end()
#define show(x)  cerr << #x << " = " << (x) << endl;
#define int long long
using namespace std;

template <typename X, typename T>
auto vectors(X x, T a) {
	return vector<T>(x, a);
}

template <typename X, typename Y, typename Z, typename... Zs>
auto vectors(X x, Y y, Z z, Zs... zs) {
	auto cont = vectors(y, z, zs...);
	return vector<decltype(cont)>(x, cont);
}

template<typename T>
ostream& operator << (ostream& os, vector<T>& v){
	rep(i,v.size()){ os << v[i] << (i == v.size() - 1 ? "" : " "); } return os;
}
template<typename T>
istream& operator >> (istream& is, vector<T>& v){
	for(T& x: v){ is >> x; } return is;
}

signed main(){
	int n, m;
	while(cin >> n >> m, n||m){
		vector<int> a(n);
		cin >> a;

		vector<int> b;
		rep(i,a.size()){
			range(j,i + 1, a.size()){
				b.emplace_back(a[i] + a[j]);
			}
		}
		sort(all(b), greater<int>());

		if(b.back() > m){
			cout << "NONE" << endl;
		}else{
			rep(i,b.size()){
				if(b[i] <= m){
					cout << b[i] << endl;
					break;
				}
			}
		}
	}
}



Measured memory_bytes: 10760
#include <bits/stdc++.h>
using namespace std;
#define rep(i, s, n) for (int i = (s); i < (int)(n); i++)
#define all(v) v.begin(), v.end()
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
using ll = long long;
const ll MOD = 1e9+7; ll LLINF = 1LL << 60; int INF = INT_MAX;

//

int main(){
    int a,b,c; cin>>a>>b>>c;
    cout<<min(c,b/a)<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define var auto
using namespace std;
using ll = long long;
using P = pair<int, int>;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const ll INF = 1LL << 60;
const int MAX_ITEM = 110;
const int MAX_VALUE = 100100;
ll dp[MAX_ITEM][MAX_VALUE]; // 重さ

int main() {
  int n;
  ll w;
  cin >> n >> w;
  ll weight[n];
  ll value[n];
  rep(i,n) {
    cin >> weight[i] >> value[i];
  }

  // 最小化問題なのでINF埋め
  rep(i,MAX_ITEM) {
    rep(j,MAX_VALUE) dp[i][j] = INF;
  }

  // 初期値00だけ0にする
  dp[0][0] = 0;
  
  // N個の品物の数ループ
  rep(i,n) {
    // 価値が 0->10^3*100 になるまで 1+v 回ループ
    rep(limit, 1+MAX_VALUE) {
      // 選ばない場合
      chmin(dp[i+1][limit], dp[i][limit]);

      // 選びたい
      if (limit - value[i] >= 0) {
        // 選んだ
        chmin(dp[i+1][limit], weight[i] + dp[i][limit - value[i]]);
      }
    }
  }

  // 10^3*100 の1次配列中から dp[i][sum_v]<w を満たす sum_v を見つける
  ll res;
  rep(i,MAX_VALUE) {
    if(dp[n][i] <= w) res = i;
  }

  cout << res << endl;
}


Measured memory_bytes: 86272
//code by lynmisakura.wish to be accepted!
/****************************/
#include<iostream>
#include<iomanip>
#include<math.h>
#include<vector>
#include<string>
#include<stack>
#include<queue>
#include<map>
#include<algorithm>
#include<bitset>
#include <climits>
#include<set>
#include<bitset>
using namespace std;
/***************************/
typedef long long ll;

//const long long INF = 1LL << 55;

#define itn ll
#define endl '\n'
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define ss second
#define ff first
#define dup(x,y) ((x) + (y) - 1)/(y)
#define mins(x,y) x = min(x,y)
#define maxs(x,y) x = max(x,y)
#define all(x) (x).begin(),(x).end()
#define Rep(n) for(ll i = 0;i < n;i++)
#define rep(i,n) for(ll i = 0;i < n;i++)
#define flush fflush(stdout)
#define rrep(i,n) for(ll i = n - 1;i >= 0;i--)
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() )
#define ioboost cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(20)
ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
ll qp(ll a, ll b) { ll ans = 1; do { if (b & 1)ans = 1ll * ans*a; a = 1ll * a*a; } while (b >>= 1); return ans; }
ll qp(ll a, ll b, ll mo) { ll ans = 1; do { if (b & 1)ans = 1ll * ans*a%mo; a = 1ll * a*a%mo; } while (b >>= 1); return ans; }

#define _GLIBCXX_DEBUG
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl

int main(void){
    int a,b,c,d,e,f;cin >> a >> b  >> c >> d >> e >> f;

    vector<int> s(9000000,0);
    for (int i = 0; i < 3000; ++i) {
        for (int j = 0; j < 3000; ++j) {
            s[i*c + j*d]++;
        }
    }

    //xグラム以下の最大の砂糖
    vector<int> maxsugar(3010,0);
    for (int i = 0; i < 3010; ++i) {
        if(s[i]){
            maxsugar[i] = i;
        }else {
            maxsugar[i] = maxsugar[i - 1];
        }
    }

    //答え
    int ans_s = 0,ans_w = 0;
    double ans = 0;

    for (int i = 0; i < 30; ++i) {
        for (int j = 0; j < 30; ++j) {
            int water = 100 * (i * a + j * b);
            if(water > f)continue;

            int left = f - water;

            int s_max = e * (i * a + j * b);

            int insugar = maxsugar[min(left,s_max)];

            double d = (double)(100 * (insugar))/(double)(water + insugar);
            if(d > ans){
                ans = d;
                ans_s = insugar;
                ans_w = water;
            }
        }
    }
    if(ans_s == 0)ans_w = 100 * min(a,b);
    cout << ans_w + ans_s << " " << ans_s << endl;

}


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

using ll=long long;
const ll MOD=1000000007;

int main() {
  int N;
  cin >> N;
  ll ans=0;
  vector<int> A(N);
  for(int i=0;i<N;i++)
    cin >> A[i];
  sort(A.begin(),A.end());
  for(int i=0;i<N-1;i++){
    for(int j=i+1;j<N;j++){
      int r=lower_bound(A.begin(),A.end(),A[i]+A[j])-A.begin();
      ans +=r-j-1;
    }
  }
  cout << ans << endl;
}


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

int main(){
    int a, b;
    cin >> a >> b;
    cout << 6 - a - b << endl;
}

Measured memory_bytes: 3656
#include <algorithm>
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <cstdio>
#include <cmath>
#include <queue>
#include <map>

using namespace std;

int main(int argc, char *argv[])
{
  int A, B, T;

  cin >> A >> B >> T;
  int v = max((T/A)*B, 0);
  cout << v << endl;
  return 0;
}


Measured memory_bytes: 256
while True:
    n, r = map(int, input().split())
    if n == 0 and r == 0:
        break
    cards = [i + 1 for i in range(n)]
    cards.reverse()
    for _ in range(r):
        p, c = map(int, input().split())
        new_cards = cards[p - 1 :p - 1 + c] + cards[0:p - 1] + cards[p - 1 + c:]
        cards = new_cards
    print(cards[0])


Measured memory_bytes: 5620
#include <iostream>
#include <vector>
#include <algorithm>

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

using namespace std;

typedef struct Edge
{
  int id;
  int to;
  int color;
  Edge(int i, int t):id(i),to(t),color(-1){}
}Edge;
typedef struct Node
{
  int id;
  int parent;
  vector<Edge> children;
  Node():parent(-1){}
  int edgeColor(int childid)
  {
    for(auto c : children)
    {
      if(c.to == childid) return c.color;
    }
    return -1;
  }
  void printColor()
  {
    for(auto c : children)
      cout << id+1 << "->" << c.to+1 << ":" << c.color << endl;
    cout << endl;
  }
}Node;

int findTop(vector<Node>& v)
{
  for(auto i : v)
  {
    if(i.parent == -1) return i.id;
  }
  return -1;
}

void color(vector<Node>& vtx, int id, int k, int* colors)
{
  int col;
  if(vtx[id].parent != -1)
    col = (vtx[vtx[id].parent].edgeColor(id) % k) + 1;
  else
    col = 1;
  for(auto& c : vtx[id].children)
  {
    c.color = col;
    colors[c.id] = col;
    col = (col % k) + 1;
    color(vtx, c.to, k, colors);
  }
}

int main()
{
  int n;
  cin >> n;
  vector<Node> vtx(n);
  int a, b;
  rep(i, n - 1)
  {
    cin >> a >> b;
    --a;--b;
    vtx[a].id = a;
    vtx[a].children.push_back(Edge(i, b));
    vtx[b].parent = a;
  }
  int k = 0;
  rep(i, n)
  {
    int hasParent = vtx[i].parent != -1 ? 1 : 0;
    k = max(k, static_cast<int>(vtx[i].children.size() + hasParent));
  }
  cout << k << endl;

  int startid = findTop(vtx);
  int colors[n-1];
  color(vtx, startid, k, colors);
  rep(i, n-1)
    cout << colors[i] << endl;
  //  vtx[i].printColor();
  return 0;
}


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

int main(){
  int n, a[101], r = 0;
  scanf("%d", &n);
  for(int i = 0; i < n; i++){
    scanf("%d", a + i);
    if(i && a[i] == a[i - 1]){
      r++;
      a[i] = -i - 1;
    }
  }
  printf("%d\n", r);
}

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

using namespace std;

#define rep(i, n) for (int i = 0; i < (int)n; ++i)
#define FOR(i, a, b) for (int i = a; i < (int)b; ++i)
#define rrep(i, n) for (int i = ((int)n - 1); i >= 0; --i)

using ll = long long;
using ld = long double;

const ll INF = 1e18;
const int Inf = 1e9;
const double EPS = 1e-9;
const ll MOD = 1e9 + 7;

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(0);
    double a, b, h, m;
    cin >> a >> b >> h >> m;
    cout << fixed << setprecision(10);
    double start = h * 30 + m * 0.5;
    double s = m * 6;
    double diff = start - s;
    if (diff < 0) diff += 360;
    double rad = diff * M_PI / 180;
    cout << sqrt(a * a + b * b - 2 * a * b * cos(rad)) << endl;
    
    return 0;
}



Measured memory_bytes: 4232
#include <bits/stdc++.h>
#define FIXED_FLOAT(x)  std::fixed <<std::setprecision(7)<<(x)
#define all(v) (v).begin(), (v).end()
using namespace  std;
#define loop(i,a,b) for (int i=a; i<b; ++i)
using ll = long long;
const int mod = 1e5;
typedef pair<int , int> pairs;
typedef complex<ll> G;

const int N = 1e3 + 10;

int power(int a,int b, int q){
    if(!b)
        return 1;
    int c=power(a,b/2, q);
    c=(1LL*c*c)%q;
    if(b%2)
        c=(1LL*c*a)%q;
    return c;
}

vector<int>dis(N);
vector<bool>vis(N);
vector<int>c[N];
int far;
int ans;
int now;
void aff(int s, int e, int d) {
    if(vis[s])return;
    vis[s] = true;
    dis[s] = d;
    ans = max(ans, dis[s]);
    for(auto u : c[s]) {
        if(u == e)continue;
        aff(u, s, d + 1);
    }
}
void dfs(int s, int e, int d) {

    if(vis[s])return;

    dis[s] = d;
    if(now < d) {
        far = s;
        now = d;
    }
    vis[s] = true;
    for(auto u : c[s]) {
        if(u == e)continue;
        dfs(u, s, d + 1);
    }
}
void done() {
    int n;
    cin >> n;
    for(int i = 1;i < n;++i) {
        int a,b;
        cin >> a >> b;
        c[a].push_back(b);
        c[b].push_back(a);
    }
    if(n == 1) {
        cout << 0 << '\n';
        return;
    }
    far = 0;
    now = 0;
    ans = 0;
    dfs(1, 0, 0);

    fill(vis.begin(), vis.end(), 0);
    fill(dis.begin(), dis.end(), 0);
    aff(far, 0, 0);
    cout << ans * 3 << '\n';

}
/*string solve_palindrome(const string& s)
{
    string a = s;
    reverse(a.begin(), a.end());
    //a = s + "#" + a;
    int c = 0;
    for (int i = 1; i < (int)a.size(); i++)
    {
        while (c != 0 && a[c] != a[i])
            c = pref[c - 1];
        if (a[c] == a[i])
            c++;
        pref[i] = c;
    }
    return s.substr(0, c);
}
*/

/*3
3 7 7 9 11
4 6 6 7*/
void solve()
{
    int n;
    cin >> n;
    string s;
    cin >> s;
    if(n <= 2)   {
        cout << 0 << '\n';
        return;
    }
    int ans = 0;
    for(int i = 0;i < n-2;++i) {
        if(s[i] == '0' && s[i + 1] == '1' && s[i + 2] == '0') {
            ++ans;
            s[i + 2] = '1';
        }
    }
    cout << ans << '\n';
}
int cal(int  n) {
    string s = to_string(n);
    int ans = 0;
    for(int i = 0;i < s.size();++i) {
        ans += s[i] - '0';
    }
    return ans;
}
int sum(long long n) {
	int res = 0;
	while (n > 0) {
		res += n % 10;
		n /= 10;
	}
	return res;
}

void another() {
    long long  a, b, c, d;
    cin >> a >> b >>  c >> d;
    cout << max(a * c, max(a * d, max(b * c, b * d))) << '\n';
}


void test_case() {
    int t;
    cin >> t;
    while(t--)solve();
}
int main() {

    ios::sync_with_stdio(NULL); cin.tie(0); cout.tie(0);

    another();
}


Measured memory_bytes: 3684
#include <iostream>
#include <vector>
using namespace std;
int main(){
  int n, m, ans;
  cin >> n >> m;
  vector<int> a(n);
  vector<int> c;
  for(int i=0;i<n;i++){
    cin >> a[i];
    c.push_back(1);
  }
  vector<vector<int> > b(m, vector<int>(2));
  for(int i=0;i<m;i++){
    for(int j=0;j<2;j++){
      cin >> b[i][j];
      b[i][j]--;
    }
  }
  for(int i=0;i<m;i++){
    if(a[b[i][0]] < a[b[i][1]]){
      c[b[i][0]] = -1;
    }else if(a[b[i][1]] < a[b[i][0]]){
      c[b[i][1]] = -1;
    }else{
      c[b[i][0]] = c[b[i][1]] = -1;
    }
  }
  ans = 0;
  for(int i=0;i<n;i++){
    if(c[i] == 1){
      ans++;
    }
  }
  cout << ans;
}


Measured memory_bytes: 9408
// In The Name Of Allah //
#include <bits/stdc++.h>
#define pb emplace_back
#define inf (int)1e9
#define ff first
#define ss second
#define ll long long
#define sp(n) cout << setprecision(n) << fixed
#define hellcat ios::sync_with_stdio(0), cin.tie(0), cout.tie(0)
#define give(x) cout << #x << " " << x << endl
#define debug cout << "dddd" << '\n'
#define debarr(a, n) for (int i = 0; i < n; ++i) cout << a[i] << ' '; cout << endl
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops")
#pragma GCC optimize("no-stack-protector,fast-math")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
using namespace std;

template <class S, class T>
inline S smax(S &l, T r) {
  return l = max(l, (S)r);
}
template <class S, class T>
inline bool smin(S &l, T r) {
  return l = min(l, (S)r);
}

void lcs( char *X, char *Y, int m, int n ) { 
   int L[m+1][n+1]; 
   for (int i=0; i<=m; i++) 
   { 
     for (int j=0; j<=n; j++) 
     { 
       if (i == 0 || j == 0) 
         L[i][j] = 0; 
       else if (X[i-1] == Y[j-1]) 
         L[i][j] = L[i-1][j-1] + 1; 
       else
         L[i][j] = max(L[i-1][j], L[i][j-1]); 
     } 
   } 
  
   int index = L[m][n]; 
 
   char lcs[index+1]; 
   lcs[index] = '\0';
  
   int i = m, j = n; 
   while (i > 0 && j > 0) 
   { 
      if (X[i-1] == Y[j-1]) 
      { 
          lcs[index-1] = X[i-1];
          i--; j--; index--;    
			} 
      else if (L[i-1][j] > L[i][j-1]) 
         i--; 
      else
         j--;
		}

   cout << lcs << '\n';
}

int32_t main () {
  hellcat;

	string s, t;
	cin >> s >> t;

	int n = s.size(), m = t.size();
	char x[n+1], y[m+1];

	for (int i = 0; i < n; ++i)
		x[i] = s[i];
	for (int i = 0; i < m; ++i)
		y[i] = t[i];

	lcs(x, y, n, m);

	return 0;
}


Measured memory_bytes: 35456
import sys,heapq
from collections import deque,defaultdict
printn = lambda x: sys.stdout.write(x)
inn = lambda : int(input())
inl   = lambda: list(map(int, input().split()))
inm   = lambda:      map(int, input().split())
DBG = True # and False
def ddprint(x):
  if DBG:
    print(x)

l,r = inm()
if r-l >= 2018:
    print(0)
    exit()
mn = 2020
for i in range(l,r):
    for j in range(i+1,r+1):
        s = (i*j)%2019
        if s < mn:
            mn = s
print(mn)


Measured memory_bytes: 41196
#include <bits/stdc++.h> 
using namespace std; 
#define for_(i, s, e) for (int i = s; i < e; i++)
#define for__(i, s, e) for (ull i = s; i < e; i++)
#define SSTR(x) static_cast<std::ostringstream&>((std::ostringstream() << std::dec << x)).str()
typedef unsigned long long ull;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> ii;


int main() {
    #ifndef ONLINE_JUDGE
	freopen("test.in", "r", stdin);
    #endif
    
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int n; cin >> n;
    string s; cin >> s;
    unordered_set<int> r, g, b;
    for_(i, 0, n) {
        if (s[i] == 'R') r.insert(i);
        else if (s[i] == 'G') g.insert(i);
        else b.insert(i);
    }
    ull all = r.size() * b.size() * g.size();
    ull inv = 0;
    for (int i: r) for (int j: b) {
        int mx = max(i, j), mn = min(i, j);
        if (g.count(2*mx - mn) != 0) inv += 1;
    }
    for (int i: r) for (int j: g) {
        int mx = max(i, j), mn = min(i, j);
        if (b.count(2*mx - mn) != 0) inv += 1;
    }
    for (int i: b) for (int j: g) {
        int mx = max(i, j), mn = min(i, j);
        if (r.count(2*mx - mn) != 0) inv += 1;
    }
    cout << all - inv << endl;


    return 0;
}

Measured memory_bytes: 3836
#include<iostream>
#include<algorithm>
#include<stdlib.h>
#include<iomanip>
#include<string>
#include<math.h>
 
using namespace std;
 
 
int main(){
    int n;
    cin>>n;
    int a,b;
    long long ka,kb;
    long long ansa,ansb;
    cin>>a>>b;
    ansa=a;
    ansb=b;
    for(int i=1;i<n;i++){
        cin>>a>>b;
        ka=ansa/a;
        if(ansa%a)ka++;
        kb=ansb/b;
        if(ansb%b)kb++;
        ka=max(ka,kb);
        ansa=a*ka;
        ansb=b*ka;
    }
    cout<<ansa+ansb<<endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define int long long
#define mod 1000000007
#define inf 1e18
using namespace std;
int dp[3001][3001];

int solve(int *a,int i,int j){
    if(i>j){
        return 0;
    }
    if(dp[i][j]!=inf){
        return dp[i][j];
    }
    if(i==j){
        return dp[i][j]=a[i];
    }
    int op1=a[i]+min(solve(a,i+2,j),solve(a,i+1,j-1));
    int op2=a[j]+min(solve(a,i,j-2),solve(a,i+1,j-1));
    return dp[i][j]=max(op1,op2);
}
int32_t main(){
    int n;
    cin>>n;
    int a[n+1];
    int sum=0;
    for(int i=1;i<=n;i++){
        cin>>a[i];
        sum+=a[i];
    }
      for(int i=1;i<=n;i++){
        for(int j=1;j<=n;j++){
            dp[i][j]=inf;
        }
    }    
  
    int x=solve(a,1,n);
    int y=sum-x;
    int ans=x-y;
    cout<<ans<<endl;
    return 0;
}

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

#define ll long long
#define PB push_back
#define PII pair<int, int>
#define MP make_pair
#define all(x) x.begin(), x.end()
#define REP(x, y, z) for(int x = y; x <= z; x++)
#define REPP(x, y, z) for(int x = y; x >= z; x--)
#define F first
#define S second
#define MSET(x, y) memset(x, y, sizeof(x)) 
#define EB emplace_back
#define maxn

//structure

//declaration

//functions

int main(void)
{
	#ifdef DBG
	freopen("in.in", "r", stdin);
	freopen("out.out", "w", stdout);
	#endif

    ll a, b;

    cin >> a >> b;

    cout << a*b/__gcd(a,b) << '\n';

	return 0;
}


Measured memory_bytes: 256
N, K = map(int, input().split())
heights = sorted([int(input()) for _ in range(N)])
ans = float('inf')
for i in range(N - K + 1):
    if abs(heights[i] - heights[i + K - 1]) < ans:
        ans = abs(heights[i] - heights[i + K - 1])
print(ans)

Measured memory_bytes: 8280
#include <bits/stdc++.h> // Tomasz Nowak
using namespace std;     // XIII LO Szczecin
using L = long long;

#define FOR(i, l, r) for(int i = l; i <= r; ++i)
#define REP(i, n) FOR(i, 0, n - 1)
constexpr int inf = 0x3f3f3f3f;
template<class T> int size(T &x) {
	return int(x.size());
}

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

	int n, m;
	cin >> n >> m;
	vector<vector<int>> graph(n);
	vector<int> indeg(n);
	while(m --> 0) {
		int v, u;
		cin >> v >> u;
		graph[--v].emplace_back(--u);
		++indeg[u];
	}

	deque<int> que;
	REP(v, n)
		if(indeg[v] == 0)
			que.emplace_back(v);

	vector<int> order;
	while(size(que)) {
		int v = que.front();
		que.pop_front();
		order.emplace_back(v);

		for(int u : graph[v])
			if(--indeg[u] == 0)
				que.emplace_back(u);
	}
	reverse(order.begin(), order.end());

	int answer = 1;
	vector<int> dp(n);
	for(int v : order)
		for(int u : graph[v])
			answer = max(answer, dp[v] = max(dp[v], dp[u] + 1));
	cout << answer << '\n';
}



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

int main() {
  int a,b,c,k;
  int total = 0;
  cin >> a >> b >> c >> k;
	if(k<=a){
      total = k;
    }
    else if(k>a && k <= b ){
      total = a;
    }
    else if(k>b){
    	total = a+a+b-k;
    }
  cout << total << endl;
  

}


Measured memory_bytes: 3556
import java.util.*;

public class Main{

	public static void main(String[] args){
           
            Scanner sc = new Scanner(System.in);
                   
            String S = sc.next();
            
            char s = S.charAt(0);
            char g = S.charAt(S.length() - 1);
          
            int size = S.length() - 2;
            
            System.out.println(s + String.valueOf(size) + g);            
            
        }        
}

Measured memory_bytes: 23124
#include <iostream>
#include <vector>

using namespace std;

int main(int argc, char const *argv[])
{
    int N;
    cin >> N;
    int tmp;
    int cnt[10] = {0};
    for (int i = 0; i < N; i++)
    {
        cin >> tmp;
        if (tmp <= 399)
        {
            cnt[0] += 1;
        }else if (tmp <= 799)
        {
            cnt[1] += 1;
        }else if (tmp <= 1199)
        {
            cnt[2] += 1;
        }else if (tmp <= 1599)
        {
            cnt[3] += 1;
        }else if (tmp <= 1999)
        {
            cnt[4] += 1;
        }else if (tmp <= 2399)
        {
            cnt[5] += 1;
        }else if (tmp <= 2799)
        {
            cnt[6] += 1;
        }else if (tmp <= 3199)
        {
            cnt[7] += 1;
        }else if (tmp >= 3200)
        {
            cnt[8] += 1;
        }
        
    }

    int sum = 0;
    for (int i = 0; i <= 7; i++)
    {
        if (cnt[i] != 0)
        {
            sum += 1;
        }
        
    }
    
    int max, min;
    if (0 == cnt[8])
    {
        max = sum;
        min = sum;
    }else{
        if (0 == sum)
        {
            min = 1;
            max = sum + cnt[8];
        }else{
            min = sum;
            max = sum + cnt[8];
        }
        
    }

    cout << min << ' ' << max << endl;

    return 0;
}

Measured memory_bytes: 888
#include <iostream>
#include <vector>
#include <utility>
#include <map>
#include <algorithm>
#include <queue>
#include <cmath>

using namespace std;


int main() {
  long long n,k;
  cin >> n >> k;
  vector<long long> a(n);
  vector<long long> f(n);

  for (int i=0; i<n; i++) cin>>a[i];
  for (int i=0; i<n; i++) cin>>f[i];

  sort(a.begin(),a.end());
  sort(f.rbegin(),f.rend());

  long long l = -1;
  long long r = 1e12;
  while(l+1 < r) {
    long long g = (l+r)/2;
    bool flag = true;

    long long count = 0;
    for (long long i=0; i<n; i++) {
      count += max(0LL,(a[i] - g/f[i]));
      if (count > k) {
        flag=false;
        break;
      }
    }
    (flag? r : l) = g;
  }

  cout << r << endl;
}

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

int main(){
  while(1){
    int n,m;
    cin>>n>>m;
    if(n==0&& m==0) break;
    int a[1000];
    lp(i,n){
      cin>>a[i];
    }
    sort(a,a+n);
    reverse(a,a+n);
    int ans=0;
    lp(i,n){
      if((i+1)%m==0) continue;
      else ans+=a[i];
    }
    cout<<ans<<endl;
  }
  return 0;
}



Measured memory_bytes: 3148
import sys 
input = sys.stdin.readline

def slove():
    n = int(input())
    A = sorted(list(map(int,input().split())))
    a_max = A[-1]+1
    B = [0] * a_max
    for value in A:
        B[value] += 1
        for i in range(value*2,a_max,value):
            B[i] += 2
    #print(B)
    print(B.count(1))

if __name__ == "__main__":
    slove()

"""
import sys
input = sys.stdin.readline

def slove():
    n = int(input())
    A = list(map(int,input().split()))
    A = sorted(A)
    ans = 0
    flag = False
    while len(A) != 0:
        ans += 1
        tmp = A.pop(0)
        #print(A)
        k = 0
        for i in range(len(A)):
            if A[i-k] % tmp == 0:
                if A[i-k] == tmp:
                    flag = True
                A.remove(A[i-k])
                k += 1
        if flag:
            ans -= 1
            flag = False
        
    print(ans)


if __name__ == "__main__":
    slove()
"""

Measured memory_bytes: 32228
// #include <bits/stdc++.h>
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <map>

#define rep(i,n) for (int i = 0; i < n; ++i)
#define repr(i,n) for (int i = n; i > 0; --i)
using namespace std;
using ll = long long;
using P = pair<int,int>;

const int MAX = 100;
const int INF = (1<<12);

int main() {
  int s;
  cin >> s;
  map<int,int> A;
  int i = 1;
  A[s] = i;
  while(1){
    if(s%2 == 0) {
      s /= 2;
    }
    else {
      s = 3 * s + 1;
    }
    i++;
    if(A[s]) {
      break;
    }
    else {
      A[s] = i;
    }
  }
  cout << i << endl;
  return 0;
}

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

int main(){
	int n,m,l;
	cin>>n>>m>>l;
	long long a[100][100],b[100][100],c[100][100];
	
	for(int i=0;i<n;i++){
		for(int j=0;j<m;j++) cin>>a[i][j];
	}
	for(int i=0;i<m;i++){
		for(int j=0;j<l;j++) cin>>b[i][j];
	}
	for(int i=0;i<n;i++){
		for(int j=0;j<l;j++) c[i][j]=0;
	}
	for(int i=0;i<n;i++){
		for(int j=0;j<l;j++){
			for(int k=0;k<m;k++){
				c[i][j]+=a[i][k]*b[k][j];
			}
		}
	}

	for(int i=0;i<n;i++){
		for(int j=0;j<l;j++){
			if(j==(l-1)){
				cout<<c[i][j]<<endl;
			}else{
				cout<<c[i][j]<<" ";
			}
		}
	}
	return 0;
}

Measured memory_bytes: 3332
class UnionFind:
    __slots__ = ["_data_size", "_roots"]

    def __init__(self, data_size: int) -> None:
        self._data_size = data_size
        self._roots = [-1] * data_size

    def __getitem__(self, x: int) -> int:
        while self._roots[x] >= 0:
            x = self._roots[x]
        return x

    def is_connected(self, x: int, y: int) -> bool:
        return self[x] == self[y]

    def unite(self, x: int, y: int) -> None:
        x, y = self[x], self[y]
        if x == y:
            return
        if self._roots[x] > self._roots[y]:
            x, y = y, x
        self._roots[x] += self._roots[y]
        self._roots[y] = x


def main():
    N, Q, *TUV = map(int, open(0).read().split())
    tree = UnionFind(N)
    res = []
    for t, u, v in zip(*[iter(TUV)] * 3):
        if t:
            res.append(int(tree.is_connected(u, v)))
        else:
            tree.unite(u, v)
    print("\n".join(map(str, res)))


if __name__ == "__main__":
    main()


Measured memory_bytes: 57916
import sys
sys.setrecursionlimit(10**7)
n=int(input())
s=[[]for i in range(n+1)]
t=[0]*(n-1)
for i in range(n-1):
    a,b=map(int,input().split())
    s[a-1].append([b-1,i])
def f(x,r):
    c=1
    for (i,j) in s[x]:
        c+=(c==r)
        t[j]=c 
        f(i,c)
        c+=1
f(0,0)
print(max(t))
for i in t:
    print(i)


Measured memory_bytes: 70968
import copy


def count(s):
    s = list(s)
    cnt = 0
    for i in range(1, len(s)):
        if s[i] == s[i-1]:
            s[i] = '*'
            cnt += 1
    return cnt


def main():
    S = input()
    K = int(input())
    if len(set(S)) == 1:
        return (len(S) * K) // 2

    else:
        n1 = count(S)
        n2 = count(S + S)
        return (K - 1) * (n2 - n1) + n1
            

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


Measured memory_bytes: 3444
#include <set>
#include <map>
#include <queue>
#include <ctime>
#include <cmath>
#include <cstdio>
#include <vector>
#include <string>
#include <cctype>
#include <bitset>
#include <cstring>
#include <cstdlib>
#include <utility>
#include <iostream>
#include <algorithm>
#define REP(i,a,b) for(int i=(a);i<=(b);i++)
#define PER(i,a,b) for(int i=(a);i>=(b);i--)
#define RVC(i,S) for(int i=0;i<(S).size();i++)
#define RAL(i,u) for(int i=fr[u];i!=-1;i=e[i].next)
using namespace std;
typedef long long LL;
typedef pair<int,int> pii;
     
template<class T> inline
void read(T& num) {
    bool start=false,neg=false;
    char c;
    num=0;
    while((c=getchar())!=EOF) {
        if(c=='-') start=neg=true;
        else if(c>='0' && c<='9') {
            start=true;
            num=num*10+c-'0';
        } else if(start) break;
    }
    if(neg) num=-num;
}
/*============ Header Template ============*/

const int maxn=(int)(1e5)+5;
LL a[maxn],b[maxn];

int main() {
    int n;
    read(n);
    REP(i,1,n) read(a[i]),read(b[i]);
    LL res=0,now=0;
    PER(i,n,1) {
        LL tmp=((a[i]+now-1)/b[i]+1)*b[i];
        if(a[i]+now==0) tmp=0;
        res+=tmp-a[i]-now;now=tmp-a[i];
    } 
    printf("%lld\n",res);
    return 0;
}

Measured memory_bytes: 1792