akhauriyash/Code-Regression huggingface dataset:
import java.util.*;
import java.util.concurrent.ThreadLocalRandom;
import java.io.*;

public class Main{
	static long[][]memo;
	static char[][] map;
	public static void main(String[] args) throws NumberFormatException, IOException, InterruptedException {
		// System.out.println("adfsf");
		Scanner sc = new Scanner(System.in);
		PrintWriter pw = new PrintWriter(System.out);
		int h=sc.nextInt();
		int w=sc.nextInt();
		map=new char[h][w];
		for (int i = 0; i < h; i++) {
			String s=sc.next();
			for (int j = 0; j < w; j++) {
				map[i][j]=s.charAt(j);
			}
		}
		//System.out.println(Arrays.deepToString(map));
		memo=new long[h][w];
		for (long[] x : memo) {
			Arrays.fill(x, -1);
		}
		memo[h-1][w-1]=1;
		System.out.println(dp(0,0));
	}
	static long dp(int h,int w) {
		if(memo[h][w]!=-1)
			return memo[h][w]=(long)(memo[h][w]%(1e9+7));
		if(map[h][w]=='#')
			return memo[h][w]=0;
		long x=0;
		if(valid(h+1,w))
			x+=dp(h+1,w);
		if(valid(h,w+1))
			x+=dp(h,w+1);
		return memo[h][w]=x%=(1e9+7);
		
	}
	private static boolean valid(int h, int i) {
		return h<map.length&&i<map[0].length;
	}
	static void shuffleArray(int[] ar) {
		// If running on Java 6 or older, use `new Random()` on RHS here
		Random rnd = ThreadLocalRandom.current();
		for (int i = ar.length - 1; i > 0; i--) {
			int index = rnd.nextInt(i + 1);
			// Simple swap
			int a = ar[index];
			ar[index] = ar[i];
			ar[i] = a;
		}
	}

	static class Scanner {
		StringTokenizer st;
		BufferedReader br;

		public Scanner(InputStream s) {
			br = new BufferedReader(new InputStreamReader(s));
		}

		public Scanner(FileReader r) {
			br = new BufferedReader(r);
		}

		public String next() throws IOException {
			while (st == null || !st.hasMoreTokens())
				st = new StringTokenizer(br.readLine());
			return st.nextToken();
		}

		public int nextInt() throws IOException {
			return Integer.parseInt(next());
		}

		public long nextLong() throws IOException {
			return Long.parseLong(next());
		}

		public String nextLine() throws IOException {
			return br.readLine();
		}

		public double nextDouble() throws IOException {
			return Double.parseDouble(next());
		}

		public int[] nextIntArr(int n) throws IOException {
			int[] arr = new int[n];
			for (int i = 0; i < arr.length; i++)
				arr[i] = nextInt();
			return arr;
		}

		public boolean ready() throws IOException {
			return br.ready();
		}
	}

}

Measured memory_bytes: 48124
#include <bits/stdc++.h>
#define rep(i, z, n) for(int i = z; i < n; i++)
#define all(v) v.begin(), v.end()
typedef long long ll;
//const int INF = 1<<29;
//const int MODINF = 1000000007;
using namespace std;

int main(){
    int N, x;
    cin >> N >> x;
    vector<int64_t> a(N);
    rep(i, 0, N) cin >> a.at(i);
    int64_t count = 0;
    rep(i, 0, N){
        if (a.at(i) > x){
            count += (a.at(i) - x);
            a.at(i) = x;
        }
    }
    rep(i, 0, N - 1){
        int64_t b = a.at(i + 1) + a.at(i);
        if (b > x){
            count += (b - x);
            a.at(i + 1) -= (b - x);
        }
    }
    cout << count << endl;
}

Measured memory_bytes: 1024
# input
N = int(input().rstrip())
V = list(map(int, input().rstrip().split()))
C = list(map(int, input().rstrip().split()))

# process
sV, sC = zip(*sorted(zip(V, C), reverse=True))

maxv = 0
for v, c in zip(sV, sC):
    sabun = v-c
    if sabun < 0:
        continue
    else:
        maxv += sabun
        
print(maxv)

Measured memory_bytes: 3064
#include <algorithm>
#include <bits/stdc++.h>
#include <cstdint>
#include <iostream>
#include <iterator>
#include <vector>

// lib/util.hpp
#ifndef UTIL_HPP
#define UTIL_HPP


typedef ::std::int_fast64_t i64;
typedef ::std::uint_fast64_t u64;
typedef ::std::int_fast32_t i32;
typedef ::std::uint_fast32_t u32;

namespace tools {
  template <typename T>
  void read(::std::istream& is, ::std::vector<T>& vector, const typename ::std::vector<T>::size_type size) {
    vector.reserve(size);
    ::std::copy_n(::std::istream_iterator<T>(is), size, ::std::back_inserter(vector));
  }
  template <typename T>
  void read(::std::vector<T>& vector, const typename ::std::vector<T>::size_type size) {
    ::tools::read(::std::cin, vector, size);
  }

  template <typename T, ::std::size_t N>
  void read(::std::istream& is, ::std::array<T, N>& array) {
    ::std::copy_n(std::istream_iterator<T>(is), N, array.begin());
  }
  template <typename T, ::std::size_t N>
  void read(::std::array<T, N>& array) {
    ::tools::read(::std::cin, array);
  }
}

#endif

// main.cpp

int main() {
  i64 N, A, B;
  std::cin >> N >> A >> B;
  std::cout << A * (N / (A + B)) + std::min(N % (A + B), A) << std::endl;
  return 0;
}

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


int solve(){
  int base[4] = {0,0,0,0};
  int out = 0;
  int p = 0;
  while(out < 3){
    string s;
    cin>>s;

    //cout<<s<<endl;

    if(s == "HIT"){
      p += base[3];
      base[0] = 1;
      for(int i=3;i;i--){
        base[i] = base[i-1];
        base[i-1] = 0;
      }
    }else if(s== "OUT"){
      out++;
    }else if(s=="HOMERUN"){
      base[0]=1;
      for(int i=0;i<4;i++){
        p += base[i];base[i]=0;
      }
    }
    /*
    for(int i=0;i<4;i++){
      cout<<base[i];
    }cout<<" "<<p<<endl;
    */
  }

  return p;
}

int main(){
  int n;
  cin>>n;
  for(int i=0;i<n;i++){
    cout<<solve()<<endl;
  }
}

Measured memory_bytes: 1212
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
using P = pair<ll,ll>;
const ll mod = 1e9+7;
#define ALL(x) (x).begin(),(x).end()
#define pow(x,y) modpow(x,y)
#define REP(i,n) for(ll (i)=0;(i)<(n);(i)++)
#define REPS(i,n) for(ll (i)=1;(i)<=(n);(i)++)
#define RREP(i,n) for(ll (i)=(n-1);(i)>=0;(i)--)
#define RREPS(i,n) for(ll (i)=(n);(i)>0;(i)--)
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define UNIQUE(v) v.erase(unique(ALL(v)),v.end());

