akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#define FOR(i, n, m) for(int i = n; i < (int)m; i++)
#define REP(i, n) FOR(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define pb push_back
using namespace std;
using ll = std::int_fast64_t;
using P = pair<ll, ll>;
constexpr ll inf = 1000000000;
constexpr ll mod = 1000000007;
constexpr long double eps = 1e-15;
template<typename T1, typename T2>
ostream& operator<<(ostream& os, pair<T1, T2> p) {
    os << to_string(p.first) << " " << to_string(p.second);
    return os;
}
template<typename T>
ostream& operator<<(ostream& os, vector<T>& v) {
    REP(i, v.size()) {
        if(i) os << " ";
        os << to_string(v[i]);
    }
    return os;
}

struct modint {
    ll n;
public:
    modint(const ll n = 0) : n((n % mod + mod) % mod) {}
    static modint pow(modint a, int m) {
        modint r = 1;
        while(m > 0) {
            if(m & 1) { r *= a; }
            a = (a * a); m /= 2;
        }
        return r;
    }
    modint &operator++() { *this += 1; return *this; }
    modint &operator--() { *this -= 1; return *this; }
    modint operator++(int) { modint ret = *this; *this += 1; return ret; }
    modint operator--(int) { modint ret = *this; *this -= 1; return ret; }
    modint operator~() const { return (this -> pow(n, mod - 2)); } // inverse
    friend bool operator==(const modint& lhs, const modint& rhs) {
        return lhs.n == rhs.n;
    }
    friend bool operator<(const modint& lhs, const modint& rhs) {
        return lhs.n < rhs.n;
    }
    friend bool operator>(const modint& lhs, const modint& rhs) {
        return lhs.n > rhs.n;
    }
    friend modint &operator+=(modint& lhs, const modint& rhs) {
        lhs.n += rhs.n;
        if (lhs.n >= mod) lhs.n -= mod;
        return lhs;
    }
    friend modint &operator-=(modint& lhs, const modint& rhs) {
        lhs.n -= rhs.n;
        if (lhs.n < 0) lhs.n += mod;
        return lhs;
    }
    friend modint &operator*=(modint& lhs, const modint& rhs) {
        lhs.n = (lhs.n * rhs.n) % mod;
        return lhs;
    }
    friend modint &operator/=(modint& lhs, const modint& rhs) {
        lhs.n = (lhs.n * (~rhs).n) % mod;
        return lhs;
    }
    friend modint operator+(const modint& lhs, const modint& rhs) {
        return modint(lhs.n + rhs.n);
    }
    friend modint operator-(const modint& lhs, const modint& rhs) {
        return modint(lhs.n - rhs.n);
    }
    friend modint operator*(const modint& lhs, const modint& rhs) {
        return modint(lhs.n * rhs.n);
    }
    friend modint operator/(const modint& lhs, const modint& rhs) {
        return modint(lhs.n * (~rhs).n);
    }
};
istream& operator>>(istream& is, modint m) { is >> m.n; return is; }
ostream& operator<<(ostream& os, modint m) { os << m.n; return os; }

using mi = modint;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int a, b;
    cin >> a >> b;
    if(a % 2 && b % 2) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
using ll = long long; using ull = unsigned long long;
using vb = vector<bool>;
using vi = vector<int>; using vvi = vector<vector<int>>;
using vl = vector<ll>; using vvl = vector<vector<ll>>;
using pii = pair<int,int>; using pll = pair<ll,ll>;
#define FOR(i,a,b) for(ll i = (a); i < (ll)(b); i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(obj) (obj).begin(), (obj).end()
#define rALL(obj) (obj).rbegin(), (obj).rend()
#define eb(val) emplace_back(val)
const double PI = acos(-1);
const double EPS = 1e-10;
const ll MOD = 1e9+7;
//#define int ll
void cioacc(){//accelerate cin/cout
  cin.tie(0);
  ios::sync_with_stdio(false);
}
signed main(){
  int a,b;
  cin >> a >> b;
  cout << b + (b%a==0?a:-a) << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
typedef long long ll;
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,a) FOR(i,0,a)
	
using namespace std;
const int MAX_N=1e5,MAX_D=1e3;
int N,D;
int zip[MAX_D][MAX_D],psm[2][MAX_D*2+1][MAX_D*2+1];
bool C(int b){
	bool ans=false;
	REP(i,D){
		REP(j,D){
			if (psm[0][D+i][D+j]-psm[0][D+i][b+1+j]-psm[0][b+1+i][D+j]+psm[0][b+1+i][b+1+j]==0
			&& psm[1][D+i][b+1+j]-psm[1][D+i][j]-psm[1][b+1+i][b+1+j]+psm[1][b+1+i][j]==0
			&& psm[1][b+1+i][D+j]-psm[1][i][D+j]-psm[1][b+1+i][b+1+j]+psm[1][i][b+1+j]==0){
				ans=true;
			}
		}
	}
	return ans;
}
int main(){
	cin>>N>>D;
	REP(i,N){
		int x,y;
		cin>>x>>y;
		zip[x%D][y%D]++;
	}
	int a;
	{
		int mx=0;
		REP(i,D){
			REP(j,D){
				mx=max(mx,zip[i][j]);
			}
		}
		a=0;
		while(mx>(a+1)*(a+1)){
			a++;
		}
	}
	REP(i,D){
		REP(j,D){
			if (zip[i][j]>a*a){
				REP(s,2)REP(t,2){
					psm[0][i+1+D*s][j+1+D*t]++;
				}
			}
			if (zip[i][j]>a*(a+1)){
				REP(s,2)REP(t,2){
					psm[1][i+1+D*s][j+1+D*t]++;
				}
			}
		}
	}
	REP(i,D*2)REP(j,D*2){
		REP(k,2){
			psm[k][i+1][j+1]+=psm[k][i+1][j]+psm[k][i][j+1]-psm[k][i][j];
		}
	}
	int lb=-1,ub=D-1;
	while(ub-lb>1){
		int m=(lb+ub)/2;
		if (C(m)){
			ub=m;
		}else{
			lb=m;
		}
	}
	cout<<a*D+ub<<endl;
}

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

int main(void){
    int n,m,correct=0,pen=0;
    cin >> n >> m;
    vector<int> iscollect(n+1,0),numofwrong(n+1,0);
    for(int i=0;i<m;i++){
        int p;
        string s;
        cin >> p >> s;
        if(iscollect[p]) continue;
        if(s=="WA") numofwrong[p]++;
        if(s=="AC"){
            iscollect[p]++;
            correct++;
            pen+=numofwrong[p];
        }
    }
    cout << correct << " " << pen;
}

Measured memory_bytes: 4048
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <utility>
#include <cmath>
#include <functional>
#include <queue>
#include <climits>
#define REP(i,n) for(int i=0;i<n;i++)
#define FOR(i,n1,n2) for(int i=n1;i<n2;i++)
#define put(a) cout<<a<<endl;
using namespace std;
typedef long long ll;
//typedef unsigned long long ull;
typedef pair<int, int> P;

