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

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

template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
#define che(a,string) cout<<"//"<<string <<"=="<<(a)<<"//" <<endl;
#define SORT(a) sort((a).begin(),(a).end())
#define rSORT(a) reverse((a).begin(),(a).end())
#define For(i, a, b)    for(int i = (a) ; i < (b) ; ++i)
#define rep(i, n)       For(i, 0, n)
#define leftunique(a) {SORT(a);(a).erase(unique((a).begin(),(a).end()),(a).end());}
//leftuniqueは配列から同じ要素のものを取り除く 例 4 6 2 1 3 4 1 2 なら 1 2 3 4 6 になる
bool IsInt(double a){int b = a/1;if(a==b){return true;}else {return false;}}
bool coY() {cout <<"Yes"<<endl;}
bool coN(){cout <<"No"<<endl;}
const int mod = 1e9 + 7;
const ll INF = 1LL << 60;

//ここから書き始める

int main()
{
	cout << setprecision(10);
	ll w , a, b;
	cin >> w >> a >> b;

	if(b <= (w+a) ) {
		swap(a,b);
	}
	ll ans = max(b-(a+w) ,(ll) 0);
	cout << ans << endl;
}


Measured memory_bytes: 256
import java.util.*;

public class Main {
	static Scanner sc = new Scanner(System.in);
	public static void main(String[] args) {
		int T = sc.nextInt();
		int S = sc.nextInt();
		int E = sc.nextInt();
		int W = sc.nextInt();
		int N = sc.nextInt();
		int B = sc.nextInt();
		String[] ss = sc.next().split("");
		for (int i=0; i<ss.length; i++) {
			if (ss[i].equals("N")) {
				int[] temp = {T,S,E,W,N,B};
				T = temp[1];
				N = temp[0];
				B = temp[4];
				S = temp[5];
			}
			else if (ss[i].equals("E")) {
				int[] temp = {T,S,E,W,N,B};
				T = temp[3];
				E = temp[0];
				B = temp[2];
				W = temp[5];
			}
			else if (ss[i].equals("S")) {
				int[] temp = {T,S,E,W,N,B};
				T = temp[4];
				N = temp[5];
				B = temp[1];
				S = temp[0];
			}
			else if (ss[i].equals("W")) {
				int[] temp = {T,S,E,W,N,B};
				T = temp[2];
				E = temp[5];
				B = temp[3];
				W = temp[0];
			}
		}
		System.out.println(T);
	}
}			



Measured memory_bytes: 26412
#include<bits/stdc++.h>
#define MAXN 100005
#define INF 1000000000
#define MOD 1000000007
#define F first
#define S second
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
int n,a[MAXN];
ll suf[MAXN];
ll ans[MAXN];
int main()
{
    scanf("%d",&n);
    for(int i=0;i<=n;i++) scanf("%d",&a[i]);
    suf[n]=a[n];
    for(int i=n-1;i>=0;i--) suf[i]=suf[i+1]+a[i];
    ans[0]=1;
    for(int i=1;i<=n;i++) 
    {
        if(ans[i-1]<a[i-1])
        {
            puts("-1");
            return 0;
        }
        ans[i]=min((ans[i-1]-a[i-1])*2,suf[i]);
    }
    if(ans[n]<a[n])
    {
        puts("-1");
        return 0;
    }
    ll res=0;
    for(int i=0;i<=n;i++) res+=ans[i];
    printf("%lld\n",res);
    return 0;
}

Measured memory_bytes: 5736
#include <iostream>
#include <queue>
#include <string>
#include <map>
#include <stdio.h>
#include <iomanip>
#include <math.h>
#include <vector>
#include <stack>
#include <algorithm>
#include <string.h>
#include <set>
#include <cstdlib>
#include <iostream>
#include <bits/stdc++.h>
#define pii pair<int,int> 
#define ll long long int 
#define sl(n) scanf("%lld",&n)
#define s(n) scanf("%d",&n)
#define f(i,n) for(int i=0;i<n;++i)
#define fo(i,n) for(int i=1;i<=n;++i)
#define fnm(n,m) for(ll i=n;i<m+1;++i)
#define pb push_back
#define pf printf
#define F first
#define S second
#define srt(v) sort(v.begin(),v.end());
#define srtc(v,cmp) sort(v.begin(),v.end(),cmp);
#define srta(v,n) sort(v,v+n);
const ll LL_INF=0x3f3f3f3f3f3f;
const ll MOD=1073741824;


using namespace std;


int T;
int d,arr[100005][5];
int dp[100005][5];

int gen(int i,int prev){ // swim:0, bugs:1, homework:2
    if(i == d)return 0;
    int &ret = dp[i][prev];
    if(~ret)return ret;
    ret = gen(i+1,(prev+1)%3)+arr[i][(prev+1)%3];
    ret = max( ret , gen(i+1,(prev+2)%3)+arr[i][(prev+2)%3]);
    if(!i)ret = max( ret , gen(i+1,(prev)%3)+arr[i][(prev)%3]);
    return ret;
}

int main(){
    // pf("\t\t\t***************************************************************************\n\n");
    // pf("\t\t\t***************************************************************************\n\n");
    // freopen("input.txt","r",stdin);
    // freopen("output.txt","w",stdout);
    memset(dp,-1,sizeof dp);
    s(d);
    f(i,d){
        s(arr[i][0]);
        s(arr[i][1]);
        s(arr[i][2]);
    }
    pf("%d\n",gen(0,0));

    return 0;
} 

Measured memory_bytes: 11904
#define _USE_MATH_DEFINES
#include<iostream>
#include<algorithm>
#include<math.h>
#include<cmath>
#include<string>
#include<set>
#include<map>
#include<stdlib.h>
#include<stdio.h>
#include<vector>
#include<utility>
#include<queue>
#include<stdbool.h>
using namespace std;
typedef long long ll;
#define N (1000000000+7)
typedef pair<int, int> P;

int dx[4] = { 1,0,-1,0 };
int dy[4] = { 0,1,0,-1 };



int main(void) {
	int a[3];
	cin >> a[0] >> a[1] >> a[2];
	sort(a, a + 3);
	cout << a[0] * a[1] / 2 << endl;
	return 0;
}

Measured memory_bytes: 256
open Batteries

let scan fmt f =
  Scanf.sscanf (read_line ()) fmt f

let scan_list cnv =
  read_line ()
  |> String.split_on_char ' '
  |> List.map cnv

let scan_array n m e conv =
  let arr = Array.make_matrix n m e in
  Enum.Labels.iter (0 --^ n)
    ~f:(fun i -> arr.(i) <- Array.of_list @@ scan_list conv);
  arr

let rec zip xs ys =
  match xs, ys with
  | [], _ -> []
  | _, [] -> []
  | x::xs, y::ys ->
    (x, y) :: zip xs ys