template<class T> inline void chmin(T& a, T b){
    if (a > b){
        a = b;
    }
}

template<class T> inline void chmax(T& a, T b){
    if (a < b){
        a = b;
    }
}

signed main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout<<fixed<<setprecision(10);
    ll N;
    cin >> N;
    int sizes = to_string(N).size();
    if(sizes == 1){
        cout << N << "\n";
    }else if(to_string(N)[0] != to_string(N+1)[0]){
        cout << to_string(N)[0]-'0' + (sizes-1)*9 << "\n";
    }else{
        cout << to_string(N)[0]-'0'-1+(sizes-1)*9 << "\n";
    }
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <stdlib.h>
#include <cmath>
#include <algorithm>
#include <numeric>
#include <climits>
#include <iomanip>
#include <deque>
#include <limits>

using namespace std;

struct Rectangle {
  int H;
  int W;
};

int main()
{
  int n;

  cin >> n;

  for (int i = 1; i <= n; i++) {
    int x = i;
    if (x % 3 == 0) {
      cout << " " << i;
    }
    else {
      while (true) {
        if (x % 10 == 3) {
          cout << " " << i;
          break;
        }
        x /= 10;
        if (!x) break;
      }
    }
  }

  cout << endl;

  return 0;
}



Measured memory_bytes: 3104
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<n; i++)
using namespace std;
const int INF = 1001001001;

int main() {
    int n, m;
    cin >> n >> m;
    vector<vector<int>> to(n);
    rep(i,m) {
        int a, b;
        cin >> a >> b;
        a--; b--;
        to.at(a).push_back(b);
        to.at(b).push_back(a);
    }
    vector<int> pre(n, -1);
    vector<int> dist(n, INF);
    queue<int> q;
    q.push(0);
    while(!q.empty()) {
        int v = q.front();
        q.pop();
        for(int u: to[v]) {
            if(dist[u]!= INF) continue;
            dist[u] = dist[v] + 1;
            pre[u] = v;
            q.push(u);
        }
    }
    cout << "Yes" << endl;
    rep(i,n) {
        if(i == 0) continue;
        cout << pre[i] + 1 << endl;
    }
}


Measured memory_bytes: 10500
#include <bits/stdc++.h>
using namespace std;
#define finish(x) return cout << x << endl, 0
#define ll long long

int n;
vector <pair <int, int> > a;

int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cin >> n;
    a.resize(n);
    vector <pair <int, int> > E;
    for(int i = 0 ; i < n ; i++){
        int x, l;
        cin >> x >> l;
        a[i].first = x - l;
        a[i].second = x + l;
        E.push_back(make_pair(i, 1));
        E.push_back(make_pair(i, -1));
    }
    auto pt = [&](pair <int, int> x){
        if(x.second == 1) return make_pair(a[x.first].first, x.second);
        return make_pair(a[x.first].second, x.second);
    };
    sort(E.begin(), E.end(), [&](pair <int, int> l, pair <int, int> r){
        return pt(l) < pt(r);
    });
    set <int> active;
    vector <int> del(n);
    for(auto &i : E){
        int x = i.first;
        int t = i.second;
        if(t == 1){
            active.insert(x);
        }
        else{
            if(!active.count(x)) continue;
            active.erase(x);
            for(auto &j : active) del[j] = 1;
            active.clear();
        }
    }
    E.clear();
    int ans = 0;
    for(int i = 0 ; i < n ; i++){
        if(del[i]) continue;
        E.push_back(make_pair(i, 1));
        E.push_back(make_pair(i, -1));
        ans++;
    }
    sort(E.begin(), E.end(), [&](pair <int, int> l, pair <int, int> r){
        return pt(l) < pt(r);
    });
    for(auto &i : E){
        int x = i.first;
        int t = i.second;
        if(t == 1){
            if(active.size()){
                ans--;
                continue;
            }
            else active.insert(x);
        }
        else active.erase(x);
    }
    cout << ans << endl;
}


Measured memory_bytes: 5360
#include<bits/stdc++.h>
using namespace std;
#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
typedef long long int ll;
#define forn(i,p,n); for(long long i=p;i<n;++i)
#define rofn(i,p,n); for(long long i=p;i>n;--i)
#define pb push_back
#define pi pair
#define ff first
#define ss second
#define vi vector
#define ump unordered_map
ll m =  1e9+7;
void solve(){
	string str;
	cin >> str;
	ll len = str.length();
	if(str[len-1]=='s'){
		str = str + "es";
		cout<<str;
		return ;
	}
	else{
		str = str + 's';
		cout<<str;
		return ;
	}
}
int main()
{
	fast;
	// int test;
	// cin >> test;
	// while(test--){
		solve();
	// 	cout<<"\n";
	// }
}

Measured memory_bytes: 3656
#include <iostream>
#include <string>
using namespace std;
int main(void){
    string str;
    getline(cin, str);
    
    for(int i=0; i<str.length(); i++){
        if(str[i]>='A' && str[i]<='C'){
            cout << char(str[i]+23);
        }
        else cout << char(str[i]-3);
    }
    cout << endl;
    return 0;
}



Measured memory_bytes: 3220
/**
*    created: 24.06.2020 12:43:41
**/
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#define int long long
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define pcnt(bit) __builtin_popcount(bit)
#define mod 1000000007
#define pi acos(-1.0)
using namespace std;

signed main() {

    cin.tie(0);
    ios_base::sync_with_stdio(false);

    int x1, y1, x2, y2;
    cin >> x1 >> y1 >> x2 >> y2;
    int xd = x2 - x1;
    int yd = y2 - y1;
    int x3 = x2 - yd;
    int y3 = y2 + xd;
    int x4 = x3 - xd;
    int y4 = y3 - yd;
    cout << x3 << " " <<  y3 << " " <<  x4 << " " <<  y4 << endl;
    return 0;
}

Measured memory_bytes: 3668
import java.util.*;

class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        String s = scanner.nextLine();

        char[] chars = new char[3];
        for (int i = 0; i < s.length(); i++) {
            chars[i] = s.charAt(i);
        }
        Arrays.sort(chars);

        if (chars[0] == 'a' && chars[1] == 'b' && chars[2] == 'c') {
            System.out.println("Yes");
        } else {
            System.out.println("No");
        }
    }
}


Measured memory_bytes: 23252
n = int(input())
info = [[] for i in range(n)]
for i in range(n):
    a = int(input())
    info[i] = [tuple(map(int, input().split())) for _ in range(a)]

ans = 0
for bit in range(1 << n):
    flag = True
    cnt = 0
    for i in range(n):
        if (bit >> i) & 1:
            cnt += 1
        else:
            continue

        for x, y in info[i]:
            b = (bit >> (x - 1)) & 1
            if b != y:
                flag = False
                break
        if not flag:
            break
    if flag:
        ans = max(ans, cnt)

print(ans)


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