int h,w;
//stinrg a[101];
int main() {
    cin >> h >> w;
    vector<string> a(h);
    REP(i,h){
        cin >> a[i];
    }
    vector<bool> b(h);
    vector<bool> c(w);
    REP(i,h){
        bool flag = true;
        REP(j,w){
            if(flag&&a[i][j]=='.'){
            }else{
                flag=false;
            }
            b[i]=flag;
        }
    }
    REP(i,w){
        bool flag = true;
        REP(j,h){
            if(flag&&a[j][i]=='.'){
            }else{
                flag=false;
            }
            c[i]=flag;
        }
    }
    /*REP(i,h){
        put(b[i]);
    }
    REP(i,h){
        put(c[i]);
    }*/
    vector<string> res;
    REP(i, h){
        if(!b[i]){
            string d = "";
            REP(j,w){
                if(!c[j]){
                    d += a[i][j];
                }
            }
            res.push_back(d);
        }
    }
    REP(i,res.size()){
        put(res[i]);
    }
    //
    //put(res);
    //
    //put(res.size());
    //put(h);
    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<iostream>
#include<algorithm>
#include<string>
#include<string.h>
#include<math.h>
#include<stdlib.h>
#include<vector>
#include<queue>
#include<map>
#include<tuple>
#include<bitset>
#include<iomanip>
#define rep(index,num) for(int index=0;index<num;index++)
#define rep1(index,num) for(int index=1;index<=num;index++)
#define scan(argument) cin>>argument
#define prin(argument) cout<<argument<<endl
#define kaigyo cout<<endl
#define eps 1e-15
#define mp(a1,a2) make_pair(a1,a2)
typedef long long ll;
using namespace std;
typedef pair<ll,ll> pll;
typedef pair<int,int> pint;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<pint> vpint;
typedef vector<pll> vpll;
ll INFl=1e+18+1;
int INF=1e+9+1;
int main(){
	int N;
	ll a[300001];
	ll ans=0;
	scan(N);
	rep(i,3*N){
		scan(a[i]);
		a[i]=-a[i];
	}
	sort(a,a+3*N);
	rep(i,N){
		ans-=a[i*2+1];
	}
	prin(ans);
	return 0;
}


Measured memory_bytes: 2560
#include <bits/stdc++.h>
#define MAX 1000000000000000000
using namespace std;
using ll = long long;
ll p = 1, nr, n, v[100100];

int main() {
    cin >> n;
    for (int i = 1; i <= n; i++) {
        cin >> v[i];
        if (v[i] == 0) {
            cout << 0;
            return 0;
        }
    }
    for (int i = 1; i <= n; i++) {
        if (p > MAX / v[i]) {
            cout << -1;
            return 0;
        }
        p *= v[i];
    }
    cout << p;
    return 0;
}


Measured memory_bytes: 4404
import itertools

N = int(input())
d753 = ["3", "5", "7"]

c = 0
for i in range(1, 10):
	for d in itertools.product(d753, repeat = i):
		if d.count("3") >= 1 and d.count("5") >= 1 and d.count("7") >= 1:
			x = int("".join(d))
			if x <= N:
				c += 1

print(c)

Measured memory_bytes: 3060
n = int(input())
v = list(map(int, input().split()))
ans = 0
for k in range(1, n):
	p, s = k, 0
	while p < n:
		r = n - p - 1
		if r <= k:
			break
		s += v[p] + v[n - 1 - p]
		if r % k != 0 or p < r:
			ans = max(ans, s)
		p += k
print(ans)

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

vector<bool> visited;
vector<vector<int>> graph;

void dfs(int node){
    visited[node] = true;
    for(int i=0; i< graph[node].size(); ++i){
        int nxt = graph[node][i];
        if(!visited[nxt]) dfs(nxt);
    }
}

int solve(int n){
    int c=0;
    for(int i=0; i<n; ++i) visited[i] = false;

    for(int i=0; i<n; ++i){
        if(!visited[i]){
            c++;
            dfs(i);
        }
    }
    return c-1;
}

int main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
    int n, m; cin>> n>> m;
    graph.resize(n); visited.resize(n);

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

    cout<< solve(n)<< endl;

}

Measured memory_bytes: 9444
#include <iostream>
#include <string>
#include <vector>
#include <cmath>
#include <algorithm>

using namespace std;