let dbg x = Printf.printf "%s\n" @@ dump x; x

let (a,b,c,x,y) = scan "%d %d %d %d %d" Tuple.Tuple5.make

let () =
  let n = min x y in
  let m = max x y in
  List.min [a*x+b*y; c*2*n+a*(x-n)+b*(y-n);c*2*m]
  |> Printf.printf "%d\n"


Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define x first
#define y second
#define ll long long
#define xmod 1000000007
using namespace std;

int a,b,c;
int main(){
	scanf("%d%d%d",&a,&b,&c);
	if (c > a && c > b)
	printf("%d\n",a*b/2);
	else
	if (b > a && b > c)
	printf("%d\n",a*c/2);
	else
	printf("%d\n",b*c/2);
    return 0;
}
//3 4 5 6 7

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

using namespace std;

struct UnionFind {
    vector<int> par; // par[i]:iの親の番号　(例) par[3] = 2 : 3の親が2

    UnionFind(int N) : par(N) { //最初は全てが根であるとして初期化
        for(int i = 0; i < N; i++) {
            par[i] = i;
        }
    }

    int root(int x) { // データxが属する木の根を再帰で得る：root(x) = {xの木の根}
        if (par[x] == x) return x;
        return par[x] = root(par[x]);
    }

    void unite(int x, int y) { // xとyの木を併合
        int rx = root(x); //xの根をrx
        int ry = root(y); //yの根をry
        if (rx == ry) return; //xとyの根が同じ(=同じ木にある)時はそのまま
        par[rx] = ry; //xとyの根が同じでない(=同じ木にない)時：xの根rxをyの根ryにつける
    }

    bool same(int x, int y) { // 2つのデータx, yが属する木が同じならtrueを返す
        int rx = root(x);
        int ry = root(y);
        return rx == ry;
    }
};

int main() {
    int N, M;
    cin >> N >> M;
    vector<long long> ans(M);
    ans.at(M - 1) = 1ll * N * (N - 1) / 2;
    vector<long long> s(N, 1), A(M), B(M);

    UnionFind tree(N);

    for (int i = 0; i < M; i++) {
        cin >> A.at(i) >> B.at(i);
        A.at(i)--;
        B.at(i)--;
    }
    for (int i = M - 1; i > 0; i--) {
        if (tree.same(A.at(i), B.at(i))) {
            ans.at(i - 1) = ans.at(i);
            continue;
        }
        int ra = tree.root(A.at(i));
        int rb = tree.root(B.at(i));
        long long sa = s.at(ra);
        long long sb = s.at(rb);
        ans.at(i - 1) = ans.at(i) - sa * sb;
        tree.unite(ra, rb);
        s.at(tree.root(ra)) = sa + sb;
    }
    for (int i = 0; i < M; i++) {
        cout << ans.at(i) << endl;
    }
}

Measured memory_bytes: 4864
#include<stdio.h>
#include<math.h>
int K,R,L,tmp=0;
double P,E,T;

double dfs(double r,double l,int c)
{
	double h=(r+l)/2,t=h-T;
	if(c==K)return(-E<=t&&t<=E)?1.0:0.0;
	if(E<T-l||E<r-T)return 0.0;
	if(E>l-r&&r<=T&&T<=l)return 1.0;
	if(h>=T) return dfs(h,l,c+1)*P+dfs(r,h,c+1)*(1.0-P);
	else return dfs(h,l,c+1)*(1.0-P)+dfs(r,h,c+1)*P;
}

int main()
{
	scanf("%d%d%d%lf%lf%lf",&K,&R,&L,&P,&E,&T);
	printf("%lf\n",dfs((double)R,(double)L,0));
	return 0;
}

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

using namespace std;
int mod(int a)
{
    if(a>0)
    {
        return(a);
    }
    return(-1*a);
}
int min(int a , int b)
{
    if(a>b)
    {
    	//cout<<b<<"\t" ;
        return(b);
    }
    //cout<<a<<"\t" ;
    return(a);
}
int main()
{
    int a,b,c,i,j,n,k ;
    cin>>n>>k ;
    vector<int>v,cost;
    for(i=0 ; i<n ;i=i+1)
    {
        cin>>a;
        v.push_back(a);
    }
    int arr[n] ;
    arr[1] = mod(v[1]-v[0]) ;
    arr[0] = 0 ;
    for(i=2 ; i<n ; i=i+1)
    {
    	b = arr[i-1]+ mod(v[i-1]-v[i]) ;
    	for(j=2 ; j<=k ; j=j+1)
    	{
    		if(i-j<0)
    	    {
    	    	break ;
			}
    		c = arr[i-j]+ mod(v[i-j]-v[i]) ;
    		b = min(b,c) ;
		}
    	arr[i] = b ;
	}
	cout<<arr[n-1] ;
}

Measured memory_bytes: 1144
#pragma GCC optimize (Ofast)
#include<bits/stdc++.h>
#include<unordered_map>
using namespace std;
#define forn(i, n) for(int i = 0; i < n; ++i)
#define forit(it, m) for(auto it = m.begin(); it!=m.end(); ++it)

int main(){
	ios::sync_with_stdio(false);
  	cin.tie(0); 
	string s,t;

	{
		cin>>s>>t;
		if(s==t.substr(0,s.length()) && s.length()+1 == t.length())
			cout<<"Yes";
		else cout<<"No";
		
		cout<<endl;
	}
	return 0;
}

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

using namespace std;

#define mod 1e9+7
#define ll long long int
#define epsilon 1e-7

ll mi(ll x, ll y){
    if(x<y)return x;
    return y;
}
vector<pair<int, int>> g[100000];

int dist[100000];

void dfs(int now, int di){
    if(dist[now] != -1)return;
    dist[now] = di%2;
    while(!g[now].empty()){
        pair<int, int>p;
        p = g[now].back();
        dfs(p.first, di + p.second);
        g[now].pop_back();
    }
    return;
}
int main(void){
    int n;
    scanf("%d", &n);
    for(int i = 0;i < n;i++){
        dist[i] = -1;
    }
    for(int i = 0;i < n-1;i++){
        int u, v, w;
        scanf("%d %d %d", &u, &v, &w);
        u--;
        v--;
        w%=2;
        pair<int, int>P1;
        P1.first = v;
        P1.second = w;
        g[u].push_back(P1);
        pair<int, int>P2;
        P2.first = u;
        P2.second = w;
        g[v].push_back(P2);
    }
    dfs(0, 0);
    for(int i = 0;i < n;i++)printf("%d\n", dist[i]);
    return 0;
}


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

void fast(){
ios::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
}