int32_t main() {
    int x, k, d;
    cin >> x >> k >> d;
    x = abs(x);
    int val = x / d;
    if (k < val) {
        cout << x - k * d << endl;
    } else if (val == k) {
        cout << abs(x - val * d) << endl;
    } else {
        k -= val;
        if (k & 1) {
            cout << abs(x - val * d - d) << endl;
        } else {
            cout << abs(x - val * d) << endl;
        }
    }
    return 0;
}


Measured memory_bytes: 3596
#include<stdio.h>
int main()
{
   int a,b,n,c,d,i,e,f=0;
   scanf("%d %d %d",&n,&a,&b);
   for(i=1;i<=n;i++)
{c=i;
e=0;
     while(c!=0){
        d=c%10;
        e=e+d;
        c=c/10;
     }
     if(e>=a && e<=b)
     {
         f=f+i;
     }
   }
   printf("%d",f);
   return 0;
}


Measured memory_bytes: 128
#include <iostream>
#include <string>
#include <cmath>
#include <vector>

using namespace std;


int main()
{
	int H, W;

	cin >> H >> W;

	char S[51][51];

	int S_n[51][51];

	for (int i = 0; i < H; i++) {
		for (int j = 0; j < W; j++) {
			cin >> S[i][j];
		}
	}

	for (int i = 0; i < H; i++) {
		for (int j = 0; j < W; j++) {
			S_n[i][j] = 0;
			if (S[i - 1][j - 1] == '#' && i > 0 && j > 0)
				S_n[i][j]++;
			if (S[i - 1][j] == '#' && i > 0)
				S_n[i][j]++;
			if (S[i - 1][j + 1] == '#' && i > 0 && j < W - 1)
				S_n[i][j]++;
			if (S[i][j - 1] == '#' && j > 0)
				S_n[i][j]++;
			if (S[i][j + 1] == '#' && j < W - 1)
				S_n[i][j]++;
			if (S[i + 1][j - 1] == '#' && i < H - 1 && j>0)
				S_n[i][j]++;
			if (S[i + 1][j] == '#' && i < H - 1)
				S_n[i][j]++;
			if (S[i + 1][j + 1] == '#' && i < H - 1 && j < W - 1)
				S_n[i][j]++;
		}
	}

	for (int i = 0; i < H; i++) {
		for (int j = 0; j < W; j++) {
			if (S[i][j] == '#')
				cout << S[i][j];
			else
				cout << S_n[i][j];
		}
		cout << endl;
	}

    return 0;
}



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

int main(){
    string s;cin>>s;
    bool odd = (s.size()%2==1);
    if(odd)s.pop_back();
    else{s.pop_back();s.pop_back();}
    int mx = 0;
    for(int i=1;i<=s.size()/2;i++){
        if(s.substr(0,i)==s.substr(i,i)){mx = i;}
    }
    co(mx*2);
}

Measured memory_bytes: 256
#include<stdio.h>
#include <bits/stdc++.h>
#include <iostream>
#include <string>
#include <cstring>
#include <cstdio>
using namespace std;
void merge(int a[], int l, int m, int r)
{
int i, j, k;
int n1 = m - l + 1;
int n2 = r - m;
int L[n1], R[n2];

for (i = 0; i < n1; i++)
L[i] = a[l + i];
for (j = 0; j < n2; j++)
R[j] = a[m + 1+ j];

i = 0;
j = 0;
k = l;
while (i < n1 && j < n2)
{
if (L[i] <= R[j])
{
a[k] = L[i];
i++;
}
else
{
a[k] = R[j];
j++;
}
k++;
}
while (i < n1)
{
a[k] = L[i];
i++;
k++;
}
while (j < n2)
{
a[k] = R[j];
j++;
k++;
}
}
void mergesort(int a[], int l, int r)
{
if (l < r)
{
int m = (r+l)/2;
mergesort(a, l, m);
mergesort(a, m+1, r);
merge(a, l, m, r);
}
}
int main(){
    int a[100000],b,c,count,n,i;
        scanf("%d",&n);
        for(i=0;i<n;i++){
            scanf("%d",&a[i]);
        }
        mergesort(a,0,n-1);
        count=1;
        c=b=-1;
        for(i=n-2;i>=0;i--){
            if(a[i]==a[i+1]){
                if(b==-1)
                b=a[i];
                else{ c=a[i]; break;}
                i--;
            }
        }
        if(c!=-1) printf("%lld",(long long int)b*c);
        else printf("0");
}


Measured memory_bytes: 1024
#include <iostream>
#include <iomanip>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#include <cstdio>
#include <utility>
#include <string>
#include <cmath>
#include <cstdlib>
#include <cstring>

using namespace std;

typedef uint64_t u64;
typedef int64_t s64;
typedef uint32_t u32;
typedef int32_t s32;
typedef vector<s32> vs32;
typedef vector<u32> vu32;
typedef vector<s64> vs64;
typedef vector<u64> vu64;

const double PI=3.14159265358979323846;

#define MAX(x, y) ((x) < (y) ? (y) : (x))
#define MIN(x, y) ((x) > (y) ? (y) : (x))

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

#define CEIL(x, y) (((x) + (y) - 1) / (y))
#define MOD 1000000007ULL

class UnionFind
{
public:
    vector<int> p;
    vector<int> d;
    vector<int> b;

    UnionFind() {}
    UnionFind(int size)
    : p(vector<int>(size, -1)), d(vector<int>(size, 1)), b(vector<int>(size, 0))
    {}

    bool same(int x, int y)
    {
        return findSet(x) == findSet(y);
    }

    void unite(int x, int y)
    {
        ++d[x];
        ++d[y];
        x = findSet(x); y = findSet(y);
        if (x == y) return;

        if (p[x] > p[y]) swap(x, y);
        p[x] += p[y];
        p[y] = x;
    }

    void block(int x, int y)
    {
        if (same(x, y))
        {
            ++b[x];
            ++b[y];
        }
    }

    int findSet(int x)
    {
        if (p[x] < 0) return x;
        else p[x] = findSet(p[x]);
        return p[x];
    }
};

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

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

    UnionFind uf(n);
    int a, b;
    rep (i, m)
    {
        cin >> a >> b;
        --a; --b;
        uf.unite(a, b);
    }

    int c, d;
    rep (i, k)
    {
        cin >> c >> d;
        --c; --d;
        uf.block(c, d);
    }

    rep (i, n)
    {
        int r = uf.findSet(i);
        cout << -uf.p[r] - uf.d[i] - uf.b[i] << " ";
    }
    cout << "\n";
    return 0;
}