int main()
{
	long long h, ans=0,count = 1;

	cin >> h;

	while (h > 0)
	{
		h /= 2;
		ans+=count;
		count*=2;
	}

	cout << ans << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define mod 1000000007

ll func(ll b, ll p)
{
    ll i, ans = 1;
    for(i=1;i<=p;i++){
        ans *= b;
        ans %= mod;
    }
    return ans;
}

int main()
{
    ll n,ans;
    scanf("%lld", &n);
    ans = (func(10,n)-(2*func(9,n))+func(8,n))%mod;
    ans = (ans+mod)%mod;
    printf("%lld\n", ans);
    return 0;
}

Measured memory_bytes: 3788
n=int(input())
data=['a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z']
dict={}
for i in range(n):
  a=input()
  for j in data:
    if j not in dict:
      dict[j]=a.count(j)
    else:
      dict[j]=min(dict[j],a.count(j))
ans=[]
for i in dict:
  ans.append(i*dict[i])
print(*ans,sep='')

Measured memory_bytes: 9144
#include <iostream>
#include <vector>
#include<algorithm>
#define mod 998244353;
using namespace std;
typedef long long ll;
int main(void){
    int n, k;
    cin >> n >> k;
    int a[n];
    for(int i =0; i<n; i++){
        cin >> a[i];
    }
    int sum =0;
    for(int i =0; i < n; i++){
        int tmp = min(a[i], k-a[i]);
        
        sum += tmp;
    }
    cout << sum*2 << endl;
}


Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<algorithm>
#define ll long long
using namespace std;
const int N=300010,P=1e9+7;
inline int read(){
	int x=0,f=0,c=getchar();
	for(;c>'9'||c<'0';f=c=='-',c=getchar());
	for(;c>='0'&&c<='9';c=getchar())
	x=(x<<1)+(x<<3)+c-'0';return f?-x:x;
}
inline void write(ll x){
	if(x<0)putchar('-'),x=-x;
	if(x>9)write(x/10);putchar(x%10+'0');
}
int n,a[N];ll ans;
int main(){
	//freopen("1.out","w",stdout);
	int i;
	n=read();n=n+n+n;
	for(i=1;i<=n;i++)a[i]=read();
	sort(a+1,a+n+1);
	for(i=n/3+1;i<n;i+=2)ans+=a[i];
	write(ans);puts("");
	return 0;
}

Measured memory_bytes: 1280
#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_int.hpp>
using bint = boost::multiprecision::cpp_int;

int main()
{
    int N;
    std::cin >> N;
    std::vector<int> ls(N);
    for (int i = 0; i < N; i++) {
        std::cin >> ls.at(i);
    }
    int max = *std::max_element(ls.begin(), ls.end());
    int sum = std::accumulate(ls.begin(), ls.end(), 0);
    sum -= max;
    if (max < sum) {
        std::cout << "Yes" << std::endl;
    } else {
        std::cout << "No" << std::endl;
    }
    return 0;
}

Measured memory_bytes: 256
# include <iostream>
using namespace std ;
int main () {
  int n, value = 0;
  cin >> n;
  int V[2][n];
  for(int i = 0; i<2;i++)
    for(int j = 0; j<n; j++)
      cin >> V[i][j];
  for(int i=0; i<n; i++)
    if(V[0][i] > V[1][i] )
      value += V[0][i]-V[1][i];
  cout<< value;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>//Carefully Crafted by hetp111
using namespace std;
#define int long long
#define double long double
#define all(v) (v).begin(),(v).end()
#define vi vector<int>
#define vvi vector<vi>
#define pii pair<int,int>
#define vii vector<pii>
//#define MOD (1000000007)
#define MOD (998244353)
#define PI acos(-1)
#define eps (1e-8)
#define INF (1e18)
#define FASTER ios_base::sync_with_stdio(0);cin.tie(0)
template<class A,class B>ostream&operator<<(ostream&out,const pair<A,B>&a){return out<<"("<<a.first<<","<<a.second<<")";}
template<class A>ostream&operator<<(ostream&out,const vector<A>&a){for(const A &it:a)out<<it<<" ";return out;}
template<class A,class B>istream&operator>>(istream&in,pair<A,B>&a){return in>>a.first>>a.second;}
template<class A>istream&operator>>(istream&in,vector<A>&a){for(A &i:a)in>>i;return in;}
//ifstream cinn("input.txt");ofstream coutt("output.txt");

signed main(){
    FASTER;
    double lll;cin>>lll;
    lll/=3.0;
    cout<<fixed<<setprecision(10)<<lll*lll*lll;
}

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

class RollingHash:
  def __init__(self, s):
    self.base1 = 1009
    self.base2 = 1007
    self.mod1 = pow(10,9)+7
    self.mod2 = pow(10,9)+9
    self.hash1 = [0 for _ in range(len(s)+1)]
    self.hash2 = [0 for _ in range(len(s)+1)]
    self.pow1 = [1 for _ in range(len(s)+1)]
    self.pow2 = [1 for _ in range(len(s)+1)]
    for i in range(len(s)):
      self.hash1[i+1] = (self.hash1[i] * self.base1 + ord(s[i])) % self.mod1
      self.hash2[i+1] = (self.hash2[i] * self.base2 + ord(s[i])) % self.mod2
      self.pow1[i+1] = self.pow1[i] * self.base1 % self.mod1
      self.pow2[i+1] = self.pow2[i] * self.base2 % self.mod2

  def get(self, l, r):
    t1 = (self.hash1[r] - self.hash1[l] * self.pow1[r-l]) % self.mod1
    t2 = (self.hash2[r] - self.hash2[l] * self.pow2[r-l]) % self.mod2
    return t1, t2

  def add(self, t):
    offset = len(self.hash1)
    self.hash1 += [0 for _ in range(len(t))]
    self.hash2 += [0 for _ in range(len(t))]
    self.pow1 += [0 for _ in range(len(t))]
    self.pow2 += [0 for _ in range(len(t))]
    for i in range(offset, offset + len(t)):
      self.hash1[i] = (self.hash1[i-1] * self.base1 + t[i]) % self.mod1
      self.hash2[i] = (self.hash2[i-1] * self.base2 + t[i]) % self.mod2
      self.pow1[i] = self.pow1[i-1] * self.base1 % self.mod1
      self.pow2[i] = self.pow2[i-1] * self.base2 % self.mod2


class UnionFind:
  def __init__(self, size):
    self.parent = [i for i in range(size)]  # i番目の親ノードを表す
    self.height = [1 for _ in range(size)]  # 高さ
    self.size = [1 for _ in range(size)]  # 集合のサイズ

  def root(self, x):
    """
    xの親ノードを返す
    """
    if self.parent[x] != x:
      self.parent[x] = self.root(self.parent[x])  # 辺の縮約
    return self.parent[x]

  def union(self, x, y):
    """
    xとyの併合
    """
    px, py = self.root(x), self.root(y)
    if px == py:
      return
    if self.height[px] <= self.height[py]:
      self.parent[px] = py
      self.size[py] += self.size[px]
      if self.height[px] == self.height[py]:
        self.height[py] += 1
    else:
      self.parent[py] = px
      self.size[px] += self.size[py]


def main():
  s = input().strip()
  t = input().strip()
  ns = len(s)
  nt = len(t)
  s = s * (len(t) // len(s) + 1) * 2
  srol = RollingHash(s)
  trol = RollingHash(t)
  uni = UnionFind(ns)
  same = [False for _ in range(ns)]
  for i in range(len(s) - len(t) + 1):
    if srol.get(i, i+nt) == trol.get(0, nt):
      same[i % ns] = True

  for i in range(ns):
    if same[i] and same[(i+nt)%ns]:
      if uni.root(i) == uni.root((i+nt)%ns):
        print(-1)
        sys.exit(0)
      else:
        uni.union(i, (i+nt)%ns)

  ans = 0
  for i in range(ns):
    if same[i]:
      ans = max(ans, uni.size[i])

  print(ans)


if __name__ == '__main__':
  main()


Measured memory_bytes: 196128
//By Don4ick 
//#define _GLIBCXX_DEBUG

#include <bits/stdc++.h>

typedef long long ll;
typedef long double ld;
typedef unsigned int ui;

#define forn(i, n) for (int i = 1; i <= n; i++)
#define pb push_back
#define all(x) x.begin(), x.end()
#define y1 qewr1234

const double PI = acos(-1.0);
const int DIR = 4;
const int X[] = {1, 0, -1, 0};
const int Y[] = {0, 1, 0, -1};

using namespace std;

ll f(ll a, ll b)
{
	if (a == 0 || b == 0)
		return 0;
	if (a < b)
	{
		if (b % a)
			return 2ll * a * (b / a) + f(a, b % a);
		return 2ll * a * (b / a) - a;	
	}
	if (a % b)
		return 2ll * b * (a / b) + f(a % b, b);	 
	return 2ll * b * (a / b) - b;
}

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

	//freopen(".in", "r", stdin);
	//freopen(".out", "w", stdout);

	ll n, x;
	cin >> n >> x;	
	cout << n + f(x, n - x) << endl;

	return 0;
}



Measured memory_bytes: 256
def main():

    N, H = map(int, input().split())
    A = []
    B = []
    count = 0
    for _ in range(N):
        a, b = map(int, input().split())
        A.append(a)
        B.append(b)
    B.sort(reverse=True)
    swing = max(A)
    for i in range(N):
        if B[i] > swing:
            H -= B[i]
            count += 1
        if H <= 0:
            print(count)
            exit()
    swingCount = -(-H // swing)
    count += swingCount

    print(count)

if __name__ == "__main__":
    main()

Measured memory_bytes: 11296
#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();
int main()
{
    vector<int> v( 3 );
    for( auto &x : v )
    {
        cin >> x;
    }
    int K;
    cin >> K;
    sort( begin( v ), end( v ) );
    REP( i, K )
    {
        v[ 2 ] *= 2;
    }
    cout << v[ 0 ] + v[ 1 ] + v[ 2 ] << endl;
    return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <array>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <vector>
using namespace std;
using ll=long long int;
using vi=vector<int>;
using vl=vector<ll>;
using vvi=vector<vi>;
using vvl=vector<ll>;
using vs=vector<string>;
constexpr int INF=1<<30;
constexpr ll INFL=1l<<60;
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define FORR(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define RANGE(i,a,b) for(int i=(a);i<=(b);i++)
#define RANGER(i,a,b) for(int i=(b);i>=(a);i--)
#define REP(i,n) FOR(i,0,n)
#define REPR(i,n) FORR(i,0,n)

#define EVALe 1

#ifdef EVAL
#define LOG(i) 0
#else
#define LOG(i) cerr<<#i<<": "<<i<<endl
#endif

void solve(){
	int N,M;
	cin>>N>>M;
	REP(i,max(N,M))cout<<min(N,M);
	cout<<endl;
}

int main(){
	solve();
	return 0;
}

Measured memory_bytes: 256
from sys import stdin
def main():
    #入力
    readline=stdin.readline
    n=int(readline())
    a=list(map(int,readline().split()))
    b=list(map(int,readline().split()))
    for i in range(1,n):
        a[i]+=a[i-1]
    for i in range(n-2,-1,-1):
        b[i]+=b[i+1]

    ans=0
    for i in range(n):
        ans=max(ans,a[i]+b[i])

    print(ans)

if __name__=="__main__":
    main()

Measured memory_bytes: 3064
use std::io;
use std::io::BufRead;

fn main() {
    let stdin = io::stdin();
    let mut stdin = stdin.lock();

    let (n, m) = {
        let mut input = String::new();
        stdin.read_line(&mut input).unwrap();
        let mut input = input.trim().split_whitespace();
        (
            input.next().unwrap().parse::<i32>().unwrap(),
            input.next().unwrap().parse::<i32>().unwrap(),
        )
    };

    let mut a = 1;
    let mut b = n;

    for _ in 0..m {
        let (l, r) = {
            let mut input = String::new();
            stdin.read_line(&mut input).unwrap();
            let mut input = input.trim().split_whitespace();
            (
                input.next().unwrap().parse::<i32>().unwrap(),
                input.next().unwrap().parse::<i32>().unwrap(),
            )
        };

        if a < l { a = l; }
        if b > r { b = r; }

        if a > b {
            println!("0");
            return;
        }
    }

    println!("{}", 1+b-a);

    
}


Measured memory_bytes: 4352
#include<cstdio>
using namespace std;
int n,d1,d2,ans;
int s[610][610];
void run(int d){
	int tmp=0;
	while (!(d%4))d/=4,tmp++;
	if (d&1){
		for (int i=0;i<n*2;i++)
			for (int j=0;j<n*2;j++)
				if ((i>>tmp)+(j>>tmp)&1)s[i][j]=1;
	}else{
		for (int i=0;i<n*2;i++)
			for (int j=0;j<n*2;j++)
				if ((i>>tmp)&1)s[i][j]=1;
	}
}
int main(){
	scanf("%d%d%d",&n,&d1,&d2);
	run(d1),run(d2);
	for (int i=0;i<2*n;i++)
		for (int j=0;j<2*n;j++)
			if (ans<n*n&&!s[i][j])
				printf("%d %d\n",i,j),ans++;
	return 0;
} 

Measured memory_bytes: 2304
#include<iostream>
#include<string>
#include<vector>
#include<iomanip>
#include<algorithm>
#include<queue>
#include<stack>
#include<map>
using namespace std;
#define ll long long
int main(){
    ll N,K,i;
    cin >> N >>K;
    ll h[N];
    ll tmp;
    ll ans=1000000000;
    for(i=0;i<N;i++){
      cin >> h[i];
    }
    sort(h,h+N);
    for(i=0;i<N-K+1;i++){
      tmp=h[i+K-1]-h[i];
      if(tmp<ans)ans=tmp;
    }
    cout << ans;
    return 0;
}


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

void swap(int& x, int& y){int tmp = x; x = y; y = tmp;}

int main(){
  int n, in, x = 0, nums[2][100001] = {0}, maxe = 0, maxo = 0, max2e = 0, max2o = 0, ie, io;
  cin >> n;
  for(int i = 0; i < n; i++){
    cin >> in;
    nums[x][in]++;
    x ^= 1;
  }
  for(int i = 1; i <= 100000; i++){
    if(max2e < nums[0][i]){
      max2e = nums[0][i];
      if(maxe < max2e){
        swap(maxe, max2e);
        ie = i;
      }
    }
    if(max2o < nums[1][i]){
      max2o = nums[1][i];
      if(maxo < max2o){
        swap(maxo, max2o);
        io = i;
      }
    }
  }
  if(ie != io) cout << n - maxe - maxo;
  else cout << n - max((max2e + maxo), (max2o + maxe));
  return 0;
}


Measured memory_bytes: 1024
#include <stdio.h>
int main(void)
{
    int R,G,B,N,i,j,ans=0;
    scanf("%d%d%d%d", &R,&G,&B,&N);
    for(i=0; R*i<=N; i++)
    {
        for(j=0; G*j<=N-R*i; j++)
        {
            if((N-R*i-G*j)%B==0) ans++;
        }
    }
    printf("%d", ans);

    return 0;
}

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

int main() {
    int n, m; cin >> n >> m;
    vector<pair<int, int>> e[n];
    vector<int> d(n, 1e9), p(m), q(m); d[0] = 0;
    vector<bool> used(m, 0);
    for (int i = 0; i < m; i++) {
        int c; cin >> p[i] >> q[i] >> c;
        p[i]--; q[i]--;
        e[p[i]].emplace_back(c, i);
        e[q[i]].emplace_back(c, i);
    }
    for (int i = 0; i < n; i++) {
        sort(e[i].begin(), e[i].end());
    }
    queue<int> qe; qe.emplace(0);
    set<int> vis;
    auto dfs = [&e, &d, &qe, &p, &q, &used, &vis](auto f, int curr, int st, int c) -> void {
        auto iter = lower_bound(e[curr].begin(), e[curr].end(), make_pair(c, 0));
        auto eiter = lower_bound(e[curr].begin(), e[curr].end(), make_pair(c+1, 0));
        while (iter != eiter) {
            auto i = iter->second;
            used[i] = 1;
            auto to = p[i] ^ q[i] ^ curr;
            if (!vis.count(to)) {
                if (d[to] > d[st] + 1) {
                    d[to] = d[st] + 1;
                    qe.emplace(to);
                }
                vis.insert(to);
                f(f, to, st, c);
            }
            iter++;
        }
    };
    while (!qe.empty()) {
        int curr = qe.front(); qe.pop();
        for (auto &edge: e[curr]) {
            if (used[edge.second]) continue;
            used[edge.second] = 1;
            auto to = p[edge.second] ^ q[edge.second] ^ curr;
            dfs(dfs, to, curr, edge.first);
            vis.clear();
        }
    }
    int ans = d[n-1] == 1e9 ? -1 : d[n-1];
    cout << ans << "\n";
}

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

using namespace std;
using llong = long long;
using ldbl = long double;
using P = pair<llong, llong>;

#define ALL(x) x.begin(), x.end()

const llong inf = llong(1e18)+7;
const llong mod = 1e9+7;

int main(){
	llong E, Y;
	cin >> E >> Y;

	switch(E){
		case 0:{
			if(Y <= 1911)
				cout << "M" << Y-1867 << endl;
			else if(Y <= 1925)
				cout << "T" << Y-1911 << endl;
			else if(Y <= 1988)
				cout << "S" << Y-1925 << endl;
			else
				cout << "H" << Y-1988 << endl;
			break;
		}
		case 1:{
			cout << Y + 1867 << endl;
			break;
		}
		case 2:{
			cout << 1911 + Y << endl;
			break;
		}
		case 3:{
			cout << 1925 + Y << endl;
			break;
		}
		case 4:{
			cout << 1988 + Y << endl;
		}
	}

	return 0;
}


Measured memory_bytes: 3088
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define fi first
#define se second
#define dbg(x) cout<<#x" = "<<((x))<<endl
template<class T,class U> ostream& operator<<(ostream& o, const pair<T,U> &p){o<<"("<<p.fi<<","<<p.se<<")";return o;}
template<class T> ostream& operator<<(ostream& o, const vector<T> &v){o<<"[";for(T t:v){o<<t<<",";}o<<"]";return o;}

int main(){
    int w,h,n;
    cin >>w >>h >>n;

    vector<int> p(n);
    rep(i,n) cin >>p[i];

    int ux=1, uy=1;
    int udx=1, udy=0;

    int sx=1, sy=2;
    int sdx=1, sdy=0;

    int ans = 0;
    rep(i,n){
        if(p[i]==0){
            ux += udx;
            uy += udy;

            if(ux==w){
                udx = 0;
                udy = 1;
                if(uy==h){
                    udx = -1;
                    udy = 0;
                }
            }
        }
        else{
            sx += sdx;
            sy += sdy;

            if(sx==w-1){
                sdx = 0;
                sdy = 1;
                if(sy==h-1){
                    sdx = -1;
                    sdy = 0;
                }
            }
        }

        if(ux<0 || sx<0) break;
        if(abs(ux-sx)+abs(uy-sy) == 1) ++ans;
    }
    cout << ans << endl;
    return 0;
}



Measured memory_bytes: 3100
#include <algorithm>
#include <cstdio>
#include <climits>
#include <vector>
using namespace std;

struct UF {
    vector<int> p;
    UF(int n):p(n,-1) {}
    int rt(int x) {return p[x]<0?x:(p[x]=rt(p[x]));}
    bool eq(int x,int y) {return rt(x)==rt(y);}
    int siz(int x) {return -p[rt(x)];}
    void cat(int x, int y) {
        x=rt(x); y=rt(y);
        if(x==y) return;
        if(p[x]<p[y]) swap(x,y);
        p[y]+=p[x];
        p[x]=y;
    }
};

int main() {
    while(true) {
        int r; scanf("%d", &r);
        if(r==0) break;
        static pair<int,int> lv_rm[2][2*500*499+1];
        static int lv_rm_siz[2];
        for(int i = 0; i < 2; i++) {
            int w,h,evx,evy; scanf("%d%d%d%d", &w, &h, &evx, &evy); evx--; evy--;
            int ev = evy*w+evx;
            UF uf(w*h);
            static int lvs[500*500];
            for(int y = 0; y < h; y++) {
                for(int x = 0; x < w; x++) {
                    scanf("%d", lvs+(y*w+x));
                }
            }
            static pair<int,pair<int,int> > edg[2*500*499];
            for(int y = 0; y < h; y++)
                for(int x = 1; x < w; x++)
                    edg[y*(w-1)+(x-1)] = make_pair(max(lvs[y*w+x],lvs[y*w+(x-1)]), make_pair(y*w+x,y*w+(x-1)));
            for(int y = 1; y < h; y++)
                for(int x = 0; x < w; x++)
                    edg[h*(w-1)+(y-1)*w+x] = make_pair(max(lvs[y*w+x],lvs[(y-1)*w+x]), make_pair(y*w+x,(y-1)*w+x));
            sort(edg, edg+h*(w-1)+(h-1)*w);
            lv_rm_siz[i] = 0;
            lv_rm[i][lv_rm_siz[i]++] = make_pair(0,0);
            for(int j = 0; j < h*(w-1)+(h-1)*w; j++) {
                int lv = edg[j].first;
                int p0 = edg[j].second.first;
                int p1 = edg[j].second.second;
                uf.cat(p0,p1);
                lv_rm[i][lv_rm_siz[i]++] = make_pair(lv,uf.siz(ev));
            }
        }
        int min_lv_sum = INT_MAX;
        int i0=0, i1=lv_rm_siz[1]-1;
        while(i0<lv_rm_siz[0] && 0<=i1) {
            int rooms = lv_rm[0][i0].second + lv_rm[1][i1].second;
            if(rooms < r) {
                i0++;
            } else {
                min_lv_sum = min(min_lv_sum, lv_rm[0][i0].first + lv_rm[1][i1].first);
                i1--;
            }
        }
        printf("%d\n", min_lv_sum);
    }
    return 0;
}

Measured memory_bytes: 16000
N,K=map(int,input().split())
X=list(map(int,input().split()))

def culclen(l,r):
  if X[l]*X[r]>=0:
    return max(abs(X[l]),abs(X[r]))
  else:
    ldis=abs(X[l])
    rdis=abs(X[r])
    return min(ldis,rdis)*2+max(ldis,rdis)

ans=10**9
for x in range(len(X)-K+1):
  ans=min(ans,culclen(x,x+K-1))
print(ans)


Measured memory_bytes: 14384
# -*- coding: utf-8 -*-
"""
A - Colorful Slimes 2
https://atcoder.jp/contests/agc026/tasks/agc026_a

"""
import sys


def solve(N, slimes):
    prev = None
    ans = 0
    for s in slimes:
        if s == prev:
            prev = None
            ans += 1
        else:
            prev = s
    return ans


def main(args):
    N = int(input())
    slimes = [int(a) for a in input().split()]
    ans = solve(N, slimes)
    print(ans)


if __name__ == '__main__':
    main(sys.argv[1:])


Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define fi first
#define se second
#define all(container) container.begin(),container.end()
#define fast ios::sync_with_stdio(0); cin.tie(0)
// #ifndef ONLINE_JUDGE
// #include "debug.cpp"
// #endif
#define int long long
const int mod = 1e9+7;  
int power(int a,int b) { if(b==0) return 1; int res = power(a,b/2); if(b&1) return res * res * a; else return res * res; }


int32_t main(){
    
  fast;
  int n; cin >> n;
  set<int> se;
  for(int i=0;i<n;i++){
    int x; cin >> x;
    se.insert(x);
  }

  if(se.size()==n) cout << "YES\n";
  else cout << "NO\n";

  return 0;
}

Measured memory_bytes: 9600
#include<stdio.h>
main()
{
	int n,k,temp,a[50],sum=0,i,j;
	scanf("%d %d",&n,&k);
	for(i=0;i<n;i++)
	{
		scanf("%d",&a[i]);
	}
	for(i=0;i<n;i++)
	{
		for(j=i+1;j<n;j++)
		{
			if(a[i]<a[j])
			{
				temp = a[i];
				a[i] = a[j];
				a[j] = temp;
			}
		}
	}
	for(i=0;i<k;i++)
	{
		sum = sum+a[i];
	}
	printf("%d\n",sum);
	return 0;
}

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

int main()
{
	//std::numeric_limits<int>::max();
	ll n,k,i,num;
	
	cin>>n;
	ll x[n];	
	for(i=0;i<n;i++)
	{
		cin>>x[i];
		num+=x[i];
	}
	ll p=ceil((double)(num)/n);
	ll p1=floor((double)(num)/n);
	ll s=0,s1=0;
	for(i=0;i<n;i++)
	{
		s+=(x[i]-p)*(x[i]-p);
		s1+=(x[i]-p1)*(x[i]-p1);
	}
	cout<<min(s,s1)<<endl;
}

Measured memory_bytes: 256
using System;


namespace JKTX_AOJ2015
{
    class Program
    {
        static void Main(string[] args)
        {
            double r;
            double s, len;

            r = Double.Parse(Console.ReadLine());

            s = r * r * Math.PI;
            len = 2 * r * Math.PI;

            Console.WriteLine("{0} {1}", s, len);
        }
    }
}

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


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

    double n;
    cin >> n;

    double ave = 0;
    vector<double> a(n);
    rep(i,n) {
        cin >> a[i];
        ave += a[i];
    }
    ave /= n;

    int ans = 0;
    double diff = 10000;
    for(int i = 0; i < n; i++){
        if(abs(a[i] - ave) < diff){
            diff = abs(a[i] - ave);
            ans = i;
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
package main

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

func add(cnt map[int]int, v int) {
	if _, ok := cnt[v]; !ok {
		cnt[v] = 1
		return
	}
	cnt[v]++
}

func main() {
	sc := NewScanner(os.Stdin)
	N := sc.NextInt()
	A := make([]int, N)
	for i := 0; i < N; i++ {
		A[i] = sc.NextInt()
	}
	l := make([]int, N)
	r := make([]int, N)
	l[0] = A[0]
	r[N-1] = A[N-1]
	for i := 1; i < N; i++ {
		l[i] = gcd(l[i-1], A[i])
	}
	for i := N - 2; i >= 0; i-- {
		r[i] = gcd(r[i+1], A[i])
	}
	ans := max(l[N-2], r[1])
	for i := 1; i < N-1; i++ {
		ans = max(ans, gcd(l[i-1], r[i+1]))
	}
	fmt.Println(ans)
}

func vmin(v []int) int {
	mn := math.MaxInt32
	for i := 0; i < len(v); i++ {
		mn = min(mn, v[i])
	}
	return mn
}

func gcd(x, y int) int {
	if y > 0 {
		return gcd(y, x%y)
	}
	return x
}

func lcm(x, y int) int {
	return x / gcd(x, y) * y
}

func max64(x, y int64) int64 {
	if x > y {
		return x
	}
	return y
}

func max(x, y int) int {
	if x > y {
		return x
	}
	return y
}

func min(x, y int) int {
	if x < y {
		return x
	}
	return y
}

// scanner
type Scanner struct {
	r   *bufio.Reader
	buf []byte
	p   int
}

func NewScanner(r io.Reader) *Scanner {
	rdr := bufio.NewReaderSize(r, 1024)
	return &Scanner{r: rdr}
}

func (s *Scanner) ReadLine() {
	s.buf = make([]byte, 0)
	for {
		line, isp, err := s.r.ReadLine()
		if err != nil {
			os.Exit(1)
		}
		s.buf = append(s.buf, line...)
		if !isp {
			break
		}
	}
}

func (s *Scanner) NextInt64() int64 {
	i, err := strconv.ParseInt(s.Next(), 10, 64)
	if err != nil {
		os.Exit(1)
	}
	return i
}

func (s *Scanner) NextInt() int {
	i, err := strconv.Atoi(s.Next())
	if err != nil {
		os.Exit(1)
	}
	return i
}

func (s *Scanner) NextFloat64() float64 {
	i, err := strconv.ParseFloat(s.Next(), 64)
	if err != nil {
		os.Exit(1)
	}
	return i
}

func (s *Scanner) Next() string {
	s.Pre()
	start := s.p
	for ; s.p < len(s.buf); s.p++ {
		if s.buf[s.p] == ' ' {
			break
		}
	}
	next := string(s.buf[start:s.p])
	s.p++
	return next
}

func (s *Scanner) Pre() {
	if s.p >= len(s.buf) {
		s.ReadLine()
		s.p = 0
	}
}


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

int main(){
    int n,k,x,sum=0;
    cin >> n >> k;
    for(int i=0;i<n;i++){
        cin >> x;
        sum += min(x,k-x);
    }
    cout << sum*2 << endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <cstring>
#include <fstream>

using namespace std;


//typedef long long ll;
int dy[201];
int dx[201];
int dp[2][1<<12];
char field[101][101];
int dmg[201];
int stepDmg[2001];
int portions[101];
int inithp;
int maxhp;
int r,c;
int step;
int S,P,T;

const int INF=1000000000LL;

void input(){
	cin>>r>>c;
	for(int i=0;i<r;i++)for(int j=0;j<c;j++)cin>>field[i][j];
	cin>>T;
	for(int i=0;i<T;i++){
		char ch;
		int m;
		cin>>ch>>m;
		dmg[ch]=m;
	}
	cin>>S;
	int cx=0;
	int cy=0;
	for(int i=0;i<S;i++){
		char ch;
		int quan;
		cin>>ch>>quan;
		for(int j=0;j<quan;j++){
			int ny=cy+dy[ch];
			int nx=cx+dx[ch];
			stepDmg[step]=dmg[field[ny][nx]];
			step++;
			cx=nx;
			cy=ny;
		}
	}
	cin>>P;
	for(int i=0;i<P;i++)cin>>portions[i];
}

int main(){
	dy['U']=-1;
	dx['U']=0;
	dy['R']=0;
	dx['R']=1;
	dy['D']=1;
	dx['D']=0;
	dy['L']=0;
	dx['L']=-1;
	while(cin>>inithp>>maxhp&&(inithp|maxhp)){
		step=0;
		input();
		// startn_ÅÍ,cÁ½¨ð·×Äg¤
		for(int j=0;j<(1<<P);j++){
			int sum=0;
			for(int i=0;i<P;i++)if(!((j>>i)&1))sum+=portions[i];
			dp[0][j]=min(maxhp,sum+inithp);
		}
		for(int i=0;i<step;i++){
			int nxt=(i+1)%2;
			int cur=i%2;
			for(int j=(1<<P)-1;j>=0;j--){
				int res=-INF;
				int s=j;
				int pos=i;
				// Ü¾gpµÄ¢È¢portionðgp
				for(int k=0;k<P;k++)
					if(!((s>>k)&1))
						res=max(res,min(dp[nxt][s|(1<<k)]+portions[k],maxhp));
				// ÌêÖ
				res=max(res,dp[cur][s]-stepDmg[pos]);
				if(res<=0)res=-INF;
				dp[nxt][s]=min(maxhp,res);
			}
		}
		bool ok=false;
		for(int j=0;j<(1<<P);j++)if(dp[step%2][j]>0)ok=true;
		if(ok)cout<<"YES"<<endl;
		else cout<<"NO"<<endl;
	}
	return 0;
}

Measured memory_bytes: 904
#include <stdio.h>

int main() {

	int n,i,S[13],H[13],C[13],D[13],number;

	char x,a;

	for (i = 0; i < 13; i++) {
		S[i] = H[i] = C[i] = D[i] = 0;
	}

	scanf("%d", &n);

	for (i = 0; i < n; i++) {
		scanf("%c%c%d",&a, &x, &number);

		if (x == 'S') {
			S[number - 1] = 1;
		}
		else if (x == 'H') {
			H[number - 1] = 1;
		}
		else if (x == 'C') {
			C[number - 1] = 1;
		}
		else {
			D[number - 1] = 1;
		}
	}


	for (i = 0; i < 13; i++) {
		if (S[i] == 0) {
			printf("S %d\n", i + 1);
		}
	}
	for (i = 0; i < 13; i++) {
		if (H[i] == 0) {
			printf("H %d\n", i+1);
		}
	}
	for (i = 0; i < 13; i++) {
		if (C[i] == 0) {
			printf("C %d\n", i+1);
		}
	}
	for (i = 0; i < 13; i++) {
		if (D[i] == 0) {
			printf("D %d\n", i+1);
		}
	}
	
	return 0;

}


Measured memory_bytes: 2056
// +build ignore
package main

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

// I/O
type Scanner struct {
	sc *bufio.Scanner
}

func NewScanner() *Scanner {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, 1024), int(1e+9))
	return &Scanner{sc}
}

func (s *Scanner) nextStr() string {
	s.sc.Scan()
	return s.sc.Text()
}

func (s *Scanner) nextInt() int {
	i, e := strconv.Atoi(s.nextStr())
	if e != nil {
		panic(e)
	}
	return i
}

func (s *Scanner) nextFloat() float64 {
	f, e := strconv.ParseFloat(s.nextStr(), 64)
	if e != nil {
		panic(e)
	}
	return f
}

func (s *Scanner) nextRuneSlice() []byte {
	return []byte(s.nextStr())
}

func (s *Scanner) nextIntSlice(n int) []int {
	res := make([]int, n)
	for i := 0; i < n; i++ {
		res[i] = s.nextInt()
	}
	return res
}

func (s *Scanner) nextFloatSlice(n int) []float64 {
	res := make([]float64, n)
	for i := 0; i < n; i++ {
		res[i] = s.nextFloat()
	}
	return res
}

func gcd(x, y int) int {
	if x%y != 0 {
		return gcd(y, x%y)
	}
	return y
}

func run(input io.Reader, output io.Writer) int {
	sc := NewScanner()
	A := sc.nextFloat()
	B := sc.nextFloat()
	H := sc.nextFloat()
	M := sc.nextFloat()

	radA := float64(H*60+M) * 0.5
	radB := float64(M * 6)
	var radAB float64
	if radA > radB {
		radAB = radA - radB
	} else {
		radAB = radB - radA
	}

	if radAB > 180 {
		radAB = 360 - radAB
	}
	aa := float64(A*A+B*B) - float64(2*A*B)*math.Cos(radAB*math.Pi/180.0)

	fmt.Printf("%0.15f", math.Sqrt(aa))

	return 0
}

func main() {
	os.Exit(run(os.Stdin, os.Stdout))
}


Measured memory_bytes: 1724
#include <iostream>
#include <string>
#include <cstdlib>
#include <cstdio>
#include <queue>
#include <stack>
#include <list>
#include <utility>
#include <vector>
#include <set>
#include <algorithm>
#include <cmath>
#include <climits>
#include <map>
#include <unordered_map>
#include <string.h>
#include<iomanip>
#include <iterator>
#include <locale>

#define all(a) a.begin(),a.end()
#define VV(T) vector<vector< T > >
#define rep(i,N) for(int i = 0; i <N; i++)
#define repsg(i,s,g) for(int i = s; i <g; i++)
#define name(x) #x
using namespace std;


const int INF = 10000000;
const long long INFL = (1LL<<40);
const int MOD = pow(10,9)+7;
int dy[]={0, 0, 1, -1, 0};
int dx[]={1, -1, 0, 0, 0};

typedef long long ll,LL;
typedef vector<int> vint;
typedef vector<vector<int> > vvint;
typedef vector<long long> vll, vLL;
typedef vector<vector<long long> > vvll, vvLL;
typedef pair<int,int> pii;
typedef pair<LL, LL> pLL;


// vector入力
template<typename T>
istream& operator >> (istream& is, vector<T>& vec){
    for(T& x: vec) is >> x;
    return is;
}
// vector出力
template<typename T>
ostream& operator << (ostream& os, vector<T>& vec){
    for(int i=0; i<vec.size(); i++){
        os << vec[i] << ( i+1 == vec.size() ? "" : " " );
    }
    return os;
}

template< typename T >
struct edge{
    int src, to;T cost;
    edge(int to,T cost) :src(-1),to(to),cost(cost){}
    edge(int src, int to, T cost) :src(src),to(to),cost(cost){}edge
    &operator=(const int &x){
        to =x;
        return *this;
    }
    operator int() const{ return to;}
};

double dist (double a, double b,  double c, double d){
    
    return sqrt((a-c)*(a-c) + (b-d)*(b-d));
    
}

bool check(int x,int y,vector<string> a,vector<string> b ){
    for(auto i = 0; i<b.size();i++){
        for(auto j =0; j<b.size();j++){
            if(a[x+i][y+j]!= b[i][j]) return false;
        }
    }
    return true;
}

int main() {

    int n;cin>>n;vector<int> A(n,0);cin>>A;
    int min2 = INT_MAX;
    
    for(auto a:A){
        int temp = 0;
        
        while(a%2 == 0){
            temp++;a/=2;
        }
        min2 = min(min2,temp);
    }
    cout<<min2<<endl;
    
    
    return 0;
}







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

using namespace std;
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define RFOR(i, a, b) for (int i = (b)-1; i >= (a); i--)
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep1(i, n) for (int i = 1; i < (n); i++)
#define rrep(i, n) for (int i = (n)-1; i >= 0; i--)
#define all(i) (i).begin(), (i).end()
#define rall(i) (i).begin(), (i).end(), greater<int>()
#define int long long
#define elif else if
#define eb emplace_back
#define pb push_back
#define mp make_pair
#define fst first
#define sec second
#define mod 1000000007
#define INF 10e10
template <typename T>

void print(T x)
{
	std::cout << x << " ";
}
template <typename T>

void println(T x)
{
	std::cout << x << "\n";
}

signed main(void) {
	map<string, int>mp;
	int N, M;
	cin >> N;
	string str;
	rep(i, N) {
		cin >> str;
		mp[str]++;
	}
	cin >> M;
	rep(i, M) {
		cin >> str;
		mp[str]--;
	}
	int max = 0;
	auto begin = mp.begin(), end = mp.end();
	for (auto iter = begin; iter != end; iter++) {
		// first: key, second: value
		if (max < iter->second)max = iter->second;
	}
	print(max);
}

Measured memory_bytes: 256
from operator import itemgetter
n,m=map(int,input().split())
a=[""]*m
b=[""]*m
for i in range(m):
    x,l=map(int,input().split())
    a[i]=x*10+5
    b[i]=l*10-5
st=sorted([(a[i],b[i]) for i in range(m)], key=itemgetter(1))
ans=0
last=0
last=-float("inf")
for i in range(m):
    if last<st[i][0]:
        ans+=1
        last=st[i][1]
print(ans)

Measured memory_bytes: 20600
#include <iostream>
#include <vector>
#include <math.h>
#include <algorithm>
using namespace std;

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

	int num = 2 * D + 1;

	int out;
	if (N % num == 0) {
		out = N / num;
	}
	else {
		out = (int)(N / num) + 1;
	}

	cout << out << endl;

	return 0;
}


Measured memory_bytes: 256
//============================================================================
// Name        : atcoder.cpp
// Author      :
// Version     :
// Copyright   : Your copyright notice
// Description : Hello World in C++, Ansi-style
//============================================================================

#include <iostream>
using namespace std;


int main() {
	long long  A,B;
	cin>>A>>B;
	long long ans=1;
	for(int i=0;i<A;++i)ans*=100;
	if(B==100)B=101;
	cout<<ans*B<<endl;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std; 
string s;
int cnt;
int main() {
    //freopen("input.txt","r",stdin);
	//freopen("output.txt","w",stdout);
	cin>>s;
	for(int i=0;i<s.size();i++)cnt+=s[i]-'0';
	cnt=cnt%9;
	if(cnt==0)cout<<"Yes"<<endl;
	else cout<<"No"<<endl;
    return 0; 
}/*
*/

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

int main() {
	int n;
	while (cin >> n, n) {
		int cnt = 0;
		for (; n != 1; cnt++) {
			if (n & 1)n = n * 3 + 1;
			else n /= 2;
		}
		cout << cnt << endl;
	}
}

Measured memory_bytes: 3064
//BROWNIE TK

#include <bits/stdc++.h>
typedef long long int lli;
typedef unsigned long long int ulli;
typedef long double ldb;

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;

#define pb push_back
#define popb pop_back()
#define pf push_front
#define popf pop_front()
#define si size()
#define be begin()
#define en end()
#define all(v) v.be, v.en
#define le length()
#define mp make_pair
#define mt make_tuple
#define F first
#define S second

#define forz(i, n) for (int i = 0; i < n; i++)
#define forzm(i, m, n) for (int i = m; i < n; i++)
#define rforz(i, n) for (int i = n - 1; i >= 0; i--)
#define rforzm(i, m, n) for (int i = n - 1; i >= m; i--)
#define deci(n) fixed << setprecision(n)
#define high(n) __builtin_popcount(n)
#define parity(n) __builtin_parity(n)
#define ctz(n) __builtin_ctz(n)
#define lb lower_bound
#define ub upper_bound
#define er equal_range
#define maxe *max_element
#define mine *min_element
#define mod 1000000007
#define mod2 998244353
#define kira ios::sync_with_stdio(0), cin.tie(0), cout.tie(0)

#define endl "\n"
#define p0(a) cout << a << " "
#define p1(a) cout << a << endl
#define p2(a, b) cout << a << " " << b << endl
#define p3(a, b, c) cout << a << " " << b << " " << c << endl
#define p4(a, b, c, d) cout << a << " " << b << " " << c << " " << d << endl

#define oset tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update>
#define osetlli tree<lli, null_type, less<lli>, rb_tree_tag, tree_order_statistics_node_update>
//member functions :
//1. order_of_key(k) : number of elements strictly lesser than k
//2. find_by_order(k) : k-th element in the set
#define ofk order_of_key
#define fbo find_by_order
using namespace std;

/*STD fucntions*/
lli power(lli x, lli y, lli p)
{
    lli res = 1;
    x = x % p;
    while (y > 0)
    {
        if (y & 1)
            res = (res * x) % p;
        //y must be even now
        y = y >> 1; //y=y/2
        x = (x * x) % p;
    }
    return res;
}
lli gcd(lli a, lli b)
{
    if (b == 0)
        return a;
    return gcd(b, a % b);
}
lli lcm(lli a, lli b)
{
    return a * b / gcd(a, b);
}
lli modi(lli a, lli m)
{
    // fermat little thm where m is prime
    return power(a, m - 2, m);
}
/*CODE BEGINS*/
int main()
{
    kira;
    lli a;
    string s;
    cin>>a;
    cin>>s;
    if(a>=3200)cout<<s;
    else cout<<"red";
    return 0;
}

Measured memory_bytes: 256
#include "iostream"
#include "vector"
#include "string"
#include "algorithm"
#include "math.h"
using namespace std;

int main()
{
  int n;
  cin >> n;
  int ans = 0;
  while (n != 0)
  {
    if (n % 10 == 2)
    {
      ans++;
    }
    n /= 10;
  }
  cout << ans << "\n";
}

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

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

  multiset<char> Cube;
  for (int i = 0; i < S.size(); i++) Cube.insert(S.at(i));
  cout << min(Cube.count('0'), Cube.count('1')) * 2 << endl;
}

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

int main(){
	int n;
	while(cin >> n, n){
		int cnt=0;
		n = 1000 - n;
		while(n >= 500){
			n -= 500;
			cnt++;
		}
		while(n >= 100){
			n -= 100;
			cnt++;
		}
		while(n >= 50){
			n -= 50;
			cnt++;
		}
		while(n >= 10){
			n -= 10;
			cnt++;
		}
		while(n >= 5){
			n -= 5;
			cnt++;
		}
		while(n >= 1){
			n -= 1;
			cnt++;
		}
		cout << cnt << endl;
	}
}

Measured memory_bytes: 1160
#include <bits/stdc++.h>
#include <sys/time.h>
using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl
template<class T1, class T2> ostream& operator << (ostream &s, pair<T1,T2> P)
{ return s << '<' << P.first << ", " << P.second << '>'; }
template<class T> ostream& operator << (ostream &s, vector<T> P)
{ for (int i = 0; i < P.size(); ++i) { if (i > 0) { s << " "; } s << P[i]; } return s; }
template<class T> ostream& operator << (ostream &s, vector<vector<T> > P)
{ for (int i = 0; i < P.size(); ++i) { s << endl << P[i]; } return s << endl; }
template<class T> ostream& operator << (ostream &s, set<T> P)
{ for(auto it : P) { s << "<" << it << "> "; } return s << endl; }
template<class T1, class T2> ostream& operator << (ostream &s, map<T1,T2> P)
{ for(auto it : P) { s << "<" << it.first << "->" << it.second << "> "; } return s << endl; }


long long A, B, C, K;
long long solve() {
    if (A + B >= K) return min(A, K);
    else return A - (K - A - B);
}

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

    while (cin >> A >> B >> C >> K) {
        cout << solve() << endl;
    }
}


















Measured memory_bytes: 3640