#define ll 		long long
#define pb 		push_back
#define rep(i,x,y)	for(__typeof(x) i=x;i<=y;i++)
#define repi(i,x,y)  	for(__typeof(x) i=x;i>=y;i--)
#define vfor(it,x)	for(__typeof(x.begin()) it= x.begin() ; it!=x.end(); it++)
#define vfori(it,x)	for(__typeof(x.begin()) it= x.end() ; it!=x.begin(); it--)
#define test(t) 	cin >> t;while(t--)
#define yes		cout <<"YES"<<endl;
#define no		cout <<"NO"<<endl;
#define debug(x)	cout << #x <<" = "<<x<<" ";	


int main()
{	
	fast();	
	ll a,b,k;
	cin >> a >> b >> k;
	if(k<=a)
		cout << a-k << " " << b << endl;	
	else if(k-a<=b)
		cout <<"0 " << b-(k-a) << endl;
	else
		cout << "0 0" << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main () {
    int H, W;
    cin >> H >> W;
    vector<vector<char>> pic(H, vector<char>(W));

    for(int i = 0; i < H; i++)
        for(int j = 0; j < W; j++)cin >> pic.at(i).at(j);

    for(int i = 0; i < H + 2; i++){
        for(int j = 0; j < W + 2; j++){
            if(i == 0 || i == H + 1 || j == 0 || j == W + 1){
                cout << '#';
            }
            else cout << pic.at(i - 1).at(j - 1);
        }
        cout << endl;
    }

}

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

map<char, char>mp{ {'[',']'},{'{','}'},{'(',')'},{']','['},{'}','{'},{')','('} };
int main() {
	string s; cin >> s;
	int Max = 0;
	rep(i, 1 << s.size()) {
		string t;
		rep(j, s.size()) {
			if (i >> j & 1)t += s[j];
		}
		if ((int)t.find("iwi") == -1)continue;
		string k = t; reverse(k.begin(), k.end());
		for (char&c : k) {
			if (!isalpha(c))c = mp[c];
		}
		if (k == t)Max = max(Max, (int)t.size());
	}
	printf("%d\n", Max);
}

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

// 型定義
typedef long long ll;
typedef pair<ll, ll> P;

// forループ
#define REP(i,n) for(ll i=0; i<(ll)(n); ++i)

// 定数宣言
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;

// グラフ表現
using Graph = vector<vector<int>>;

// n次元配列の初期化。第２引数の型のサイズごとに初期化していく。
template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}

vector<int> ini_count;
vector<ll> total_count;
vector<bool> seen;

void bfs(const Graph &G, int v, int counter) {
    seen[v] = true;
    total_count[v] = counter + ini_count[v];
    for (auto next_v : G[v]) { 
        if (seen[next_v]) continue;
        bfs(G, next_v, total_count[v]); // 再帰的に値を追加していく
    }
}

int main()
{
    int N, Q;
    cin >> N >> Q;

    // グラフ
    Graph G(N);

    ini_count.assign(N, 0);
    total_count.assign(N, 0);
    seen.assign(N, false);

    REP(i, N-1){
        int a, b;
        cin >> a >> b;
        G[a-1].push_back(b-1);
        G[b-1].push_back(a-1);
    }

    REP(i, Q){
        int p, x;
        cin >> p >> x;
        ini_count[p-1] += x;
    }

    vector<bool> seen(N, false);

    // 幅優先探索で
    bfs(G, 0, 0);

    REP(i, N){
        if(i != N-1){
            cout << total_count[i] << " ";
        }
        else{
            cout << total_count[i] << endl;
        }
    }
    return 0;
}

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

int main(){
 int N;
 cin >> N;
 string str;
 int count = 0;
 for(int i = 1; i <=N; i++){
  str = to_string(i);
  if(str.size() % 2 ==1){
    count++;
  }
 }
 cout << count << endl;
}


Measured memory_bytes: 3668
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
//#include <boost/multiprecision/cpp_ll.hpp>
//typedef boost::multiprecision::cpp_ll ll;
typedef long double dd;
#define i_7 (ll)(1E9+7)
//#define i_7 998244353
#define i_5 i_7-2
ll mod(ll a){
    ll c=a%i_7;
    if(c>=0)return c;
    return c+i_7;
}
typedef pair<ll,ll> l_l;
ll inf=(ll)1E18;
#define rep(i,l,r) for(ll i=l;i<=r;i++)
#define pb push_back
ll max(ll a,ll b){if(a<b)return b;else return a;}
ll min(ll a,ll b){if(a>b)return b;else return a;}
void Max(ll &pos,ll val){pos=max(pos,val);}//Max(dp[n],dp[n-1]);
void Min(ll &pos,ll val){pos=min(pos,val);}
void Add(ll &pos,ll val){pos=mod(pos+val);}
dd EPS=1E-9;
#define endl "\n"
#define fastio ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);


int main(){fastio
    ll n,m,x;cin>>n>>m>>x;
    ll c[n];
    ll a[n][m];
    rep(i,0,n-1){
        cin>>c[i];
        rep(j,0,m-1){
            cin>>a[i][j];
        }
    }
    
    ll po=pow(2,n);
    ll sum[m];
    ll ans=inf;
    rep(i,0,po-1){
        rep(j,0,m-1)sum[j]=0;
        ll tot=0;
        rep(j,0,n-1){
            if((i>>j)&1){
                tot+=c[j];
                rep(k,0,m-1){
                    sum[k]+=a[j][k];
                }
            }
        }
        bool bol=true;
        rep(k,0,m-1){
            if(sum[k]<x){
                bol=false;
            }
        }
        if(bol){
            ans=min(ans,tot);
        }
    }
    if(ans==inf){
        cout<<-1<<endl;
    }else{
        cout<<ans<<endl;
    }
    
    
    return 0;
}




Measured memory_bytes: 4120
class RollingHash:
    """Rolling Hash"""

    __slots__ = ["_base", "_mod", "_hash", "_power"]

    def __init__(self, source: str, base: int = 1007, mod: int = 10 ** 9 + 7) -> None:
        self._base = base
        self._mod = mod
        self._hash = [0] * (len(source) + 1)
        self._power = [0] * (len(source) + 1)

        self._power[0] = 1
        for i, c in enumerate(source, 1):
            self._hash[i] = (self._hash[i - 1] * self._base + ord(c)) % self._mod
            self._power[i] = self._power[i - 1] * self._base % self._mod

    def get_hash(self, left: int, right: int) -> int:
        """Return hash of interval [left, right)."""
        return (
            self._hash[right] - self._hash[left] * self._power[right - left]
        ) % self._mod


def abc141_e():
    # https://atcoder.jp/contests/abc141/tasks/abc141_e
    N = int(input())
    S = input().rstrip()

    rh = RollingHash(S)
    ok, ng = 0, N // 2 + 1
    while ng - ok > 1:
        mid = (ok + ng) // 2
        flg = False
        memo = set()
        for i in range(N - 2 * mid + 1):
            memo.add(rh.get_hash(i, i + mid))
            if rh.get_hash(i + mid, i + 2 * mid) in memo:
                flg = True
                break
        if flg:
            ok = mid  # next mid will be longer
        else:
            ng = mid  # next mid will be shorter

    print(ok)  # max length of substrings appeared twice or more