Measured memory_bytes: 2048
#include<iostream>
#include<cstdlib>
using namespace std;
bool prime[100008];
int like_2017[100008];
void pp(int n)
{
	for(int i=2;i<=n;i++)prime[i]=1;
	for(int i=2;i*i<=n;i++)
	{
		if(!prime[i])continue;
		for(int j=2*i;j<=n;j+=i)
		prime[j]=0;
	}
	/*int now=2;
	while(now<=n)
	{
		cout<<"pp "<<now<<endl;
		system("pause");
		while(prime[now]==0)now++;
		for(int i=now;i<=n;i+=now)
			prime[i]=0; 
		now++;
	}*/
}
bool l_2017(int a){return prime[a]&&prime[(a+1)/2]&& a&1;}
int main()
{
	pp(100002);
	//for(int i=1;i<=10002;i++)if(prime[i])cout<<i<<" ";cout<<endl;
	int tot=0;
	for(int i=1;i<=100002;i++)
	{
		if(l_2017(i))tot++;//if(l_2017(i))cout<<i<<endl;
		like_2017[i]=tot;
		//cout<<i<<" "<<like_2017[i]<<endl;
	}
	int n;cin>>n;
	while(n--)
	{
		int l,r;cin>>l>>r;
		cout<<like_2017[r]-like_2017[l]+l_2017(l)<<endl;
	}
	return 0;
}//2019.3.15 18:36

Measured memory_bytes: 1152
#include<iostream>
using namespace std;
int main(void)
{
  int a,b,c;
  cin >> a >> b >> c;
  int ans;
  if(a+b+1 >= c){
    ans = c+b;
  }
  else{
    ans = a+b+1+b;
  }
  
  cout << ans <<endl;
  
  return 0;
}

Measured memory_bytes: 256
n = int(input())
w = [input() for i in range(n)]
c = 0

if len(set(w)) != n:
  print("No")
  exit()
  
for i in range(n-1):
  if w[i][-1] == w[i+1][0]:
    c += 1

print("Yes" if c == n-1 else "No")

Measured memory_bytes: 3060
package main

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

func main() {
	X, Y := nextInt(), nextInt()

	if Y%2 == 0 && 2*X <= Y && Y <= 4*X {
		fmt.Println("Yes")
	} else {
		fmt.Println("No")
	}
}

var sc = bufio.NewScanner(os.Stdin)

func init() {
	sc.Buffer(make([]byte, 256), 1e9)
	sc.Split(bufio.ScanWords)
}

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

func nextInt() int {
	a, _ := strconv.Atoi(next())
	return a
}


Measured memory_bytes: 1756
#include <bits/stdc++.h>
using namespace std;
 
int main(){ 
  int N;
  vector<int64_t> A(100010);

  cin >> N;
  for(int i=0; i<N; i++) cin >> A[i];

  
  vector<int64_t> cur_max; cur_max.push_back(A[0]);
  int ans = 1; 

  for(int i=1; i<N; i++){
    if(A[i] <= cur_max[cur_max.size()-1]){
      cur_max.push_back(A[i]);
      ans++;
    } else if(A[i] > cur_max[0]){
      cur_max[0] = A[i];
    } else {
      int p = upper_bound(cur_max.begin(), cur_max.end(), A[i], greater<int>()) - cur_max.begin();
      cur_max[p] = A[i];
    }    
  }

  cout << ans << endl;

}

Measured memory_bytes: 2168
import java.io.*;
import java.util.*;

public class Main {
  public static void main (String[] args) {
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    long h = sc.nextInt();
    long[] wields = new long[n];
    long[] bato = new long[n];
    long batoSum = 0;
    long ans = 0;
    long maxWield = 0;
    long batoOfMax = 0;
    for(int i = 0; i < n; i++) {
      wields[i] = sc.nextLong();
      bato[i] = sc.nextLong();
      maxWield = Math.max(maxWield, wields[i]);
      if(maxWield == wields[i]) {
        batoOfMax = Math.max(bato[i], batoOfMax);
      }
    }
    long batos = 0;
    Arrays.sort(bato);
    for(int i = n-1; i >= 0; i--) {
      if(bato[i] >= maxWield) {
        batoSum += bato[i];
        batos++;
        if(batoSum >= h) {
          break;
        }
      }
    }
    if(h > batoSum) {
      ans += Math.ceil(((h-batoSum)/(double)maxWield));
      //System.out.println(ans);
    }
    ans += batos;
    System.out.println(ans);
  }
}


Measured memory_bytes: 72644
let n, cs, e, s = read_int (), Array.make 100001 0, ref 0, ref 0
let _ = for _ = 1 to n do Scanf.scanf " %d" @@ fun a -> cs.(a) <- cs.(a) + 1 done; Array.iter (fun c -> if c > 1 then s := !s + if c mod 2 = 0 then (incr e; c / 2 - 1) else c / 2) cs; Printf.printf "%d\n" @@ n - 2 * (!s + (!e + 1) / 2)

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

using namespace std;

#define MAX 100000

int A[MAX], n;

int partition(int p, int r){
    int x, i, j, t;
    x = A[r];
    i = p-1;
    for(j = p; j < r; j++){
        if(A[j] <= x){
            i++;
            t = A[i]; A[i] = A[j]; A[j] = t;
        }
    }
    t = A[i+1]; A[i+1] = A[r]; A[r] = t;
    return i + 1;
}

int main(){
    int i, q;

    cin >> n;
    for ( i = 0; i < n; i++)
    {
        cin >> A[i];
    }

    q = partition(0, n-1);
    
    for ( i = 0; i < n; i++)
    {
        if(i) cout << " ";
        if(i == q) cout << "[";
        cout << A[i];
        if(i == q) cout << "]";
    }
    cout << endl;

    return 0;
}


Measured memory_bytes: 3484
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Scanner;
import java.util.Set;

public class Main {

	public static void main(String args[]) {
		Scanner sc = new Scanner(System.in);
		int n=sc.nextInt();
		int m=sc.nextInt();
		Set<Integer> set = new HashSet<>();
		for(int i=0;i<n;i++) {
		int k=sc.nextInt();
		List<Integer> list = new ArrayList<>();
		
		for(int j=0;j<k;j++) {
			if(i==0) set.add(sc.nextInt());
			else 	list.add(sc.nextInt());
		}if(i!=0)
		set.retainAll(list);
		}
		
		System.out.println(set.size());
	}

}


Measured memory_bytes: 22612
// Date: 2020-03-30

#include <bits/stdc++.h>
using namespace std;

typedef long long LL;
typedef long double LD;
typedef vector<int> VI;
typedef pair<LL, LL> pll;
typedef pair<int, int> pii;
#define IO freopen("in.txt", "r", stdin);freopen("out.txt", "w", stdout)
#define FIO ios::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define rep(i, a, b) for(int i = int(a); i <= int(b); ++i)
#define per(i, b, a) for(int i = int(b); i >= int(a); --i)
#define mem(x, y) memset(x, y, sizeof(x))
#define all(x) (x).begin(),(x).end()
#define D(x) cout << #x << " = " << x << endl;
#define SZ(x) ((int)x.size())
#define mk make_pair
#define pb push_back
#define fi first
#define se second
const LL INF = 1e18;
const LL mod = 1e9 + 7;
const int inf = 0x3f3f3f3f;
const int N = 2e5 + 10;
template <typename T> void chkmax(T &x, T y) { x = max(x, y); }
template <typename T> void chkmin(T &x, T y) { x = min(x, y); }
LL qpow(LL x, LL y, LL MOD) {LL a=1; while(y){ if(y&1) a=a*x%MOD; x=x*x%MOD; y>>=1; } return a;}

int n;
pii a[N];
multiset<int> x, y;

LL cal() {
    return 1LL*(*x.rbegin()-*x.begin()) * (*y.rbegin()-*y.begin());
}

int main() {
    FIO;
    int n;
    cin >> n;
    rep(i, 1, n) {
        cin >> a[i].fi >> a[i].se;
        if(a[i].fi > a[i].se) swap(a[i].fi, a[i].se);
    }
    sort(a+1, a+1+n);
    rep(i, 1, n) x.insert(a[i].fi), y.insert(a[i].se);
    LL ans = cal();
    rep(i, 1, n) {
        x.erase(x.find(a[i].fi)), y.insert(a[i].fi);
        y.erase(y.find(a[i].se)), x.insert(a[i].se);
        chkmin(ans, cal());
    }
    cout << ans;

    return 0;
}

Measured memory_bytes: 22656
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <map>
#include <cmath>
#include <iomanip>
#include <queue>
#include <stack>
#include <functional>
using ll = long long;
using namespace std;
int main() {
	ll n, m, ans = 0, A[10101];
    cin >> n >> m;
    cout << max({n+m,n-m,n*m}) << endl;
	return 0;
}

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

using namespace std;
typedef long long ll;
typedef string str;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector <pii> vpii;
typedef vector <pll> vpll;
typedef map <str,int> mapsi;
typedef map <str,int> :: iterator mapsitr;
typedef map <int , int> mint;
typedef map <ll , ll> mll;
typedef set <int> si;
typedef set <ll> sll;
typedef si :: iterator sitr;
typedef si :: reverse_iterator rsitr;
typedef sll :: iterator sltr;
typedef sll :: reverse_iterator rsltr;
#define mset multiset

typedef mset <int> msi;
typedef mset <ll> msll;
typedef msi :: iterator msitr;
typedef msi :: reverse_iterator msritr;
typedef msll :: iterator msltr;
typedef msll :: reverse_iterator mslritr;

#define mp make_pair
#define pb push_back
#define pob pop_back
#define pf push_front
#define pof pop_front
#define fi first
#define se second
#define fs first.second
#define ss second.second
#define ff first.first
#define sf second.first
#define newl '\n'

char to_upper (char x){
    if( 97 <= int(x) && int(x) <= 126)return char(x-32);
    else if( 65 <= int(x) && int(x) <= 90)return x;
}
char to_lower (char x){
    if( 97 <= int(x) && int(x) <= 126)return x;
    else if( 65 <= int(x) && int(x) <= 90)return char(x+32);
}
int numerize (char x){
    if(48 <= int(x) && int(x) <= 57)return int(x-'0');
    else if( 97 <= int(x) && int(x) <= 126)return int(x-96);
    else if( 65 <= int(x) && int(x) <= 90)return int(x-64);
}
bool isect (int l1, int r1, int l2, int r2){
    pii p1,p2;
    p1 = mp(l1,r1); p2 = mp(l2,r2);
    if(p1>p2)swap(p1,p2);
    if(p2.fi <= p1.se)return true;
    else return false;
}
ll fexp (ll num1, ll num2, ll MOD){
    if(num2==0)return 1;
    else if(num2==1)return num1;
    else{
        ll temp = fexp (num1,num2/2,MOD); ll res = ((temp%MOD) * (temp%MOD))%MOD;
        if(num2%2==1) res = ((res%MOD)*(num1%MOD))%MOD; return res;
    }
}
ll invmod (ll num, ll MOD){return fexp (num,MOD-2,MOD);}
ll gcd (ll num1, ll num2){
    if(num1 < num2) swap(num1,num2); ll num3 = num1 % num2 ;
    while(num3 > 0){ num1 = num2; num2 = num3; num3 = num1 % num2;}
    return num2;
}
ll lcm (ll num1 , ll num2){return (ll) (num1/gcd(num1,num2))*num2;}

// end of Template

int n,a;
int main(){

//    freopen("input.txt", "r", stdin);
//    freopen("output.txt", "w", stdout);

    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cin>>n>>a;
    cout<<n*n-a<<newl;
}


Measured memory_bytes: 256
#include "iostream"
#include "climits"
#include "list"
#include "queue"
#include "stack"
#include "set"
#include "functional"
#include "algorithm"
#include "string"
#include "map"
#include "unordered_map"
#include "unordered_set"
#include "iomanip"
#include "cmath"
#include "random"
#include "bitset"
#include "cstdio"
#include "numeric"
#include "cassert"
#include "ctime"

using namespace std;

constexpr long long int MOD = 1000000007;
//constexpr int MOD = 1000000007;
//constexpr int MOD = 998244353;
//constexpr long long int MOD = 998244353;
constexpr long double EPS = 1e-12;

//int N, M, K, H, W, L, R;
long long int N, M, K, H, W, L, R;


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

	cin >> N >> M;
	if (N < 10)M += (10 - N) * 100;
	cout << M << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <functional>
#include <string>
#include <vector>
#include <climits>
#include <cstring>
#include <cmath>
#include <cassert>

#include <queue>
#include <map>
#include <set>

using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
const int MN = 1e5 + 5, MOD = 1e9 + 7;

int N, W;
ll dp[MN];

int main() {
    ios_base::sync_with_stdio(0), cin.tie(0);
    cin >> N >> W;
    for (int i = 0, w, v; i < N; i++) {
        cin >> w >> v;
        for (int j = W; j >= w; j--) dp[j] = max(dp[j], dp[j - w] + v);
    }
    cout << dp[W] << '\n';
    return 0;
}