if __name__ == "__main__":
    abc141_e()


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

using namespace std;
using ll = long long;

int main() {
    int n, k, q;
    cin >> n >> k >> q;
    vector<int> num(n, 0);
    for(int i = 0; i < q; i++) {
        int a;
        cin >> a;
        ++num.at(--a);
    }
    for(int i = 0; i < n; i++) {
        if (k - (q - num.at(i)) <= 0) cout << "No" << endl;
        else cout << "Yes" << endl;
    }
    return 0;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
#define FAST ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0)
#define dofloat cout<<fixed<<setprecision(8)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define bitcount __builtin_popcount
#define all(vec) vec.begin(),vec.end()
#define rall(vec) vec.rbegin(),vec.rend()
using namespace std;
typedef long long ll;
typedef long double ld;
typedef vector<long long> vl;
typedef pair<long long,long long> pll;
typedef vector<pair<long long,long long> > vll;
typedef vector<pair<int,int> > vii;
typedef vector<int> vi;
typedef pair<int,int> ii;
const long long MOD=1000000007;
const long long MAX=100005;
const long double PI=3.14159265359;
const long double G=9.807;
const long long INF=1e18;
const long double EPS=1e-6;
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
bool isprime(ll a){
  if(a==2)return 1;
  if(!(a&1))return 0;
  for(ll i=3;i*i<=a;i+=2)
    if(a%i==0)return 0;
  return 1;
}
ll mpow(ll base,ll exponent,ll modulus){
  if(modulus==1)return 0;
  long long result = 1;
  base=base%modulus;
  while(exponent){
    if(exponent%2 == 1)
    result=(result*base)%modulus;
    exponent=exponent>>1;
    base=(base*base)%modulus;
  }
  return result;
}
ll minv(ll a,ll mod){
  ll _gcd=gcd(a,mod);
  assert(_gcd==1);
  return mpow(a,mod-2,mod);
}


/*
ll ncr(ll N,ll K){
  if(N<K)return 0;
  if(K==0)return 1;
  if(N==0)return 0;

  ll den=1;
  for(ll i=1;i<=K;i++)den*=i;
  ll num=1;
  while(K--){
    num*=N;
    if(num%den==0){
      num/=den;
      den=1;
    }
    N--;
  }

  return num;
}
*/
ll n,m,M;
ll ro[3*MAX],co[3*MAX];
ll cus[3*MAX];

int main(){FAST;
cin>>n>>m>>M;

map<pll,ll>soopers;
for(ll i=1;i<=M;++i){
  ll x,y;cin>>x>>y;
  ++ro[x];
  ++co[y];
  ++soopers[{x,y}];
}
set<ll>ra,ca;
ll mxr = *max_element(ro+1,ro+n+1);
ll mxc = *max_element(co+1,co+m+1);
for(ll i=1;i<=n;++i){
  if(ro[i] == mxr){
    ra.insert(i);
  }
}

for(auto it:soopers){
  if(ra.count(it.first.first))
    ++cus[it.first.second];
}

ll k = ra.size();

ll ans = 1;

for(ll i=1;i<=m;++i){
  if(co[i] == mxc){
    if(cus[i] != k)ans = 0;
  }
}

ans = mxr+mxc-ans;

cout<<ans;
return 0;
}

/*
 WA? check edge cases, N=1,M=1 etc. Read code fully once and check all variables.
 Read the question again and see what you might have missed.
 Consider changing your solution or find more cases.
 */

Measured memory_bytes: 43472
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <sstream>
#include <cassert>
#include <vector>
#include <string>
#include <bitset>
#include <cmath>
#include <algorithm>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <random>
#include <chrono>
#include <ctime>

using namespace std;

#define en '\n'
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) int((x).size())

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

const int INF = 1e9 + 7;
const ll INFLL = 1e18;
const double EPS = 1e-9;
const double PI = 3.1415926535897932384626433832795;
const int MAX_SIZE = 5e5;

mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());

bool IS_ONE_TEST = 1;
ld START_TIME, TIME;

void fast_in_out() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
}

void solve() {
    ll n;
    cin >> n;
    cout << (n % 1000 == 0 ? 0 : 1000 - n % 1000) << en;
}

int main() {
    START_TIME = clock();
    fast_in_out();
    int TESTS = 1;
    if (!IS_ONE_TEST) cin >> TESTS;
    while (TESTS--) { solve(); }
#ifdef __APPLE__
    TIME = (clock() - START_TIME) / CLOCKS_PER_SEC;
    cerr << en << TIME * 1000 << " ms." << en;
#endif
    return 0;
}

/*
     ▄▀▀▀▄
▄███▀░◐░░░▌
    ▌░░░░░▐
    ▐░░░░░▐
    ▌░░░░░▐▄▄
    ▌░░░░▄▀▒▒▀▀▀▀▄
   ▐░░░░▐▒▒▒▒▒▒▒▒▀▀▄
   ▐░░░░▐▄▒▒▒▒▒▒▒▒▒▒▀▄
    ▀▄░░░░▀▄▒▒▒▒▒▒▒▒▒▒▀▄
      ▀▄▄▄▄▄█▄▄▄▄▄▄▄▄▄▄▄▀▄
           ▌▌░▌▌
           ▌▌░▌▌
         ▄▄▌▌▄▌▌        */


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

typedef long long ll;
typedef vector<ll> vi;
typedef pair<ll,ll> ii;

#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define sz(vs) (ll)(vs.size())
#define rep(i,a,b) for (ll i = a; i < b; ++i)
#define rep_(i,a,b) for (ll i = a; i > b; --i)
#define endl '\n'
const ll mod = 1e9 + 7;

const ll maxn = 1e5;

ll n, m;
ll a[maxn];
vi g[maxn];

void solve() {
	cin >> n;
	int rem7 = 7 % n;
	int rem = 7 % n;
	rep(i, 1, 2 * n + 2) {
		if (!rem) {
			cout << i;
			return;
		}
		rem = ((rem * 10) % n + rem7) % n;
	}
	cout << -1;
}

void aux() {
}

int main() {
	ios_base::sync_with_stdio(false); cin.tie(NULL);
	cout<<fixed<<setprecision(10);
	aux();
	ll _ = 1;
	// cin>>_;
	while(_--) {
		solve();
	}
	return 0;
}

Measured memory_bytes: 5996
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
using ll = int64_t;
#define rep(i,n) for(int i = 0; i < ((int)(n)); i++)   // 0-indexed昇順