Measured memory_bytes: 1024
//https://atcoder.jp/contests/abc139/tasks/abc139_a
// clang-format off
#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for(int i=0; i<(n); i++)
#define REP2(i,x,n) for(int i=x; i<(n); i++)
#define ALL(n) begin(n),end(n)
struct cww{cww(){ios::sync_with_stdio(false);cin.tie(0);}}star;
const long long INF = numeric_limits<long long>::max();
// clang-format on
int main()
{
    string S, T;
    cin >> S >> T;
    int res{};
    REP(i, (int)S.size())
    {
        res += S[i] == T[i] ? 1 : 0;
    }
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <stack>
#include <cassert>
using namespace std;
using VI = vector<long>;

int main() {
    int n;
    cin >> n;
    int l = 0, r = n - 1;
    string lstr, rstr, ans;
    cout << l << endl;
    cin >> lstr;
    if (lstr == "Vacant") {
        return 0;
    }
    cout << r << endl;
    cin >> rstr;
    if (rstr == "Vacant") {
        return 0;
    }
    while (1) {
        int m = (l + r) / 2;
        cout << m << endl;
        cin >> ans;
        if (ans == "Vacant") {
            return 0;
        }
        
        if ((m - l) % 2 == 1) {
            if (ans != lstr) {
                l = m;
                lstr = ans;
            } else {
                r = m;
                rstr = ans;
            }
        } else {
            if (ans == lstr) {
                l = m;
                lstr = ans;
            } else {
                r = m;
                rstr = ans;
            }
        }
    }
}


Measured memory_bytes: 852
#include "bits/stdc++.h"
using namespace std;
#define ll long long int
#define rep(i,n) for( int i = 0; i < n; i++ )
#define rrep(i,n) for( int i = n; i >= 0; i-- )
#define REP(i,s,t) for( int i = s; i <= t; i++ )
#define RREP(i,s,t) for( int i = s; i >= t; i-- )
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define INF 2000000000
#define mod 1000000007
#define INF2 1000000000000000000


int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N; cin >> N;
    int h[110];
    rep(i, N) cin >> h[i];
    int ans = 0;
    while(true) {
        int i = 0;
        int cnt = INF;
        int first = 0;
        while(first < N && h[first] == 0) first++;
        if (first == N) break; 
        i = first;
        cnt = h[first];
        while(i < N && h[i] != 0) {
            cnt = min(cnt, h[i]);
            i++;
        }
        ans += cnt;
        REP(j, first, i - 1) h[j] -= cnt;
        //rep(j, N) cout << h[j] << " ";
        //cout << endl;
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef set<int> si;
typedef pair<int,int> pii;
#define rep(i,a,b) for(int i=(a); i<(b); ++i)
#define per(i,a,b) for(int i=(b)-1; i>=(a); --i)
#define all(x) (x).begin(),(x).end()
#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define F first
#define S second
const int INF = 987654321;
const ll MOD = 1000000007;
//const long double PI = (acos(-1));
//const long double EPS = 0.0000000001;
int dy[4] = {-1, 0, 1, 0};
int dx[4] = {0, 1, 0, -1};

int x, y;

int main(void) {
	ios_base::sync_with_stdio(false); 
	cin.tie(NULL); 
	cout.tie(NULL);
	//freopen("in.txt", "r", stdin);
	
	cin >> x >> y;
	int ret = 0;
	if(x == 1) {
		ret += 300000;
	} else if(x == 2) {
		ret += 200000;
	} else if(x == 3) {
		ret += 100000;
	}

	if(y == 1) {
		ret += 300000;
	} else if(y == 2) {
		ret += 200000;
	} else if(y == 3) {
		ret += 100000;
	}

	if(x == 1 && y == 1) {
		ret += 400000;
	}

	cout << ret << endl;
	return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;
import java.util.Arrays;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int[] a=new int[3];
        for(int i=0;i<3;i++)a[i]=sc.nextInt();
        Arrays.sort(a);
        System.out.println(a[0]+" "+a[1]+" "+a[2]);
    } 
}


Measured memory_bytes: 26256
#include<iostream>
using namespace std;
int main(){
  int n,m,flag=0;
  cin >> n >> m;
  int a[m],b[m],one_a[200001]={0},one_b[200001]={0};
  for(int i=0;i<m;i++){
    cin >>a[i]>>b[i];
    if(a[i]==1)one_b[b[i]]=1;
    if(b[i]==1)one_a[a[i]]=1;
  }
  for(int i=0;i<m;i++){
    if(a[i]==n&&one_a[b[i]]==1){
      flag=1;
      break;
    }
    if(b[i]==n&&one_b[a[i]]==1){
      flag=1;
      break;
    }
  }
  if(flag==1)cout << "POSSIBLE"<<endl;
  else cout << "IMPOSSIBLE"<<endl;
}


Measured memory_bytes: 3328
#include <limits.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <unistd.h>
#include <math.h>

#define P 1000000007

int comp(const void *a, const void *b){return *(int*)a-*(int*)b;}

int U[26], *u=U-'a';
int main(void){
	char s[27];
	scanf("%s", s);
	int n=strlen(s);
	if(n==26){
		int i;
		for(i=n-2; i>=0; i--){
			if(s[i]<s[i+1]) break;
		}
		if(i<0){
			puts("-1");
		}else{
			char c=s[i+1];
			for(int j=i+2; j<n; j++){
				if(s[j]>s[i] && s[j]<c) c=s[j];
			}
			s[i]=c;
			s[i+1]=0;
			puts(s);
		}
	}else{
		fprintf(stdout, s);
		for(int i=0; i<n; i++){
			u[s[i]]=1;
		}
		for(char c='a'; c<='z'; c++){
			if(u[c]==0){
				putchar(c);
				break;
			}
		}
		putchar(10);
	}
}


Measured memory_bytes: 128
#include <cstdio>
#include <algorithm>
#define N_MAX 100000
typedef long long lnt;
typedef void vnt;
const int INF = 0x3F3F3F3F;
int n, p, i, j, a[N_MAX + 1], b[N_MAX + 1], c[N_MAX * 2 + 2], l, m, r, ans;
lnt sum, cur;
inline vnt ins(int i)
{
	for (; i <= p; i += i & -i) ++c[i];
}
inline lnt qry(int i)
{
	lnt s = 0;
	for (; i > 0; i -= i & -i) s += c[i];
	return s;
}
int main()
{
	scanf("%d", &n);
	l = INF;
	for (i = 1; i <= n; ++i)
		scanf("%d", &a[i]), l = std::min(l, a[i]), r = std::max(r, a[i]);
	sum = (lnt) n * (n + 1) / 4 + 1;
	while (l <= r)
	{
		m = (l + r) >> 1, p = 0;
		for (i = 1; i <= n; ++i)
			b[i] = b[i - 1] + (a[i] <= m), p = std::max(p, b[i] * 2 - i + n + 1);
		for (i = 1; i <= p; ++i)
			c[i] = 0;
		cur = 0;
		ins(n + 1);
		for (i = 1; i <= n; ++i)
			cur += qry(b[i] * 2 - i + n), ins(b[i] * 2 - i + n + 1);
		if (cur >= sum)
			r = m - 1, ans = m;
		else
			l = m + 1;
	}
	printf("%d\n", ans);
	return 0;
}

Measured memory_bytes: 1664
#include <iostream>
#define rep(i,n) for(int i = 0;i<n;i++)

using namespace std;

int main ()
{
        bool check[51][51] = {false};
        int array[51][51] = {0};
        int W,H,T,n,p;
        int x[100],y[100],t[100];
        cin >> W >> H >>T;
        cin >> p;
        int answer = 0;

        rep(i,p){cin >> x[i] >> y[i] >> t[i];}
        rep(i,H){
                rep(j,W ){
                cin >> n;
                if(n)
                        check[i][j] = true;

                }
        }
        rep(i,p){
                if(check[y[i]][x[i]])
                        answer++;
        }
        cout << answer << endl;
}

Measured memory_bytes: 1164
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
#include <cmath>
#include <random>
#include <queue>

using namespace std;




int main()
{
	int N, M;

	cin >> N >> M; 

	vector<int> Ls(M);
	vector<int> Rs(M);

	int max_l = 0;
	int min_r = 1e9;

	for (int mi = 0; mi < M; mi++){
		cin >> Ls[mi] >> Rs[mi];
		if (Ls[mi] > max_l) max_l = Ls[mi];
		if (Rs[mi] < min_r) min_r = Rs[mi];
	}

	int ans = max(0,min_r - max_l + 1); 

	printf("%d",ans);


	return 0;
}



Measured memory_bytes: 1024
N, C, K = map(int, input().split())
T = [int(input()) for i in range(N)]
T.sort()
#print(T)
Bcnt = 0
while True:
    if len(T) <= 0:
        break
    BS = T[0] + K
    Bcnt += 1
    del T[0]
    cnt = 1
    while cnt < C and len(T) > 0:
        if T[0] <= BS:
            del T[0]
            cnt += 1
        else:
            break
print(Bcnt)


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

using int32 = int_fast32_t;
using int64 = int_fast64_t;

const int32 INF = 1e9;
const int32 MOD = 1e9+7;
const int64 LLINF = 1e18;

#define YES(n) cout << ((n) ? "YES\n" : "NO\n"  )
#define Yes(n) cout << ((n) ? "Yes\n" : "No\n"  )
#define ANS(n) cout << (n) << "\n"
#define REP(i,n) for(int64 i=0;i<(n);++i)
#define FOR(i,a,b) for(int64 i=(a);i<(b);i++)
#define FORR(i,a,b) for(int64 i=(a);i>=(b);i--)
#define ALL(obj) (obj).begin(),(obj).end()
#define pii pair<int32,int32>
#define pll pair<int64,int64>
#define pb(a) push_back(a)
#define mp make_pair

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    string w[3] = {"Sunny", "Cloudy", "Rainy"};
    string s;
    cin >> s;
    REP(i,3){
        if(s == w[i]){
            cout << w[(i+1)%3] << endl;
            return 0;
        }
    }
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
#include <algorithm>
int main(){
  int H,N;
  cin >> H >> N;
  int hight[10010][3];

  for(int i = 0; i < 10010; i++){
    for(int j = 0; j < 3; j++){
      hight[i][j]=1;

    }
  }
  for(int i = 0; i < 3; i++){
    hight[H][i] = 0;
    hight[0][i] = 0;
  }
  for(int i = 0; i < N; i++){
    int x,y;
    cin >> x >> y;
    if(x == 0){
      for(int k = 0; k < 2; k++) hight[y-k+1][x] = 0;
    }
    if(x == 1){
      for(int j = 0; j < 2; j++)
        for(int k = 0; k < 2; k++){
          hight[y-k+1][x-j] = 0;
        }
    }
    if(x == 2){
      for(int j = 0; j < 2; j++)
        for(int k = 0; k < 2; k++){
          hight[y-k+1][x-j] = 0;
        }
    }
    if(x == 3){
      for(int j = 0; j < 2; j++)hight[y-j+1][x-1] = 0;
    }
  }
  /*
  for(int i = 0; i < H; i++){
    for(int j = 0; j < 3; j++){
      cout << hight[i][j] << " ";
    }
    cout << endl;
  }
  */
  int ans = 0;
  for(int i = 1; i < H;i++){
    if(hight[i][0] == 1){
      ans++;
      hight[i][0] = hight[i][1] = hight[i+1][0] = hight[i+1][1] = 0;
    }
    if(hight[i][2] == 1){
      ans++;
      hight[i][2] = hight[i+1][2] = hight[i][1] = hight[i+1][1]=0;
    }
    if(hight[i][1] == 1){
      int temp = 1;
      while(hight[i+temp][0]&&hight[i+temp][2]&&temp+i < H)temp++;
      if(temp%2 == 1){
	ans++;
	for(int j = 0; j < 2; j++)
      hight[i+j][0]=hight[i+j][1]=hight[i+j][2]=0;
      }
   
    }
  }
  cout << ans   << endl;
}



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

// #define int long long
#define ll long long
#define pb push_back
#define vi vector<int>
#define vii vector<vector<int> >

template <class X> void print(X Target){ cout << Target << '\n'; }

bool isprime(int num)
{
  if (num == 2){
    return (true);
  }
  else if (num == 1 || num % 2 == 0){
    return (false);
  }
  for (int i = 3; i <= num / i; i += 2){
    if (num % i == 0){
      return (false);
    }
  }

  return (true);
}

signed main()
{
  ios::sync_with_stdio(false);
  
  int n, cnt = 0;
  cin >> n;
  while (n--){
    int num;
    cin >> num;
    if (isprime(num)){
      cnt++;
    }
  }
  print(cnt);

  return (0);
}

Measured memory_bytes: 1196
#include<cstdio>
#include<cstring>
#include<iostream>
#include<string>
using namespace std;


int main(void)
{
	int n,t,k=0,res=0,last,b=0,temp=0;
	cin>>n>>t;
	last = t;
	res = 0;
	while(n--)
	{
		cin >> k;
		if(k<last)
		{
			last = k+t;
		}
		else
		{
			res+=(last-b);
			
			b = k;
			last = k+t;
		}
	}
	res+=(last-b);
	cout<<res<<endl;
	return 0;
}

Measured memory_bytes: 256
import sys
readmi = lambda: map(int, sys.stdin.readline().split())

A, B, C, K = readmi()
# result var
max_sum = 0

# check 1
max_sum = min(A, K)
K = K - max_sum

# check 0
if K > 0:
  K = K - min(B, K)

# check - 1
if K > 0:
  max_sum = max_sum - min(K, C)
# print result
print(max_sum)

Measured memory_bytes: 9192
import java.util.Scanner;

public class Main {
  public static void main(String[] args ) throws Exception {
    Scanner sc = new Scanner(System.in);
    int N = Integer.parseInt(sc.next());
    int N2 = Integer.parseInt(sc.next());
    int N3 = Integer.parseInt(sc.next());
    int N4 = Integer.parseInt(sc.next());
    if(N4-N <= 0) {
    	System.out.println(N4*1);
    } else if((N4-N) - N2 <= 0) {
    	System.out.println(N*1);
    } else {
    	System.out.println(N*1 + (-1 * ((N4-N) - N2)));
    }

  }
}

Measured memory_bytes: 26992
import java.util.*;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n=sc.nextInt();
        int m=sc.nextInt();
        long[] a=new long[n];
        for(int i=0;i<n;i++){
            a[i]=sc.nextInt()/2;
        }
        long lcm=1;
        for(int i=0;i<n;i++){
            lcm=lcm*a[i]/gcd(lcm,a[i]);
            if(lcm>m){
                System.out.println(0);return;
            }
        }
        int min=Integer.MAX_VALUE;
        int count;
        for(int i=0;i<n;i++){
            count=0;
            while(a[i]%2==0){
                a[i]/=2;
                count++;
            }
            min=Math.min(count,min);
        }
        if(lcm/(long)Math.pow(2,min)%2==0){
            System.out.println(0);
            return;
        }
        System.out.println(((m/lcm)+1)/2);
 
    }
    static long gcd(long n,long m){
        if(n<m){
            n=n+m;
            m=n-m;
            n=n-m;
        }
        n%=m;
        if(n==0){
            return m;
        }else{
            return gcd(n,m);
        }
    }


}

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

using namespace std;
typedef long long ll;

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    ll n;
    cin >> n;
    ll p=26;
    int x=1;
    while(n>p)
    {
        n-=p;
        p*=26;
        x++;
    }
    n--;
    string res;
    while(x--)
    {
        res+=(n%26+'a');
        n/=26;
    }
    reverse(res.begin(),res.end());
    cout << res << "\n";
    return 0;
}


Measured memory_bytes: 3652
#pragma GCC optimize("-O3")

#include <bits/stdc++.h>

using namespace std;

#define ll long long

signed main() {
	int n; cin >> n;
	vector<int> a(n);
	for (int i = 0; i < n; ++i)
		cin >> a[i];
	ll ans = 0;
	for (int i = 0; i < n; ++i) {
		int b; cin >> b;
		ans += b;
	}
	vector<int> c(n - 1);
	for (int i = 0; i < n - 1; ++i)
		cin >> c[i];
	for (int i = 0; i < n - 1; ++i) {
		if (a[i] + 1 == a[i + 1])
			ans += c[a[i] - 1];
	}

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

Measured memory_bytes: 256
def p_c():
    L, R = map(int, input().split())
    year = 2019

    if R - L >= year:
        print(0)
        exit()

    ans = year
    for i in range(L, R + 1):
        for j in range(i + 1, R + 1):
            ans = min(ans, (i * j) % year)
            if ans == 0:
                print(0)
                exit()

    print(ans)
    
p_c()

Measured memory_bytes: 38896
import java.io.BufferedReader
import java.io.InputStreamReader
import java.io.PrintWriter
import java.util.*

val br = BufferedReader(InputStreamReader(System.`in`))
val pw = PrintWriter(System.out)
fun main(args : Array<String>) {
    func()
    pw.flush()
}

fun func() {
    // 回答をここに書く
    val (a,b,c,d) = listOfInt()
    val r = when {
        a+b > c+d -> {"Left"}
        a+b == c+d -> {"Balanced"}
        a+b < c+d -> {"Right"}
        else -> ""
    }
    println(r)
}

// 入力取得
fun next() = br.readLine()!!
fun nextInt() = next().toInt()
fun nextLong() = next().toLong()
fun nextDouble() = next().toDouble()
fun listOfString() = next().split(" ")
fun listOfInt() =listOfString().map { it.toInt() }
fun listOfLong() =listOfString().map { it.toLong() }
fun listOfDouble() =listOfString().map { it.toDouble() }

// 約数のList
fun divisor(value : Long) : List<Long> {
    val max = Math.sqrt(value.toDouble()).toLong()
    return (1..max)
            .filter { value % it == 0L }
            .map { listOf(it, value / it) }
            .flatten()
            .sorted()
}

// 範囲内の素数を取得
// fromだけ指定すると戻り値の個数で素数判定ができる
fun prime(from : Long, to : Long = from) : List<Long> {
    return (from..to).filter { i ->
        val max = Math.sqrt(i.toDouble()).toLong()
        (2..max).all { j ->  i % j != 0L }
    }
}

// 素因数分解
fun decom(value : Long) : List<Long>{
    if (value == 1L) return listOf(1)
    val max = Math.sqrt(value.toDouble()).toLong()
    return prime(2, max).filter { value % it == 0L }
}

// 最大公約数
fun gcd(a : Long, b : Long) : Long {
    return if (a % b == 0L) b else gcd(b, a % b)
}

// 文字列を入れ替え
fun swap(base : String, a : String, b : String) : String {
    return base.map {
        when (it) {
            a.toCharArray()[0] -> b
            b.toCharArray()[0] -> a
            else -> it.toString()
        }
    }.joinToString()
}

fun println(value : Any) {
    pw.println(value)
}

Measured memory_bytes: 35780
/*input
123456789
*/

// Nihesh Anderson - knandy

#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 ll;
typedef long double ld;
typedef tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update> ordered_set; // find_by_order, order_of_key
ll MOD=1000000007;

#define endl '\n'
#define fast_cin() ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define pb push_back
ll INF = 2000000000000000001;
long double EPS = 1e-9;
ll power(ll a, ll n, ll md){if(n==0){return 1;}else{ll res=power(a,n/2,md);res=(res*res)%md;if(n%2!=0){res=(res*a)%md;}return res;}}
random_device rndm;
mt19937 grndm(rndm());
void mix(ll* a, ll* b){shuffle(a,b,grndm);}

int main(){
	fast_cin();
	// freopen("input.in","r",stdin);
	// freopen("output.out","w",stdout);
	string s; cin >> s;
	ll sum = 0;
	for(auto c: s) {
		sum += c - '0';
	}
	if(sum % 9 == 0) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}
	return 0;
}




















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