int main() {
    int N; cin >> N;
    vector<bool> A(N+1), B(N+1);
    for (int i = 1; i <= N; i++) {
        int a; cin >> a;
        A.at(i) = a;
    }

    int M = 0;
    int cnt = 0;
    for (int i = N; i > 0; i--) {
        int p = 0;
        for (int j = i + i; j <= N; j += i) {
            p += B[j];
        }
        if (A[i] == p % 2) continue;
        B[i] = 1;
        cnt++;
        if (M < i) M = i;
    }
    cout << cnt << endl;
    if (M == 0) return 0;
    for (int i = 1; i <= M; i++) {
        if (B[i] == 1) {
            cout << i;
            if (i != M) cout << " ";
        }
    }
    cout << endl;
}


Measured memory_bytes: 3596
//#define _GLIBCXX_DEBUG
#include<bits/stdc++.h>
#define PI 3.14159265359
using namespace std;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
const long long INF= 1e+18+1;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll> >vvl;
typedef pair<ll,ll> P;
typedef tuple<ll,ll,ll> T;
const ll MOD=1000000007LL;
string abc="abcdefghijklmnopqrstuvwxyz";
string ABC="ABCDEFGHIJKLMNOPQRSTUVWXYZ";
int main(){
  ll n,a,b;cin>>n>>a>>b;
  vl h(n);
  rep(i,n)cin>>h[i];
  ll ng=0,ok=1e9;
  while(ok-ng>1){
    ll md=(ok+ng)/2;
    ll cnt=0;
    rep(i,n){
      cnt+=(max(0LL,h[i]-md*b)+(a-b)-1)/(a-b);
    }
    if(cnt<=md)ok=md;else ng=md;
  }
  cout<<ok<<endl;
}
  

Measured memory_bytes: 1024
x, y = map(int, input().split())

if x <= y:
    if 0 <= x or y <= 0:
        print(y-x)
    elif abs(x) >= abs(y):
        print(abs(x) - abs(y) + 1)
    else:
        print(1+abs(y)-abs(x))
else:
    if 0 < y or x < 0:
        print(1+abs(x-y)+1)
    elif x == 0 or y == 0:
        print(abs(x-y)+1)
    elif abs(x) >= abs(y):
        print(1+abs(x)-abs(y))
    else:
        print(abs(y)-abs(x)+1)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define range(i, a, b) for(int i = (a); i < (b); i++)
#define rep(i, a) range(i, 0, a)
using namespace std;

int main() {
    int n;
    cin >> n;
    vector <int> x(n), y(n), h(n);

    rep(i, n)
    {
        cin >> x[i] >> y[i] >> h[i];
    }

    rep(i, 101) rep(j, 101)
    {
        set <int> cands_h;
        rep(k, n)
        {
            if(h[k] > 0)
            cands_h.insert(h[k] + abs(i - x[k]) + abs(j - y[k]));
        }

        for(auto & cand_h : cands_h)
        {
            bool ok = true;
            rep(k, n)
            {
                ok &= max(cand_h - abs(i - x[k]) - abs(j - y[k]), 0) == h[k];
            }
            if(ok)
            {
                cout << i <<  " " << j << " " << cand_h << endl;
                return 0;
            }
        }
    }

    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cmath>
#include<vector>
#include<queue>
#include<map>
#include<algorithm>
#include<complex>
#include<string>
#include<cstring>
using namespace std;
#define rep2(x,from,to) for(int x=(from);(x)<(to);(x)++)
#define rep(x,to) rep2(x,0,to)
#define INF 100000000
#define debug(x) cout<<#x<<": "<<x<<endl

#define all(x) x.begin(),x.end()
typedef pair<int,int> P;
typedef pair<int,P> PP;
string s;
int h,w;
int main()
{
	cin>>h>>w;
	rep(i,h)
	{
		rep(j,w)
		{
			cin>>s;
			if(s=="snuke")
			{
				printf("%c%d\n",'A'+j,i+1);
			}
		}
	}
	return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		while (true) {
			int a = scanner.nextInt();
			int b = scanner.nextInt();
			if (a == 0 & b == 0)
				break;
			for (int i = 0; i < a; i++) {
				for (int j = 0; j < b; j++) {
					if (i % 2 == 0 && j % 2 == 0 || i % 2 == 1 && j % 2 == 1)
						System.out.print("#");
					else
						System.out.print(".");
				}
				System.out.println();
			}
			System.out.println();
		}
	}
}

Measured memory_bytes: 26832
#include<stdio.h>
#define MAX 100
#define WHITE 0
#define GRAY 1
#define BLACK 2

void search(int);
void search_in();

int n, G[MAX][MAX];
int color[MAX],first_count[MAX],second_count[MAX];
int counter;

int main(){
  
  int num,sum,bin,ain;
  int a,b;
  
  scanf("%d",&n);
  
  for(a=0;a<n;a++){
    for(b=0;b<n;b++)G[a][b]=0;
  }
  
  for(a=0;a<n;a++){
    scanf("%d%d",&bin,&sum);
    bin--;
    for(b=0;b<sum;b++){
      scanf("%d",&ain);
      ain--;
      G[bin][ain]=1;
    }
  }
  
  search_in();
  
  for(a=0;a<n;a++)printf("%d %d %d\n",a+1,first_count[a],second_count[a]);
  
  return 0;
}

void search(int u){
  
  int a;
  
  color[u]=GRAY;
  counter++;
  first_count[u]=counter;
  
  for(a=0;a<n;a++){
    if (G[u][a]==0)continue;
    if(color[a]==WHITE)search(a);
  }
  color[u]=BLACK;
  counter++;
  second_count[u]=counter;
}

void search_in(){
  
  int  a;
  for(a=0;a<n;a++)color[a]=WHITE;
  
  counter=0;
  
  for(a=0;a<n;a++){
    if(color[a]==WHITE)search(a);
  }
}




Measured memory_bytes: 2112
#!/usr/bin/env python3
# encoding:utf-8
import copy
import random
import bisect #bisect_left　これで二部探索の大小検索が行える
import fractions #最小公倍数などはこっち
import math
import sys
import collections
from decimal import Decimal # 10進数で考慮できる

mod = 10**9+7
sys.setrecursionlimit(mod) # 再帰回数上限はでdefault1000

d = collections.deque()
def LI(): return list(map(int, sys.stdin.readline().split()))

A, B, C, D = LI()
ans = max(min(B, D) - max(A, C), 0)
print(ans)

Measured memory_bytes: 10820
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <bitset>
#include <algorithm>
#include <complex>
#include <array>
#include <functional>
#include <stack>
#include <iomanip>
#include <limits>
using namespace std;
#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define ALL(c) (c).begin(), (c).end()

typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<double> VD;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef vector<VD> VVD;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;
using Graph=vector<vector<int>>;
using edge= struct{int to;ll cost;};


template<class t,class u> void chmax(t&a,u b){if(a<b)a=b;}
template<class t,class u> void chmin(t&a,u b){if(b<a)a=b;}
using Graph =vector<vector<int>>;
//xor