using namespace std;

const int mx = 200000 + 9;

bitset <mx> mark;
int d[mx];
vector <int> adj[mx];

int main() {
    int n, m; cin >> n >> m;
    for (int i = 0; i < m; i++) {
        int a, b; cin >> a >> b;
        adj[a].push_back(b);
        adj[b].push_back(a);
    }

    mark[1] = 1;
    queue <int> q;
    q.push(1);

    while (!q.empty()) {
        auto u = q.front();
        q.pop();
        for (auto v : adj[u]) {
            if (mark[v]) continue;
            mark[v] = 1;
            d[v] = 1 + d[u];
            q.push(v);
        }
    }

    if (d[n] == 2) cout << "POSSIBLE" << endl;
    else cout << "IMPOSSIBLE" << endl;
}

Measured memory_bytes: 15936
#include<iostream>
using namespace std;
int main(){
  int H,W;
  while(cin>>H>>W){
    if(H==0&&W==0) break;
    if(W%2==0){
      for(int i=1;i<=H;i++){
	if(i%2==1){
	  for(int j=0;j<W/2;j++) cout << '#' << '.';
	  cout << endl;
	}
	else{
	  for(int k=0;k<W/2;k++) cout << '.' << '#';
	  cout << endl;
	}
      }
    }
    else{ 
      for(int i=1;i<=H;i++){
	if(i%2==1){
	  for(int j=0;j<W/2;j++) cout << '#' << '.';
	  cout << '#' << endl;
	}
	else{
	  for(int k=0;k<W/2;k++) cout << '.' << '#';
	  cout << '.' << endl;
	}
      }
    }
    cout << endl;
  }
  return 0;
}
  

Measured memory_bytes: 1152
#include <bits/stdc++.h>
using namespace std;
#define endl "\n"
#define rep(i,n); for(long long i = 0;i < (n);i++)
using ll = long long;
using P = pair<long long,long long>;
template <class T> using vec = vector<T>;
const ll mod = 1e9+7;

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    ll n; cin >> n;
    vec<string> s(n); rep(i,n)cin >> s[i];
    sort(s.begin(),s.end());
    ll ans = 1
    rep(i,n-1){
        if(s[i] != s[i+1])ans++;
    }
    cout << ans << endl;
}

Measured memory_bytes: 9540