int main(){
  int x,y,a,b,c;cin>>x>>y>>a>>b>>c;
  priority_queue<ll,vector<ll>,greater<ll>> p;
  priority_queue<ll,vector<ll>,greater<ll>> q;
  priority_queue<ll> r;
  priority_queue<ll> ans;
  int tmp;
  REP(i,a){
    cin>>tmp;
    p.push(tmp);
  }
  REP(i,b){
    cin>>tmp;
    q.push(tmp);
  }
  REP(i,c){
    cin>>tmp;
    r.push(tmp);
  }
  if(a-x>=0){
    for(int i=0;i<a-x;i++){
      p.pop();
    }
  }
  if(b-y>=0){
    for(int i=0;i<b-y;i++){
      q.pop();
    }
  }
  while(!p.empty()){
    r.push(p.top());
    p.pop();
  }
  while(!q.empty()){
    r.push(q.top());
    q.pop();
  }
  ll final=0;
  REP(i,x+y){
    final+=r.top();
    r.pop();
  }
  cout<<final<<endl;
}


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

typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;
const ull mod = 1e9 + 7;
#define REP(i,n) for(int i=0;i<(int)n;++i)

//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

template < typename T >
void vprint(T &v){
	REP(i, v.size()){
		cout << v[i] << " ";
	}
	cout << endl;
}

int main(){
	ll N;
	cin >> N;
	ll dig[4];
	dig[0] = N/1000;
	N %= 1000;
	dig[1] = N/100;
	N %= 100;
	dig[2] = N/10;
	N %= 10;
	dig[3] = N;
	REP(mask, 1<<3){
		ll ope[3];
		REP(k, 3) ope[k] = (mask>>k & 1);
		ll res = dig[0];
		REP(k, 3){
			res += (ope[k]==1?dig[k+1]:-dig[k+1]);
		}
		if(res==7){
			cout << dig[0] << (ope[0]==1?'+':'-') << dig[1] << (ope[1]==1?'+':'-') << dig[2] << (ope[2]==1?'+':'-') << dig[3] << "=7" << endl;
		return 0;
		}
	}
    return 0;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {

	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		String str = "";
		char c, d;
		boolean flg;
		int count=0;
		
		while( scan.hasNext()) {
			str = scan.next();

			flg = false;
			for( int i=0; i<(str.length()/2); i++) {
				c = str.charAt(i);
				d = str.charAt(str.length()-1-i);
				if(c!=d) {flg = true; break;}
				
			}
			if(!flg) count++;
		}
		scan.close();
		System.out.println(count);
	}

}

Measured memory_bytes: 12000
#include <iostream>

using namespace std;
 
int main(void){
	string a, b;
	cin >> a >> b;
	int n = stoi(a + b);
	for(int i = 0; i < 10000; i++){
		if(i * i == n){
			cout << "Yes" << endl;
			return 0;
		}
	}
	cout << "No" << endl;
	return 0;
}

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

#define INF ((1<<30)-1)
#define LLINF (1LL<<60)
#define EPS (1e-10)

struct edge { int to, cost; };
int V;
vector<edge> g[101010];
int d[101010];
int prv[101010];

void dijkstra(int s) {
    priority_queue<pair<int, int>, vector<pair<int, int>>, greater<pair<int, int>>> que;
    fill(d, d+V, INF);
    d[s] = 0;
    que.push({0, s});

    while (que.size()) {
        auto p = que.top(); que.pop();
        int v = p.second;
        if (d[v] < p.first) continue;
        for (auto e : g[v]) {
            if (d[e.to] > d[v] + e.cost) {
                d[e.to] = d[v] + e.cost;
                que.push({d[e.to], e.to});
                prv[e.to] = v;
            }
        }
    }
}

int main() {
    int M;
    cin >> V >> M;
    rep(i, M) {
        int a, b;
        cin >> a >> b;
        a--;
        b--;
        g[a].push_back(edge{b, 1});
        g[b].push_back(edge{a, 1});
    }
    dijkstra(0);

    cout << "Yes" << endl;
    for (int i = 1; i < V; ++i) {
        cout << prv[i]+1 << endl;
    }
}


Measured memory_bytes: 13580
#include <stdio.h>

int main(void)
{
	int x, answer, i, j, k;
	while(scanf("%d", &x)==1)
	{
		answer = 0;
		
		for(i = 0; i <= 9; i++)
		{
			if(i > x || i + 27 < x)
			{
				continue;
			}
			for(j = 0; j <= 9; j++)
			{
				if(i + j > x || i + j + 18 < x)
				{
					continue;
				}
				for(k = 0; k <= 9; k++)
				{
					if(i + j + k > x || i + j + k + 9 < x)
					{
						continue;
					}
					answer++;
				}
			}
		}
		
		printf("%d\n", answer);
	}
	return 0;
}

Measured memory_bytes: 596
#include <iostream>
#include <vector>
#include <map>

using namespace std;
using ll = long long;

void gen(vector<ll>& a, const int N, const ll S, const ll W)
{
    ll g = S;
    for (int i = 0; i < N; i++) {
        a[i] = (g / 7) % 10;
        if (g % 2 == 0) {
            g = (g / 2);
        } else {
            g = (g / 2) ^ W;
        }
    }
}

int main()
{
    while (true) {
        int N;
        ll S, W, Q;
        cin >> N >> S >> W >> Q;
        if (N == 0 and S == 0 and W == 0 and Q == 0) {
            break;
        }
        vector<ll> a(N);
        gen(a, N, S, W);

        if (Q != 2 and Q != 5) {
            vector<ll> hash(N + 1, 0);  // a_(i)..a_(N-1)
            ll base = 10;
            for (int i = N - 1; i >= 0; i--) {
                hash[i] = (hash[i + 1] + a[i] * base) % Q;
                base = (base * 10) % Q;
            }
            map<ll, int> num;
            num[0]++;
            ll ans = 0;
            for (int i = N - 1; i >= 0; i--) {
                if (a[i] != 0) {
                    ans += num[hash[i]];
                }
                num[hash[i]]++;
            }
            cout << ans << endl;
        } else {
            vector<int> num(N, 0);
            num[N - 1] = (a[N - 1] % Q == 0 ? 1 : 0);
            for (int i = N - 2; i >= 0; i--) {
                num[i] = num[i + 1] + (a[i] % Q == 0 ? 1 : 0);
            }
            ll ans = 0;
            for (int i = 0; i < N; i++) {
                if (a[i] == 0) {
                    continue;
                }
                ans += num[i];
            }
            cout << ans << endl;
        }
    }
    return 0;
}



Measured memory_bytes: 9856
N = int(input())
T, A = map(int,input().split())
H = list(map(int,input().split()))
a = []
for i in H:
    t = T - i * 0.006
    a.append(t)
for i in range(N):
    a[i] = abs(a[i]- A)
x = a[0]
for i in range(N - 1):
    if x > min(a[i],a[i +  1]):
        x = min(a[i],a[i +  1])
ans = a.index(x) + 1
print(ans)

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

int main() {
  int N, A, min = 100;
  cin >> N;
  for (int i = 0; i < N; i++) {
    cin >> A;
    int c = 0;
      while (A % 2 == 0) {
         A /= 2;
         c++;
      }
    if (c <= min) {
      min = c;
    }
  }
  cout << min << endl;
}

Measured memory_bytes: 256
#!/usr/bin/env python3
import sys


def solve(N: int, V: "List[int]", C: "List[int]"):
    return sum(filter(lambda x: x>0, [v-c for v, c in zip(V, C)]), 0)


# Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    V = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    C = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    print(solve(N, V, C))

def test():
    import doctest
    doctest.testmod()

if __name__ == '__main__':
    #test()
    main()


Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n;
	cin >> n;
	double a,sum=0;
	for(int i=0;i<n;i++){
		scanf("%lf",&a);
		sum+=1.0/a;
	}
	printf("%lf\n",1.0/sum);
	return 0;
}

Measured memory_bytes: 256
import math

N, K = map(int, input().split())
ans = 0

for i in range(1,N+1):
    tmp = math.log(K/i, 2)
    x = int(math.log(K/i,2))
    if i >= K:
        ans += 1/N
    else:
        if tmp - x != 0:
            x += 1
        ans += 1/N * (0.5)**x

print(ans)


Measured memory_bytes: 39024
#include <bits/stdc++.h>
using namespace std;
typedef long long ll; //10^19 < 9223372036854775807
typedef unsigned long long ull; //10^20 < 18446744073709551615

#define REP(i,n) for(ll i=0;i<ll(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=ll(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=ll(b);i--)
#define FORA(i,I) for(const auto& i:I)
#define ALL(x) x.begin(),x.end() 
#define SIZE(x) ll(x.size()) 

#define MOD 1000000007

int main(void)
{
    ll N;
    cin >> N;

    ll ans = 1000000000010;
    for (ll i = 1; i <= sqrt(N); i++) {
        if (N%i == 0) {
            ans = min((N/i-1) + i-1, ans);
        }
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 3680
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main(){
    long long N;
    cin >> N;
    vector<long long> a(N), b(N);
    for(int i = 0; i < N; i++) cin >> a[i];
    for(int i = 0; i< N; i++)cin >> b[i];
    for(int i = 0; i < N; i++){
        if((b[i] - a[i]) % 2 == 1){
            a[i] += 2;
            b[i] += 1;
        }
    }
    long long res = 0, res2 = 0;
    for(int i = 0; i < N; i++){
        if(b[i] > a[i]) res += b[i] - a[i];
        else res2 += a[i] - b[i];
    }
    if(res2 * 2 > res){
        cout << "No" << endl;
        return 0;
    }
    cout << "Yes" << endl;
}

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

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

Measured memory_bytes: 3600
#include <bits/stdc++.h>
using namespace std;
typedef long long lo;
typedef vector<lo> vl;
typedef vector<vl>vll;
#define all(v) (v).begin(), (v).end()
#define debug(x) cerr<<#x<<" = "<<x<<endl;
#define REPV(a, b, c) for (lo(a) = b; (a) < (c); (a)++) 
#define REP(a,b) for(lo i =(a) ;i<(b);i++)

template <typename T>

istream &operator>>(istream &in, vector<T> &v)
{
    for (unsigned i = 0; i < v.size(); i++)
        in >> v[i];
    return in;
}




int main(){
    ios::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    cout.precision(20);
    lo A,B,C,K,ans=0; 
    cin>>A>>B>>C>>K;
    if(K>A){
        K-=A;
        ans+=A;
    }
    else
    {
        cout<<K<<endl;
        return 0;
    }
    if(K>B){
        K-=B;
    }
    else{
        cout<<ans<<endl;
        return 0;
    }
    if(K>C){
        K-=C;
        ans-=C;
    }
    else{
        ans-=K;
        cout<<ans<<endl;
        return 0;
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 3648
W, H, N = map(int, input().split())
ary = [list(map(int, list(input().split()))) for i in range(N)]
rec = [[1 for i in range(W)] for j in range(H)]

for i in range(N):
    if ary[i][2] == 1:
        for j in range(W):
            if j < ary[i][0]:
                for k in range(H):
                    rec[k][j] = 0
    elif ary[i][2] == 2:
        for j in range(W):
            if j >= ary[i][0]:
                for k in range(H):
                    rec[k][j] = 0
    elif ary[i][2] == 3:
        for j in range(H):
            if j < ary[i][1]:
                for k in range(W):
                    rec[j][k] = 0
    elif ary[i][2] == 4:
        for j in range(H):
            if j >= ary[i][1]:
                for k in range(W):
                    rec[j][k] = 0
print(sum(sum(i) for i in rec))

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


int main(){
    int A, B, C, K;
    int picked_A, picked_B, picked_C;
    cin >> A >> B >> C >> K;

    unsigned int i;
    int ans = 0;

    if( A - K < 0 ){
        ans = A;

        int tmp_K = K - A;
        if( B - tmp_K < 0 ){
            int tmp_K2 = tmp_K - B;
            ans -= tmp_K2;
        }
    }
    else{
        ans = K;
    }

    cout << ans << endl;
    return 0;



}

Measured memory_bytes: 3636
import java.util.*;

class Main {
	public static void main (String[] args) {
    	Scanner sc=new Scanner(System.in);
    	int N=sc.nextInt();
    	int num=0;
    	for(int i=1;i<=9;i++){
    	    if(N<=(i*100+i*10+i)){
    	        num=i*100+i*10+i;
    	        break;
    	    }     
    	}
    	System.out.println(num);
	}
}

Measured memory_bytes: 21844
def multmod(a,b,m):
  ans = 0
  a = a % m
  
  while b:
    if (b & 1): # odd
      ans = (ans + a) % m
    
    a = (2 * a) % m
    b >>= 1 # b = b / 2
    
  return ans

n = int(input())
S = [int(a) for a in input().split()]
divisor = 10**9 + 7
tot = 0
a,b = 0,0
arr_sum = sum(S) #% divisor
arr_ssq = arr_sum*arr_sum #% divisor
isq_sum = 0
for i in range(n):
  isq_sum += S[i]*S[i] #% divisor
  
#isq_sum = isq_sum % divisor
tot = (arr_ssq - isq_sum)//2 % divisor

print(tot)

Measured memory_bytes: 31356
#define E(n,e)else if(!(k&n))for(x=0;x<5;x++)puts(k&1<<(e+x)?"1":"2");
#define K(n)||(k&n)==n
i,k;main(x){for(;;i++){scanf("%d",&x);if(!x)exit(0);k+=1<<(5*x+i);if(i==4){if((k&992&&k&31744&&k&1015808)K(992)K(31744)K(1015808))for(x=5;x--;)puts("3");E(992,10)E(31744,15)E(1015808,5)k=0,i=-1;}}}

Measured memory_bytes: 584
#include <iostream>

int main()
{
	int n, a;

	std::cin >> n;

	int min = 1000000, max = -1000000;
	long sum = 0;
	for (int i = 0; i < n; ++i)
	{
		std::cin >> a;
		if (a < min) min = a;
		if (a > max) max = a;
		sum += a;
	}

	std::cout << min << " " << max << " " << sum << std::endl;

	return 0;
}

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

using namespace std;

int main() {
  ios::sync_with_stdio(false);

  unsigned long a, b;
  cin >> a >> b;
  bitset<32> bsa(a);
  bitset<32> bsb(b);

  cout << (bsa & bsb) << endl;
  cout << (bsa | bsb) << endl;
  cout << (bsa ^ bsb) << endl;
}




Measured memory_bytes: 3240
#include<stdio.h>

int main()
{
	int a[120] = {0}, n, input[4], i, j, k;

	scanf("%d", &n);
	for (i = 0; i < n; i++)
	{
		for (j = 0; j < 4; j++)
			scanf("%d", input + j);
		a[(input[0] - 1) * 30 + (input[1] - 1) * 10 + (input[2] - 1)] += input[3];
	}

	for (i = 0; i < 4; i++)
	{
		for (j = 0; j < 3; j++)
		{
			for (k = 0; k < 10; k++)
				printf(" %d", a[i * 30 + j * 10 + k]);
			printf("\n");
		}
		if (i < 3)
		{
			for (j = 0; j < 20; j++)
				printf("#");
			printf("\n");
		}
	}
	return 0;
}


Measured memory_bytes: 2048
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)
INF = float('inf')

N = int(input())
h = list(map(int, input().split()))
h.append(0) #はみ出す
dp = [INF] * (N+1) #はみ出す
dp[0] = 0

for i in range(N-1):
    dp[i+1] = min(dp[i+1], dp[i]+abs(h[i+1]-h[i]))
    dp[i+2] = min(dp[i+2], dp[i]+abs(h[i+2]-h[i]))
print(dp[N-1]) #はみ出す

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

using namespace std;

#define loop(i, n) for(int i = 0;i < int(n);i++)
#define rloop(i, n) for(int i = int(n);i >= 0;i--)
#define range(i, a, b) for(int i = int(a);i <= int(b);i++)
#define SZ(c) int(c.size())
#define ALL(c) c.begin(), c.end()
#define RALL(c) c.rbegin(), c.rend()
#define PI acos(-1)
#define pb push_back
#define mp make_pair
#define fr first
#define sc second
#define sfi1(v) scanf("%d",&v)
#define sfi2(v1, v2) scanf("%d %d",&v1,&v2)
#define sfi3(v1, v2, v3) scanf("%d %d %d",&v1,&v2,&v3)
#define sfll1(v) scanf("%I64d",&v);
#define sfll2(v1, v2) scanf("%I64d %I64d",&v1,&v2)
#define sfll3(v1, v2, v3) scanf("%I64d %I64d %I64d",&v1,&v2,&v3)
#define endl '\n'

typedef vector<int> vi;
typedef vector<pair<int, int> > vii;
typedef long long ll;
typedef pair<int, int> pii;

const int N = 1e5 + 5;
const int LG = 18;
int up[N][LG];
int arr[N];
int n, l, q;

void run_case() {
    cin >> n;
    loop(i, n)cin >> arr[i];
    cin >> l >> q;

    rloop(i, n - 1) {
        int par = i == n - 1 ? n - 1 : (upper_bound(arr + i, arr + n, arr[i] + l) - arr - 1);
        up[i][0] = par;
        for (int k = 1; k < LG; ++k)
            up[i][k] = up[up[i][k - 1]][k - 1];
    }

    while (q--) {
        int a, b;
        cin >> a >> b;
        a--, b--;
        if (a > b)swap(a, b);
        int ans = 1;
        for (int i = LG - 1; i >= 0; i--) {
            if (up[a][i] < b) {
                a = up[a][i];
                ans += 1 << i;
            }
        }
        cout << ans << endl;
    }
}

int main() {

#ifndef ONLINE_JUDGE
//    freopen("in.in", "r", stdin);
//    freopen("out.in", "w", stdout);
#endif
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);


    int T = 1;
//    cin >> T;
    while (T--)run_case();

    return 0;
}


Measured memory_bytes: 11068
#include <bits/stdc++.h>
#define BIT(n) (1LL << (n))
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPB(i, n) for (int i = 0; i < BIT(n); i++)
#define REPS(i, x) for (int i = 1; i <= (int)(x); i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define FORA(i, n) for (auto &&i : n)
#define FORS(i, m, n) for (int i = m; i <= n; i++)
#define DEBUG(x) cerr << #x << ": " << x << "\n"
#define PRINTALL(V)    \
  for (auto v : (V)) { \
    cout << v << " ";  \
  }                    \
  cout << "\n";
#define ALL(v) v.begin(), v.end()
#define fst first
#define snd second
#define mp make_pair
#define pb push_back
#define epb emplace_back
#define int long long
using namespace std;
template <class T> bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> bool chmin(T &a, const T &b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> using vec = std::vector<T>;
template <class T> void print(const T &x) { cout << x << "\n"; }
const int MOD = 1000000007, INF = 1061109567;
const double EPS = 1e-10, PI = acos(-1.0);
const int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
signed main() {
  cin.tie(0), ios::sync_with_stdio(false);
  cout << fixed << setprecision(10);
  int N, M;
  cin >> N >> M;
  if (N < M) swap(M, N);
  if (N == 1 && M == 1) {
    print(1);
  } else if (M == 1) {
    print(N - 2);
  } else {
    print((N - 2) * (M - 2));
  }
}

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

int main(){

  int q1,b,c1,c2,q2;
  int sum1,sum2;

  while(cin >> q1 && q1){

    cin >> b >> c1 >> c2 >> q2;
    sum1 = sum2=0;

    while(b>=c1 && q2>0){
      sum1 ++;
      b -= c1;
      q2--;
    }
    while(b>=c2){
      sum2++;
      b -= c2;
    }

    while(sum1>1 && sum1+sum2<q1){
      sum1--;
      b+=c1;
      while(b>=c2){
	b-=c2;
	sum2++;
      }
    }
   

    if(sum1+sum2 >= q1 && sum1>0){
      cout << sum1 << ' ' << sum2 << endl;
    }
    else{
      cout << "NA" << endl;
    }

  }
      

  return 0;
}

Measured memory_bytes: 1160