akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
int findMin(vector<int> nums,int n);
int main()
{
  //  freopen("test.txt","r",stdin);
    int k,t;
    cin>>k>>t;
    vector<int> nums(t);
    for(int i=0;i<t;i++)
    {
        cin>>nums[i];
    }
    int res = findMin(nums,nums.size());
    if(res == 0)
    {
        cout<<res<<endl;
    }else
    {
        cout<<res-1<<endl;
    }

    return 0;
}
int findMin(vector<int> nums,int n)
{
    int sum  = 0 ;
    for(int i=0;i<n;i++)
    {
        sum+=nums[i];
    }
    bool dp[n+1][sum+1];
    for(int i=0;i<=n;i++)
    {
        dp[i][0]=true;
    }
    for(int i=1;i<=sum;i++)
    {
        dp[0][i]=false;
    }
    for(int i=1;i<=n;i++)
    {
        for(int j=1;j<=sum;j++)
        {
            dp[i][j]=dp[i-1][j];
            if(nums[i-1]<=j)
            {
                dp[i][j]|=dp[i-1][j-nums[i-1]];
            }
        }
    }
    int diff = INT_MAX;
    for(int i=sum/2;i>=0;i--)
    {
        if(dp[n][i]==true)
        {
            diff = sum -2*i;
            break;
        }
    }
    return diff;
}


Measured memory_bytes: 1280
#1. input
# set N<=M 
N, M = map(int, input().split())

if N>M:
    temp = N
    N = M
    M = temp

#2. N=1 -> M-2 (if M=1, ans=1)
#    N=2 -> ans = 0
#    N>3 -> ans = NM - {2(M+N)-4}
if N == 1:
    if M == 1:
        ans = 1
    else:
        ans = M-2
elif N == 2:
    ans = 0
else:
    ans = M*N - 2*(M+N) +4
    
print(ans)
            

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define all(x) (x).begin(),(x).end()
const int mod=998244353,MAX=100003,INF=1<<30;

int par[MAX],size[MAX];

void init(int n){
    for(int i=0;i<n;i++){
        par[i]=i;
        size[i]=1;
    }
}

int root(int a){
    if(par[a]==a) return a;
    else return par[a]=root(par[a]);
}

void unite(int a,int b){
    if(root(a)!=root(b)){
        size[root(a)]+=size[root(b)];
        par[root(b)]=root(a);
    }
}

bool check(int a,int b){
    return root(a)==root(b);
}


int main(){
    
    std::ifstream in("text.txt");
    std::cin.rdbuf(in.rdbuf());
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    ll N,M,Q;cin>>N>>M>>Q;
    init(N);
    vector<ll> A(Q),B(Q),C(Q);
    bool app1=false;
    set<ll> SE,T;
    
    for(int i=0;i<Q;i++){
        cin>>A[i]>>B[i]>>C[i];
        if(C[i]==0){
            unite(A[i],B[i]);
            SE.insert(A[i]);
            SE.insert(B[i]);
            
            //use.insert(A[i]);
            //use.insert(B[i]);
        }
    }
    bool ok=true;
    
    for(int i=0;i<Q;i++){
        if(C[i]==1){
            app1=true;
            if(check(A[i],B[i])) ok=false;
            
            //use.insert(A[i]);
            //use.insert(B[i]);
        }
    }
    if(app1&&N-1==M) ok=false;
    
    if(app1&&SE.size()==N) ok=false;
    
    ll rem=N-ll(SE.size());
    
    for(int i=0;i<N;i++){
        if(size[root(i)]>1) T.insert(root(i));
    }
    
    if(M>rem*(rem-1)/2+ll(T.size())*rem+ll(SE.size())-ll(T.size())+ll(T.size())*ll(T.size()-1)/2) ok=false;
    
    if(!ok) cout<<"No"<<endl;
    else cout<<"Yes"<<endl;
    
}




Measured memory_bytes: 8064
N = int(input())

T, A = map(int, input().split())
H = list(map(int, input().split()))

ans = 0
n = 0
for i, item in enumerate(H):
    if i == 0:
        ans = i + 1
        n = abs(T - item*0.006 - A)
    else:
        if abs(T - item*0.006 - A) < n:
            ans = i + 1
            n = abs(T - item*0.006 - A)

print(ans)

Measured memory_bytes: 3064
#include<cstdio>
#include<cctype>
#include<algorithm>
#include<cstring>
#include<vector>
//#include<ctime>
#define rg register
typedef long long ll;
template <typename T> inline T max(const T a,const T b){return a>b?a:b;}
template <typename T> inline T min(const T a,const T b){return a<b?a:b;}
template <typename T> inline void mind(T&a,const T b){a=a<b?a:b;}
template <typename T> inline void maxd(T&a,const T b){a=a>b?a:b;}
template <typename T> inline T abs(const T a){return a>0?a:-a;}
template <typename T> inline void swap(T&a,T&b){T c=a;a=b;b=c;}
//template <typename T> inline void swap(T*a,T*b){T c=a;a=b;b=c;}
template <typename T> inline T gcd(const T a,const T b){if(!b)return a;return gcd(b,a%b);}
template <typename T> inline T lcm(const T a,const T b){return a/gcd(a,b)*b;}
template <typename T> inline T square(const T x){return x*x;};
template <typename T> inline void read(T&x)
{
	char cu=getchar();x=0;bool fla=0;
	while(!isdigit(cu)){if(cu=='-')fla=1;cu=getchar();}
	while(isdigit(cu))x=x*10+cu-'0',cu=getchar();
	if(fla)x=-x;
}
template <typename T> inline void printe(const T x)
{
	if(x>=10)printe(x/10);
	putchar(x%10+'0');
}
template <typename T> inline void print(const T x)
{
	if(x<0)putchar('-'),printe(-x);
	else printe(x);
}
int n;
ll sum[11][11];
ll ans;
int main()
{
	read(n);
	for(rg int i=1;i<=n;i++)
	{
		int A=i,B=i%10;
		while(A>=10)A/=10;
		sum[A][B]++;
	}
	for(rg int i=0;i<=9;i++)
		for(rg int j=0;j<=9;j++)
		{
		//	if(i>j)continue;
			ans+=sum[i][j]*sum[j][i];
		}
	print(ans);
	return 0;
}

Measured memory_bytes: 128
import java.io.IOException;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) throws IOException {
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int b = sc.nextInt();
		int c = sc.nextInt();
		sc.close();

		if (a<b & b<c) {
			System.out.println("Yes");
		}else {
			System.out.println("No");
		}



	}

}



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

using namespace std;

struct edge {
    int to;
};

int N;

vector<vector<edge>> v;

bool search(vector<int>& p, int par) {
    int cur = p.back();
    if(cur == N-1) return true;
    for(auto& it : v[cur]){
        if(it.to == par) continue;
        p.push_back(it.to);
        if(search(p, cur)) return true;
        p.pop_back();
    }
    return false;
}

int count(int cur, int par, int wh) {
    if(cur == wh) return 0;
    int a = 0;
    for(auto& it : v[cur]){
        if(it.to == par) continue;
        a += count(it.to, cur, wh);
    }
    return a+1;
}

int main(void){
    cin >> N;
    v.resize(N);
    for(int i=0; i<N-1;i++){
        int a,b;
        cin >> a >> b;
        a--;b--;
        v[a].push_back(edge{b});
        v[b].push_back(edge{a});
    }
    // search a path from 0 to N-1
    vector<int> path;
    path.push_back(0);
    search(path, -1);
    int wh = (path.size()+1)/2; // bound
    int f = count(0, -1, path[wh]);
    int s = N-f;
    cout << (f > s ? "Fennec" : "Snuke") << endl;
    return 0;
}

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

#include <boost/multiprecision/cpp_int.hpp>

// increment
#define rep_n(_1, _2, _3, NAME, ...) NAME
#define rep_2(i, n) for (int(i) = 0; (i) < (int)(n); ++(i))
#define rep_3(i, initial, n) \
  for (int(i) = (int)(initial); (i) < (int)(n); ++(i))
#define rep(...) rep_n(__VA_ARGS__, rep_3, rep_2, rep_1)(__VA_ARGS__)
// decrement
#define rep_r_n(_1, _2, _3, NAME, ...) NAME
#define rep_r_2(i, n) for (int(i) = (int)(n); (i) > 0; (i)--)
#define rep_r_3(i, initial, n) \
  for (int(i) = (int)(initial); (i) > (int)(n); (i)--)
#define rep_r(...) rep_r_n(__VA_ARGS__, rep_r_3, rep_r_2)(__VA_ARGS__)
// define type definition
using namespace std;
typedef long long ll;
using mpint = boost::multiprecision::cpp_int;  // 多倍長整数（任意精度）
typedef pair<int, int> P;

// define construct variable
const double EPS = numeric_limits<double>::epsilon();
// 10^9 + 7
const ll MOD = ll(1e9) + 7;
const ll INF = ll(1e10);
const string ALPHABET = "abcdefghijklmnopqrstuvwxyz";
const double PI = acos(-1);

// define methods
// 最大公約数
ll gcd(const ll a, const ll b) { return b ? gcd(b, a % b) : a; }
// 最小公倍数
ll lcm(const ll a, const ll b) { return a / gcd(a, b) * b; }
// char -> int
int ctoi(char c) { return (int)(c - '0'); }
// 素因数分解
vector<pair<ll, ll>> prime_factorize(ll n) {
  vector<pair<ll, ll>> p;
  for (ll i = 2; i * i <= n; i++) {
    if ((n % i) != 0) continue;
    pair<ll, ll> a = make_pair(i, 0);
    while ((n % i) == 0) {
      n /= i;
      a.second += 1;
    }
    p.push_back(a);
  }

  if (n != 1) p.push_back(make_pair(n, 1));
  return p;
}
// 組み合わせの整合性を保つ（後ほど解析する）
ll modinv(ll a) {
  ll b = MOD, u = 1, v = 0;
  while (b) {
    ll t = a / b;
    a -= t * b;
    swap(a, b);
    u -= t * v;
    swap(u, v);
  }
  u %= MOD;
  if (u < 0) {
    u += MOD;
  }
  return u;
}
// 順列
ll permutation(const ll n, const ll m) {
  ll result = 1;
  for (ll i = n; i > n - m; i--) {
    result = (result * i) % MOD;
  }
  return result;
}

// 繰り返し n 乗法
ll repeat_square(const ll n, const ll x) {
  if (x == 0) return 1;
  ll res = repeat_square(n, x / 2);
  res = res * res % MOD;
  if ((x % 2) == 1) res = res * n % MOD;
  return res;
}
// 組み合わせ nCm
ll combination(ll n, ll m) {
  ll p = permutation(n, m);
  ll div = 1;
  for (ll i = 2; i <= m; i++) {
    div = (div * i) % MOD;
  }
  return (p * modinv(div)) % MOD;
}

// アルファベットの取得
string get_alphabet(ll n) {
  n--;
  return string(1, 'a' + (n % 26));
}

string to_str(ll n) {
  return to_string(n);
}

int main() {
  int N, T, A;
  cin >> N >> T >> A;

  vector<double> H(N);
  rep(i, N) {
    double h;
    cin >> h;
    H[i] = (double)T - h * 0.006;
  }

  double diff = double(1e5);
  int ans = 0;
  rep(i, N) {
    double temp = abs(A - H[i]);
    if (temp < diff) {
      diff = temp;
      ans = i+1;
    }
  }

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


Measured memory_bytes: 3756
n=gets.chomp.to_i
max_root=Math.sqrt(n).to_i
prime=Array.new
m=n
k=n
i=2
while i <= max_root
	if n%i==0
		prime << i
		n=n/i
	elsif i==2
		i+=1
	else
		i+=2
	end
end
if m==n || n!=1
	prime << n
end

prime.uniq!

j=0
while j <= prime.length-1
	k= k-k/prime[j]
	j+=1
end
puts k

Measured memory_bytes: 8628
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define pb push_back
#define mp make_pair
#define v vector
#define len length()
#define fi first
#define se second
#define mt make_tuple
#define repr(i,n) for(ll i=n-1;i>=0;i--)
#define rep(i,n) for(ll i=0;i<n;i++)
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
const int M = 1e9+7;
int ll_max=1e6;
v<ll> fact;
//factorial
void factorial(ll n)
{
    fact[0] = 1;
    for (ll i = 1; i <=n; i++)
    {
        fact[i] = i * fact[i - 1];
        fact[i] %= M;
    }
}
// modular exponentiation 
ll binpow(ll val, ll deg)
{
    if (!deg)
        return 1 % M;
    if (deg & 1)
        return binpow(val, deg - 1) * val % M;
    ll res = binpow(val, deg >> 1);
    return (res * res) % M;
}
//combination
ll combination(ll n, ll i)
{
    ll res = fact[n]; 
    ll div = fact[n - i] * fact[i];
    div %= M;
    // using fermat little theorum
    div = binpow(div, M - 2); // modular inverse  
    return (res * div) % M; 
}
int main() {
	// your code goes here
	IOS;
	int64_t n,m,i;
	int64_t j,t,x,y,z,k,d;
	cin>>n;
	v<ll> numoffactors(n+1,2);
	numoffactors[1]=1;
	
	for (i = 2; i <= n; i++) {
      
        for (j = i*2; j <= n; j += i)
             numoffactors[j]++;
      }
      int64_t sum=0;
      for(i=1;i<=n;i++){
            sum+=i*numoffactors[i];
      }
      cout<<sum;
	return 0;
}

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

int main(){
    long n;
    long long k;
    long c = 1;
    cin >> n >> k;
    vector<long> a(n),e(n),f(n,0);
    for(long i = 0; i < n; ++i){
        cin >> a[i];
    }
    
    long p = 0;
    long q;
    e[0] = 1;
    f[0] = 1;
    for(long i = 0; i < n; ++i){
        q = a[p] - 1;
        if(f[q] == 1){
            break;
        }
        f[q] = 1;
        e[c] = a[p];
        p = q;
        ++c;
    }
    vector<long>::iterator itr = find(e.begin(),e.end(),(q+1));
    long r = distance(e.begin(),itr);
    if(k >= c){
        k -= r;
        c -= r;
        k %= c;
        k += r;
    }
    cout << e[k] << endl;
    return 0;
}

Measured memory_bytes: 7988
#include<iostream>
#include<cmath>
#include<stdio.h>
#include <ctype.h>
#include<iomanip>
#include<algorithm>
#include<string>
#include<stack>
#include<set>
#include<map>
#include<deque> //<< fixed << setprecision()
#include<queue> //priority_queue
#include<vector>
#define em3 ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define iof freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);

using namespace std;
#define f first
#define s second
#define X real()
#define Y imag()
#define cross(a, b) ((conj(a) * (b)).Y)
#define dot(a, b) ((conj(a) * (b)).X)
#define inFile(t) freopen((t),"r",stdin)
#define outFile(t) freopen((t),"w",stdout)
#define all(v) (v).begin(),(v).end()
#define allr(v) (v).rbegin(),(v).rend()
#define EPS 1e-7
long long mod = 1e9 + 7;
const int N = 1e4 + 5;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
const double pi = acos(-1);
//typedef complex <ll> point;
typedef tuple<int, int, int> line;
//typedef vector<point> polygon;


int main()
{

	string s;
	cin >> s;
	if (s == "Sunny")
		cout << "Cloudy";
	else if (s == "Cloudy")
		cout << "Rainy";
	else
		cout << "Sunny";

}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <cstdio>
#include <cmath>
#include <tuple>
#include <iomanip>
#include <numeric>
#include <unordered_map>
#include <sstream>   
#include<limits.h>
using namespace std;
#define i64  long long
#define lint long long
 
#define I32_MAX 2147483647
#define I64_MAX 9223372036854775807
#define MOD_Q 1e9 + 7
#define MOD_A 998244353

 #define int long long


int MIN = I64_MAX;

void solve()
{

  int N;
  cin>>N;
  cout<<N*N<<endl;
  
  return;  
}
 
int32_t main(int32_t argc, const char *argv[])
{
 
  solve();
 
  return 0;
}

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

long long int n,a[500000],m,b[500000],c[500000],ko,ans;
vector<pair<int,int> >br;

int  main()
{
    cin>>n>>m;
    for(int i=0;i<n;i++)cin>>a[i];
    sort(a,a+n);
    for(int i=0;i<m;i++){
        int h,l;
        cin>>h>>l;
        br.push_back(make_pair(l,h));
    }
    sort(br.begin(),br.end());
    reverse(br.begin(),br.end());

    for(int i=0;i<n;i++){
        if(ko>m-1)break;
        if(a[i]<br[ko].first&&br[ko].second>0){
            a[i]=br[ko].first;
            br[ko].second--;
        }
        if(br[ko].second==0)ko++;
    }

    for(int i=0;i<n;i++){
            ans+=a[i];
        }

    cout<<ans<<endl;

}


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

using namespace std;

const int N = 1e5 + 5;

int sum[N];
int a[N], b[N];

int main() {
  int n;
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    int x;
    scanf("%d", &x);
    sum[x-1] = i;
  }
  a[0] = b[0] = 1;
  for (int i = 1; i < n; i++) {
    int c = sum[i] - sum[i-1];
    a[i] = a[i-1] + 1;
    b[i] = b[i-1] - 1;
    if (c > 0)
      a[i] += c;
    else
      b[i] += c;
  }
  int ma = -b[n-1] + 1;
  for (int i = 0; i < n; i++)
    b[i] += ma;
  for (int i = 0; i < n; i++)
    printf("%d ", a[i]);
  printf("\n");
  for (int i = 0; i < n; i++)
    printf("%d ", b[i]);
  printf("\n");
  return 0;
}

Measured memory_bytes: 768
#include <bits/stdc++.h>
using namespace std;
#define rep(i,ini,n) for(int i=ini;i<n;i++)
#define _rep(i,ini,n) for(int i=ini;i>=n;i--)
#define ToEnd(a) a.begin(),a.end()
uint64_t MOD=1000000007;

int main(){
    int64_t N,A,B,C,D,E; cin>>N>>A>>B>>C>>D>>E;

    int64_t minT=min(A,min(B,min(C,min(D,E))));
    int64_t ans=N/minT+(N%minT>0);
    cout<<ans+4<<endl;
}

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



int main() {
    long long N, a, b, c;
    long long ans = 0;
    vector<int> A, B, C;
    cin >> N;
    for (int i = 0; i < N; i++){
        cin >> a;
        A.push_back(a);
    }
    for (int i = 0; i < N; i++){
        cin >> b;
        B.push_back(b);
    }
    for (int i = 0; i < N; i++){
        cin >> c;
        C.push_back(c);
    }
    sort(A.begin(), A.end());
    sort(B.begin(), B.end());
    sort(C.begin(), C.end());
    for (auto b: B){
        long long less_than_b = distance(A.begin(), lower_bound(A.begin(), A.end(), b));
        long long greater_than_b = C.size() - distance(C.begin(), upper_bound(C.begin(), C.end(), b));
        ans += less_than_b * greater_than_b;
    }
    cout << ans << endl;
}


Measured memory_bytes: 4684
#include <iostream>
#include <vector>
#include <algorithm>
#include <set>
#include <map>

using namespace std;

using ll = long long;

int main() {

    int n;

    cin >> n;

    vector<int> v(n);
    map<int, int> vCount;
    vector<ll> num(n + 1);

    num.push_back(0);

    for(int i = 0; i < n; ++i)
        num[i + 1] = num[i] + i;



    for(int i = 0; i < n; ++i) {
        cin >> v[i];

        if(vCount.find(v[i]) == vCount.end())
            vCount[v[i]] = 1;
        else
            vCount[v[i]]++;

    }

    ll sum = 0;
    for(const auto &a : vCount) {
        sum += num[a.second];

    }

    for(int i = 0; i < n; ++i) {

        int count = vCount[v[i]];
        ll s = sum;
        s -= num[count];
        s += num[count - 1];

        cout << s << endl;
        
    }



    return 0;


}

Measured memory_bytes: 11236
#include <iostream>

using namespace std;
typedef long long llint;

llint d, g;
llint p[15], c[15];

int main(void)
{
	cin >> d >> g;
	for(int i = 0; i < d; i++) cin >> p[i] >> c[i];
	int s = 1 << d;
	
	int rem[15];
	llint ans = 1e9;
	for(int i = 0; i < s; i++){
		llint score = 0, cnt = 0;
		for(int j = 0; j < d; j++){
			if(i & (1<<j)){
				score += p[j] * (j+1) * 100;
				score += c[j];
				cnt += p[j];
			}
		}
		if(score >= g) goto end;
		for(int j = d-1; j >= 0; j--){
			if(i & (1<<j)) continue;
			for(int k = 0; k < p[j]; k++){
				score += (j+1)*100;
				cnt++;
				if(score >= g) goto end;
			}
		}
		end:;
		ans = min(ans, cnt);
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<ll, ll> P;
typedef vector<ll> VI;
typedef vector<VI> VVI;
const ll MOD = 1000000007;
const ll INF = 2147483647;
const ll LINF = 9223372036854775807;
#define REP(i, n) for (int i = 0; i < n; i++)
#define ALL(v) v.begin(), v.end()

ll power(ll x, ll y, ll p) {
	if (y == 0)
		return 1;
	else if (y == 1)
		return x % p;
	else if (y % 2 == 0) {
		ll pow = power(x, y / 2, p);
		return (pow * pow) % p;
	}
	else {
		ll pow = power(x, y / 2, p);
		return (((pow * pow) % p) * x) % p;
	}
}

int main() {
	int n, p; cin >> n >> p;
	string s; cin >> s;
	ll ans = 0;
	if(p==2||p==5){
		REP(i,n){
			if((s[i]-'0')%p==0)
				ans+=i+1;
		}
	}
	else{
		reverse(ALL(s));
		VI r(n+1,0); 
		REP(i,n)r[i+1]=(r[i]+(s[i]-'0')*power(10,i,p))%p;
		VI f(p,0);
		REP(i,n+1)f[r[i]]++;
		REP(i,p)ans+=f[i]*(f[i]-1)/2;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 2180
#include <bits/stdc++.h>
using namespace std;
int min1(int a,int b, int c)
{
	return (min(a,min(b,c)));
}
int k;

int solve(vector<int> &arr, vector<int> &dp, int n)
{
	if (n<=1)
	{
		if (n>=0)
		{
			dp[n]=0;
		}
		return 0;
	}
	if (dp[n]!=-1)
	{
		return dp[n];
	}
	int cost=INT_MAX;
	for (int i=1; i<=k; i++)
	{
		if (n-i>=0)
		cost=min(abs(arr[n]-arr[n-i])+solve(arr,dp,n-i),cost);
	}
	dp[n]=cost;
	return dp[n];
}

int main()
{
	int n;
	cin >> n;
	cin >> k;
	if (k>=n)
	{
		k=n-1;
	}
	vector<int> arr(n+2);
	arr[0]=	INT_MAX;
	arr[1]=	INT_MAX;
	for (int i=2; i<n+2; i++)
	{
		cin >> arr[i];
	}
	vector<int> dp(n+2,-1);
	dp[2]=0;
	cout << solve(arr,dp,n+1);
	return 0;
}

Measured memory_bytes: 8832
import java.util.Scanner;

public class Main {
    private static final int MOD = 1_000_000_007;
    private static final String YES = "Yes";
    private static final String NO = "No";

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        int N = sc.nextInt();
        solve2(sc, N);
    }

    private static void solve(Scanner sc, int N) {
        String leftVal, rightVal;

        System.out.println(0);
        leftVal = sc.next();
        if (leftVal.equals("Vacant")) return;

        System.out.println(N / 2);
        rightVal = sc.next();
        if (rightVal.equals("Vacant")) return;


        int left = 0;
        int right = N - 1;
        if (leftVal.equals(rightVal)) {
            right = N / 2;
        } else {
            leftVal = rightVal;
            left = N / 2;
        }


        System.err.println(left + ", " + right);
        while (right - left > 1) {
            int mid = (right + left) / 2;
            if (left == mid) {
                mid = right;
            }
            System.out.println(mid);

            String input = sc.next();
            if (input.equals("Vacant")) {
                return;
            }

            if ((mid - left + 1) % 2 == 0) {
                if (input.equals(leftVal)) {
                    left = mid;
                    leftVal = input;
                } else {
                    if (left == mid) break;
                    right = mid;
                    rightVal = input;
                }
            } else {
                if (input.equals(leftVal)) {
                    if (left == mid) break;

                    right = mid;
                    rightVal = input;
                } else {
                    left = mid;
                    leftVal = input;
                }

            }
        }

        System.out.println(right % N);
        String input = sc.next();
        if (!input.equals("Vacant")) {
            System.exit(1);
        }
    }

    private static void solve2(Scanner sc, int N) {
        System.out.println(0);
        String leftString = sc.next();
        if (leftString.equals("Vacant")) {
            return;
        }

        int left = 0;
        int right = N;
        while (true) {
            int mid = (left+right)/2;
            System.out.println(mid);
            String ans = sc.next();
            if (ans.equals("Vacant")) return;

            if ((mid-left+1)%2 == 0 && leftString.equals(ans)
                    || (mid-left+1)%2 != 0 && !leftString.equals(ans)) {
                right = mid;
            } else {
                leftString = ans;
                left = mid;
            }
        }
    }
}

Measured memory_bytes: 24228
import java.util.Scanner;

public class Main{
	public static void main(String[] args) {
		try(Scanner sc = new Scanner(System.in)) {
			while(sc.hasNext()) {
				int[] v=new int[101];
				while(sc.hasNext()) {
					int a=sc.nextInt();
					int b=sc.nextInt();
					if(a+b==0) break;
					v[a]++;
					v[b]++;
				}
				//一筆書き判定　始点終点の頂点の次数が奇数かつそれ以外の頂点の次数が偶数→できる
				if(v[1]%2==1 && v[2]%2==1) {
					boolean tf=true;
					for(int i=3; i<101; i++) {
						if(v[i]%2==1) {
							tf=false;
							break;
						}
					}
					if(! tf) System.out.println("NG");
					else System.out.println("OK");
				}
				else
				System.out.println("NG");
			}

		}
	}
}


Measured memory_bytes: 32716
n,m=gets.split.map(&:to_i)
a=(1..n).map{|i| gets.split.map(&:to_i)}
b=(1..m).map{|i| gets.to_i}
puts (0..n-1).map{|i| c=0; (0..m-1).each{|j| c+=a[i][j]*b[j]}; c}*$/

Measured memory_bytes: 6128
#include<iostream>
#include<string>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<cstring>
using namespace std;

int main(){
    string str;
    cin >> str;
    if(str == "AAA" || str == "BBB") cout << "No" << endl;
    else cout << "Yes" << endl;
}

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

using namespace std;

const int max_n = 111, inf = 1000111222;

int n, x, y;
string s;

int main() {
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    cin >> n >> s;
    for (int i = 0; i < n; ++i) {
        if (s[i] == 'R') {
            ++x;
        } else {
            ++y;
        }
    }
    if (x > y) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
    return 0;
}


Measured memory_bytes: 256
import java.io.PrintWriter
val pw = PrintWriter(System.out)

fun main(args : Array<String>) {
    func()
    pw.flush()
}

fun func() {
    val o = next()
    val e = next()

    var ans = ""
    for (i in 0 until o.length) {
        ans += o[i]
        if (i < e.length) ans += e[i]
    }
    println(ans)
}

fun next() = readLine()!!

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

Measured memory_bytes: 32016
#include <bits/stdc++.h>
using namespace std;
#define ll          long long
#define vl          vector<ll>
#define vi          vector<int>
#define pi          pair<int,int>
#define pl          pair<ll,ll>
#define all(a)      a.begin(),a.end()
#define mem(a,x)    memset(a,x,sizeof(a))
#define pb          push_back
#define mp          make_pair
#define F           first
#define S           second
#define trace(x)     cerr<<#x<<":"<<x<<endl;
#define trace2(x,y) cerr<<#x<<":"<<x<<"|"<<#y<<":"<<y<<endl;
#define trace3(x,y,z) cerr<<#x<<":"<<x<<"|"<<#y<<":"<<y<<"|"<<#z<<":"<<z<<endl;
#define fast_io     std::ios::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL)
const int maxn = 1e5+7;
int main(){
	fast_io;
	int n;
	cin>>n;
	ll ans =0 ;
	for(int i=1;i<=n;i++){
		if((i%3!=0 )&&(i%5!=0))ans+=i;
	}
	cout<<ans;
	
	// cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
	return 0;
}

Measured memory_bytes: 3652
using System;
using System.Collections.Generic;
using System.Linq;
using static System.Console;
using static System.Math;

class MainClass : Scanner
{
    static void Main()
    {
        var (A, B) = ReadTuple<int,int>();
        var ans = Max(A + B, Max(A - B, A * B));
        WriteLine(ans);
    }
}



class Scanner
{
    public static string RString() => Console.ReadLine();
    public static int RInt() => ReadTuple<int>();
    public static long RLong() => ReadTuple<long>();
    public static double RDouble() => ReadTuple<double>();

    public static string[] RStrings() => Console.ReadLine().Split();
    public static int[] RInts() => Array.ConvertAll(Console.ReadLine().Split(), int.Parse);
    public static long[] RLongs() => Array.ConvertAll(Console.ReadLine().Split(), long.Parse);
    public static double[] RDoubles() => Array.ConvertAll(Console.ReadLine().Split(), double.Parse);
    public static int[] RInts(Func<string, int> func) => Console.ReadLine().Split().Select(func).ToArray();
    public static long[] RLongs(Func<string, long> func) => Console.ReadLine().Split().Select(func).ToArray();
    public static double[] RDoubles(Func<string, double> func) => Console.ReadLine().Split().Select(func).ToArray();
    //public static string[] RStrings(Func<string, string> func) => Console.ReadLine().Split().Select(func).ToArray();

    public static T1 ReadTuple<T1>()
    {
        var r = RString();
        var r1 = (T1)Convert.ChangeType(r, typeof(T1));
        return r1;
    }
    public static (T1, T2) ReadTuple<T1, T2>()
    {
        var r = RStrings();
        var r1 = (T1)Convert.ChangeType(r[0], typeof(T1));
        var r2 = (T2)Convert.ChangeType(r[1], typeof(T2));
        return (r1, r2);
    }
    public static (T1, T2, T3) ReadTuple<T1, T2, T3>()
    {
        var r = RStrings();
        var r1 = (T1)Convert.ChangeType(r[0], typeof(T1));
        var r2 = (T2)Convert.ChangeType(r[1], typeof(T2));
        var r3 = (T3)Convert.ChangeType(r[2], typeof(T3));
        return (r1, r2, r3);
    }
    public static (T1, T2, T3, T4) ReadTuple<T1, T2, T3, T4>()
    {
        var r = RStrings();
        var r1 = (T1)Convert.ChangeType(r[0], typeof(T1));
        var r2 = (T2)Convert.ChangeType(r[1], typeof(T2));
        var r3 = (T3)Convert.ChangeType(r[2], typeof(T3));
        var r4 = (T4)Convert.ChangeType(r[3], typeof(T4));
        return (r1, r2, r3, r4);
    }
}


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

typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pi;

#define F first
#define S second
#define PB push_back
#define MP make_pair
#define what_is(x) cerr << #x << " is " << x << endl;
#define MT make_tuple
#define eb emplace_back
#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))

#define REP(i,a,b) for (int i = a; i <= b; i++)
#define FOR(i,n) for (int i=0;i < n ; i++)
#define error(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }

void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
	cerr << *it << " = " << a << endl;
	err(++it, args...);
}
bool checkeven(string s){
	int n=s.length();
	if(n%2!=0) return false;
	int c=n/2;
	for(int j=0; j<c;j++){
		if(s[j]!=s[j+c]) return false;
	}
	return true;
}


int main(){
	string s;
	cin >> s;
	int n=s.length();
	if(n%2) {
		int i=n-1;
		while(!checkeven(s.substr(0,i))) i-=2;
		cout << i;
	}
	if(n%2==0){
		int i=n-2;
		while(!checkeven(s.substr(0,i))) i-=2;
		cout << i;
	}

	return 0;
}

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

#define ran 202202

int k, x, y;
int lv;
pair<int, int> v[ran];

int main() {
	scanf("%d%d%d", &k, &x, &y);
	if (k%2==0 && (x+y)%2!=0) {
		puts("-1");
		return 0;
	}
	
	int fx =1, fy = 1;
	if (x<0) {
		fx = -1;
		x = -x;
	}
	if (y<0) {
		fy = -1;
		y = -y;
	}
	
	int tot;
	if ((x+y)%k==0) tot = x+y;
	else
	if (x+y<k) tot = k*2;
	else tot = ((x+y)/k+1)*k;
	if (tot%2 != (x+y)%2) tot += k;
	
	lv = 0;
	int todo = (tot-x-y)/2;
	if (todo >= k) {
		v[lv++] = make_pair(-k, 0);
		x+=k;
		
		int res = todo - k;
		v[lv++] = make_pair(k-res, -res);
		x -= (k-res);
		y += res;
	} else 
	if (todo > 0) {
		int res = k-todo;
		if (x>y) {
			v[lv++] = make_pair(res, -todo);
			x-=res;
			y+=todo;
		} else {
			v[lv++] = make_pair(-todo, res);
			x+=todo;
			y-=res;
		}
	}
	for(;x+y>0;) {
		int dx = min(x, k);
		int dy = min(y, k-dx);
		v[lv++] = make_pair(dx, dy);
		x -= dx; y -= dy;
	}
	
	printf("%d\n", lv);
	x = 0, y = 0;
	for(int i=0;i<lv;i++) {
		x += v[i].first;
		y += v[i].second;
		printf("%d %d\n", x*fx, y*fy);
	}
	
	return 0;
}

Measured memory_bytes: 3712
#include<bits/stdc++.h>
using namespace std;
#define FOR(i, s, e) for(int i = (s); i < (e); i++)
#define FOE(i, s, e) for(int i = (s); i <= (e); i++)
#define FOD(i, s, e) for(int i = (s); i >= (e); i--)
#define ll long long

ll A[100005], prime[10005], prime_3[10005];
int n, m, x, y, z, k, w;
int p[10005];

map<ll, int> M;

void find_prime()
{
	FOE(i, 2, 10000)
	{
		if (p[i] == 1) continue;
		for (int j = i * i; j <= 10000; j += i) p[j] = 1;
	}
	
	FOE(i, 2, 10000) if (p[i] == 0) 
	{
		prime[k] = i;
		prime_3[k++] = 1ll * i * i * i;
	}
}

ll inv(ll x)
{
	ll tmp = x, ret = 1ll;
	
	FOR(i, 0, k)
	{
		if (prime_3[i] > tmp) break;
		y = 0;
		while (tmp % prime[i] == 0) 
		{
			tmp /= prime[i];
			y++;
		}
		
		if (y == 1) ret *= prime[i] * prime[i];
		else if (y == 2) ret *= prime[i];
	
		if (ret > 10000000000ll) return -1;
	}
	
	ll t = (ll)sqrt(tmp);
	if (t * t == tmp) ret *= t;
	else ret *= tmp * tmp;
	
	if (ret > 10000000000ll) return -1;
	return ret;
}

int main ()
{
	find_prime();

	scanf("%d", &n);
	FOR(i, 0, n) 
	{
		scanf("%lld", &A[i]);
		FOR(j, 0, k) while (A[i] % prime_3[j] == 0) A[i] /= prime_3[j];
	}
	
	sort(A, A + n);

	x = 0;
	FOR(i, 0, n) 
	{
		x++;
		if (i == n - 1 || A[i] != A[i + 1])
		{
			M.insert(make_pair(A[i], x));
			x = 0;
		}
	}
	
	//FOR(i, 0, n) printf("%lld ", A[i]); printf("\n");
	
	int ans = 0;
	ll tmp;
	
	FOR(i, 0, n)
	{
		if (A[i] == 1) continue;
		if (i > 0 && A[i] == A[i - 1]) continue;
		
	//	printf("%d %d\n", A[i], M.find(A[i]) -> second);
		
		tmp = inv(A[i]);
		
		if (M.find(tmp) == M.end()) ans += M.find(A[i]) -> second;
		else 
		{
			if (tmp < A[i]) continue;
			ans += max(M.find(A[i]) -> second, M.find(tmp) -> second);
		}
	} 
	
	
	if (A[0] == 1) ans++;
	printf("%d\n", ans);
}


Measured memory_bytes: 7296
n =int(input())

S=[]
ans = 0
count=1

for i in range(n):
    tmp=input()
    S.append("".join(sorted(tmp)))

S.sort()

for i in range(len(S)-1):
    if S[i] == S[i+1]:
        count+=1
    else:
        ans+=count*(count-1)/2
        count=1

ans+=count*(count-1)/2

print(int(ans))
    

Measured memory_bytes: 10584
#include<iostream>
#include<stdio.h>
#include<vector>//s1.erase(n)=文字列s1の、n文字目以降削除
#include<algorithm>//辞書順=next_permutation
#include<set>
#include<string>//char 小文字のほうが32大きい
#include<sstream>
#include<string.h>
#include<complex>
#include<time.h>
#include<random>
#include<cmath>
#include<math.h>
#include<queue>
#include<time.h>
#include<iomanip>
#include<locale>
#include<utility>//swap=数値交換
#define rt "\n"
#define rep(i,n) for(int i=0;i<n;i++)
#define rop(i,n) for(int i=1;i<=n;i++)
#define drep(i,n) for(int i=n-1;0<=i;i--)
#define drop(i,n) for(int i=n;0<i;i--)
#define yes(ans) if(ans)cout<<"yes"<<rt;else cout<<"no"<<rt;
#define Yes(ans) if(ans)cout<<"Yes"<<rt;else cout<<"No"<<rt;
#define YES(ans) if(ans)cout<<"YES"<<rt;else cout<<"NO"<<rt;
#define sec(a,b,ans) if(ans)cout<<a<<rt;else cout<<b<<rt;
#define vcin(s,n) rep(i,n)cin>>s[i];//vcin(配列名),(繰り返し回数)
#define sort(s) sort(s.begin(),s.end())//標準=昇順
#define reve(s) reverse(s.begin(),s.end())
#define asas int ans=0
#define llcncn llint cnt=0
#define llasas llint ans=0
#define str string
#define please return
#define AC 0
#define ic_a int a;cin>>a;
#define ic_b int b;cin>>b;
#define ic_s string s;cin>>s;
#define Rapid_pleaseAC_fast cin.tie(0);ios::sync_with_stdio(false)
#define Pi 3.1415926535897932384626
#define nine 1000000000

using namespace std;
typedef vector<int> vint;
typedef vector<string> vstr;
typedef vector<char> vchar;
typedef vector<double> vdou;
typedef long long int llint;
typedef pair<int, int> pint;
typedef pair<llint, llint> pllint;
typedef vector<llint> vllint;
typedef vector<pint> vpint;
typedef vector<pair<llint, llint>> vpllint;
typedef vector<vector<int>> vvint;
typedef vector<vector<char>> vvchar;
typedef vector<vector<llint>> vvllint;
typedef vector<vector<string>> vvstr;
typedef vector<vector<bool>> vvbool;
typedef vector<vector<pint>> vvpint;
typedef vector<bool> vbool;
typedef long double ld;
const ld eps = 1.0e-10; // 許容される誤差
long long GCD(long long a, long long b) {
	if (b == 0) return a;
	else return GCD(b, a % b);
}

long long LCM(long long a, long long b) {
	return a * b / GCD(a, b);
}

unsigned GetDigit(unsigned num) {
	return std::to_string(num).length();
}

int tow(int n) {//2のn乗
	if (n == 0)return 1;
	int x = tow(n / 2);
	x *= x;
	if (n % 2 == 1)x *= 2;
	return x;//@domino
}

int keta(int n) {
	int sum = 0;
	while (n != 0) {
		sum += n % 10; n /= 10;
	}
	return sum;//Nanashi,tRue,wai
}

/*

 (char)toupper(a[n])=文字列のn文字目を大文字で出力

  pow(a,b)=aのb乗

  */
ld mysqrtl(ld x)
{
	ld a = sqrtl((double)x); // 近似値
	do {
		a = (a + x / a) / 2.0L;
	} while (fabsl(x - a * a) > eps);
	return a;
}
//平方根を求める。sqrtより精度が高い。
//epsを変えて誤差を調整する。
int main(void) {
	Rapid_pleaseAC_fast;
	llint ans=0, n=0,m,count,sum=0,ch=0;
	llint s;
	bool check = false;
	vector<llint> a;
	vector<llint> r,b;
	char c,d,e;
	cin >>n;
	rop(i, n) {
		if (i % 3 != 0 && i % 5 != 0)ans+=i;
	}
	cout << ans << endl;
	please AC;
}


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

int n;

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0), cout.tie(0);
	cin >> n;
	int a, b, cnt = 0;
	for(int i = 1; i <= n; ++i){
		cin >> a >> b;
		if(a == b) ++cnt;
		else cnt = 0;
		if(cnt == 3) return puts("Yes"), 0;
	}
	puts("No");
}

Measured memory_bytes: 3648
#include <iostream>
#include <vector>
#include <algorithm>
#include <iterator>
#include <set>
#include <unordered_set>
#include <map>
#include <cmath>
#include <deque>
#include <queue>
#include <string>
#include <cstring>
#include <stack>


using namespace std;
typedef long long ll;

#define F first
#define S second
#define PB push_back
#define MP make_pair
#define REP(i, a, b) for (int i = a; i < b; i++)
#define V vector

string s;
string t;
void solve(string l, string r) {
    REP(i, 0, l.size()) {
        if(l[i] != r[i]) {
            cout << "No";
            return ;
        }
    }
    cout << "Yes";
    return ;
}

int main() {
    cin >> s >> t;
    solve(s, t);
    return 0;
}



Measured memory_bytes: 3124
/**
 * 
 */
//package AtCoder;
import java.util.*;
/**
 * @author Shivansh Singh
 *
 */
public class Main {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner sc=new Scanner(System.in);
		int i,j,n,W;
		n=sc.nextInt();
		W=sc.nextInt();
		int []w=new int[n];
		int []v=new int[n];
		for (i=0;i<n;i++) {
			w[i]=sc.nextInt();
			v[i]=sc.nextInt();
		}
		long [][]dp=new long[n+1][W+1];
		for (i=0;i<=n;i++)
			dp[i][0]=0;
		for (i=0;i<=W;i++)
			dp[0][i]=0;
		for (i=1;i<=n;i++) {
			for (j=1;j<w[i-1];j++)
				dp[i][j]=dp[i-1][j];
			for (;j<=W;j++) {
				dp[i][j]=(long)Math.max(dp[i-1][j],(dp[i-1][(int)(j-w[i-1])]+v[i-1]));
			}
		}
//		for (i=0;i<=n;i++) {
//			for (j=0;j<=W;j++) {
//				System.out.print(dp[i][j]+" ");
//			}
//			System.out.println();
//		}
		System.out.println(dp[(int)n][(int)W]);
		sc.close();
	}

}


Measured memory_bytes: 141668
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<map>
#include<set>
#include<vector>
#include<queue>
#include<list>
#include<stack>
//#include<unordered_map>
using namespace std;
#define ll long long
#define dd cout<<endl
const long long int inf = 1e18+7;
const int mod = 998244353;

using namespace std;

inline ll int max(ll int a,ll int b) { return a>b?a:b; }
inline ll int min(ll int a,ll int b) { return a<b?a:b; }

const int maxn=205;

bool bk[maxn];

int main()
{
	ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
	
	int x,n;
	
	cin>>x>>n;
	
	for(int i=0,y;i<n;i++)
	{
		cin>>y;
		bk[y]=true;
	}
	
	for(int i=0,now;;i++)
	{
		now=x-i;
		if(!bk[now]) {
			return cout<<now<<endl,0;
		}
		
		now=x+i;
		if(!bk[now]) {
			return cout<<now<<endl,0;
		}
	}
	
}

Measured memory_bytes: 3620
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <memory.h>
#include <math.h>
#include <assert.h>
#include <queue>
#include <map>
#include <set>
#include <string>
#include <algorithm>
#include <iostream>
#include <functional>
#include <unordered_map>
#include <unordered_set>
#include <list>
#include <bitset>

using namespace std;
typedef pair<int, int> Pi;
typedef long long ll;
#define pii Pi
#define pll PL
#define Fi first
#define Se second
#define pb(x) push_back(x)
//#define sz(x) ((int)(x).size())
#define rep(i, n) for(int i=0;i<n;i++)
#define all(x) (x).begin(), (x).end()
typedef tuple<int, int, int> t3;
typedef pair<ll, ll> pll;
typedef long double ldouble;
typedef pair<double, double> pdd;

const double PI = acos(-1);
const double EPS = 1e-9;

const int MX = 100005;

int A[MX*3];
int N;

int main()
{
	scanf("%d", &N);
	for(int i = 1; i <= 3*N; i++) scanf("%d", A+i);
	sort(A+1, A+N*3+1);
	ll sum = 0;
	for(int i = N+1; i <= 3*N; i += 2) sum += A[i];
	printf("%lld\n", sum);
}


Measured memory_bytes: 1408
import java.util.*;

fun main(args: Array<String>) {
    val sc = Scanner(System.`in`)
    val x = Integer.parseInt(sc.next())
    val y = Integer.parseInt(sc.next())
    val a = Integer.parseInt(sc.next())
    val b = Integer.parseInt(sc.next())
    val c = Integer.parseInt(sc.next())
    var p = LongArray(a)
    var q = LongArray(b)
    var r = LongArray(c)
    repeat(a){p[it] = sc.nextLong()}
    repeat(b){q[it] = sc.nextLong()}
    repeat(c){r[it] = sc.nextLong()}
    var apple = (p.sortedBy{it*-1}.slice(0..x-1).toLongArray() + q.sortedBy{it*-1}.slice(0..y-1).toLongArray() + r).sortedBy{it*-1}.take(x+y)
    println(apple.sum())
}


Measured memory_bytes: 122332
#include <bits/stdc++.h>
#include <algorithm>
#include <iostream>
#include <stdio.h>
#include <math.h>
typedef long long ll;
using namespace std;

int main() {
	int a,b,c,d,ma,mi;
	cin>>a>>b>>c>>d;
	ma=max(a,c);
	mi=min(b,d);
    if(mi-ma<0){
    	cout << 0<<endl;
    }
    else{
    	cout << mi-ma<<endl;
    }
	return 0;
}


Measured memory_bytes: 256
import math

# Inputs
n = int(input())
x_list = list(map(int, input().split()))
y_list = list(map(int, input().split()))

# p = 1
d1_list = [abs(x-y) for x, y in zip(x_list, y_list)]
d1 = sum(d1_list)

# p = 2
d2_list = [abs((x-y))**2 for x, y in zip(x_list, y_list)]
d2 = math.sqrt(sum(d2_list))

# p = 3
d3_list = [(abs(x-y))**3 for x, y in zip(x_list, y_list)]
d3 = (sum(d3_list))**(1/3)

# p = infinite
d4_list = [abs(x-y) for x, y in zip(x_list, y_list)]
d4 = max(d4_list)

# Output
print('{:.8f}'.format(d1))
print('{:.8f}'.format(d2))
print('{:.8f}'.format(d3))
print('{:.8f}'.format(d4))



Measured memory_bytes: 5700
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define pb                 push_back
#define bug(x)             cerr<<#x<<" "<<x<<endl;
#define T int time;        scanf("%d", &time); while(time--)
    vector<ll>ar;
  bool check(ll i,ll n){
    if(abs(i-n)<=1)return true;
    for(ll ii=n-1; ii>i; ii--)if(ar[ii]<ar[ii-1])
      cout<<ar[ii]<<" ";
    cout<<endl;
    return true;
  }

   int main(){
      string s;
      cin>>s;
      ll l=s.length();
      for(ll i=0; i<l; i++)
        cout<<"x";
      cout<<endl;
     }
   

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

#ifdef ONLINE_JUDGE
    #define DEBUG(...) // Skip Debug
#else
    #define DEBUG(...) fprintf(stderr,__VA_ARGS__)
#endif

#define rep(i , l , r) for(int i = (l) , ___ = (r) ; i <= ___ ; ++i )
#define per(i , r , l) for(int i = (r) , ___ = (l) ; i >= ___ ; --i )

using namespace std;

string S;
int tot , num;

int main()
{
	cin >> S;
	rep(i , 0 , S.size()-1)
	{
		tot += S[i] - '0';
		num = num * 10 + S[i] - '0';
	}
	if(num % tot == 0) cout << "Yes\n";
	else cout << "No\n";
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<stdlib.h>
#include<string>
#include<math.h>
using namespace std;

int main() {
	string s;
	cin >> s;
	int ans = 0;
	for (int i = 0; i < s.length(); i++) {
		if (s[i] == '+')ans++;
		else ans--;
	}
	cout << ans;
}



Measured memory_bytes: 256
#include "stdio.h"
#include "stdlib.h"
#include "iostream"
#include "math.h"
#include <string.h>
#include <stack>
#include <queue>
#include <map>
#include <string>
#include "algorithm"


using namespace std;
#define fori0(G) for(int i=0;i<G;i++)
#define fori1(G) for(int i=1;i<=G;i++)
#define forj0(G) for(int j=0;j<G;j++)
#define forj1(G) for(int j=1;j<=G;j++)
#define fork0(G) for(int k=0;k<G;k++)
#define fork1(G) for(int k=1;k<=G;k++)
int dx[] = { -1,0,1,0 ,0 }, dy[] = { 0,1,0,-1,0 };
#define nxnycon (0<=nx&&nx<h&&0<=ny&&ny<w) 



int main() {
	
		int a, b, c, x, y, t, s = 0, p;

		cin >> a >> b >> c >> x >> y;
		if (x > y) { t = y;p = 0; }
		else { t = x;p = 1; }
		if (a + b > 2 * c) { s = 2 * c*t; }
		else { s = (a + b)*t; }
		switch (p) {
		case 0:
			if (a > 2 * c) { s += 2 * c*(x - t); }
			else { s += a * (x - t); }
			break;
		case 1:
			if (b > 2 * c) { s += 2 * c*(y - t); }
			else { s += b * (y - t); }
			break;
		}
		cout << s;
		//system("pause");

	return 0;

}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
#define f first
#define s second
#define pb push_back
#define reset(a,b) memset(a,b,sizeof a);
#define ALL(x) x.begin(),x.end()
 
template <typename T>
void cetak(T t){cout << t << ')' << endl;}
template <typename T, typename... V>
void cetak(T t, V... v) {cout << t; if (sizeof...(v)) cout << ", "; cetak(v...);}
 
#define debug(x...) cout << '(' << #x << ") = ("; cetak(x) 
#define sz(x) (int)(x.size())
#define lt(x) (int)(x.length())


const int MOD = 1e9 + 7;

int add(int x, int y){
    int ret = x + y;
    if(ret >= MOD) ret -= MOD;
    return ret;
}
int sub(int x, int y){
    int ret = x - y;
    if(ret < 0) ret += MOD;
    return ret;
}
int mul(int x, int y){
    return (long long)x * y % MOD;
}


const int mx = 1e5 + 10;

int n, m;
int xx[] = {0, 1, 0, -1};
int yy[] = {-1, 0, 1, 0};
vector<string> g;

int bfs(int sx, int sy, int tx, int ty){
    vector<vector<int>> dist(n, vector<int>(m, -1));
    queue<pair<int, int>> q;
    q.push({sx, sy});
    dist[sx][sy] = 0;
    while(!q.empty()){
        int x = q.front().f;
        int y = q.front().s;
        q.pop();
        for(int i = 0; i < 4; i++){
            int X = x + xx[i];
            int Y = y + yy[i];
            if(0 <= X && X < n && 0 <= Y && Y < m && dist[X][Y] == -1 && g[X][Y] == '.'){
                dist[X][Y] = dist[x][y] + 1;
                q.push({X, Y});
            }
        }
    }
    return dist[tx][ty];
}

void solve(){
    cin >> n >> m;
    g.resize(n);
    int ans = 0;
    for(int i = 0; i < n; i++) cin >> g[i];
    for(int i = 0; i < n; i++){
        for(int j = 0; j < m; j++){
            for(int ii = 0; ii < n; ii++){
                for(int jj = 0; jj < m; jj++){
                    if(g[i][j] != '.' || g[ii][jj] != '.') continue;
                    ans = max(ans, bfs(i, j, ii, jj));
                }
            }
        }
    }
    cout << ans << endl;
}

int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int t = 1;
    // cin >> t;
    while(t--){
        solve();
    }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
				using namespace std;
				#define ll long long
				#define mod 1000000007
				#define pll pair<long,long>
				#define se second
				#define fi first
				#define pb push_back
				#include <ext/pb_ds/assoc_container.hpp>
				#include <ext/pb_ds/tree_policy.hpp>
				using namespace __gnu_pbds;

				typedef tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update>ordered_set;
				typedef tree<pll,null_type,less<pll>,rb_tree_tag,tree_order_statistics_node_update>pllordered_set;
				
			
				bool is(string s)
				{
					ll j=s.length()-1;
					for(ll i=0;i<j;i++,j--)
					{
						if(s[i]!=s[j])
							return false;
						}
						return true;
				}
				int main()
				{
					ios_base::sync_with_stdio(false);
					cin.tie(NULL);
					
					string s;
					cin>>s;
					ll n=s.length();
					ll n1=(n-1)/2;
					ll n2=(n+3)/2-1;
					ll diff=n-1-n2+1;
					//cout<<is(s);
					//cout<<is(s.substr(0,n1));
					//cout<<is(s.substr(n2,diff));
					if(is(s) && is(s.substr(0,n1)) && is(s.substr(n2,diff)))
						cout<<"Yes";
					else
						cout<<"No";
				}
				


Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
#include<string.h>
typedef long long LL;
LL gcd(LL a,LL b)
{
	if(b==0)
		return a;
	else
		return gcd(b,a%b);
}
int main()
{
	int N;
	LL a[100+10];
	scanf("%d",&N);
	a[0]=1;
	for(int i=1;i<=N;i++)
	{
		scanf("%lld",&a[i]);
		LL gyz=gcd(a[i-1],a[i]);
		a[i]=(a[i-1]/gyz)*a[i];
	}	
	printf("%lld\n",a[N]);
	return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <algorithm>

using namespace std;
#define REP(i,n) for (int i = 0; i < n; ++i)
#define FOR(i,m,n) for (int i = m; i < n; ++i)

const int MAX = 1e5+10;
const int INF = 1e9+9;
int N, K;
int H[MAX];
int dp[MAX];

int main() {
  cin >> N >> K;
  REP (i, N) {
    cin >> H[i];
    dp[i] = INF;
  }
  dp[0] = 0;
  REP (i, N) {
    FOR (j, 1, K+1) {
      if(i+j >= N) break;
      dp[i+j] = min(dp[i+j], dp[i] + abs(H[i+j]-H[i]));
    }
  }
  cout << dp[N-1] << endl;
  return 0;
}

Measured memory_bytes: 1024
//***The night is the darkest just before the dawn***
 
#include<bits/stdc++.h>
using namespace std;
 
#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
#define pb push_back
#define ll long long
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define rep(i,n) for(i=0;i<n;i++)
#define forn(i, n) for (ll i = 0; i < (ll)(n); ++i)
#define for1(i, n) for (ll i = 1; i <= (ll)(n); ++i)
#define ford(i, n) for (ll i = (ll)(n) - 1; i >= 0; --i)
#define fore(i, a, b) for (ll i = (ll)(a); i <= (ll)(b); ++i)
#define fora(it,x) for(auto it:x)
#define PI 3.14159265
#define sync ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define endl "\n"
 
typedef pair<ll, ll> pii;
typedef vector<ll> vi;
typedef vector<pii> vpi;
typedef vector<vi> vvi;
typedef long long i64;
typedef vector<i64> vi64;
typedef vector<vi64> vvi64;
typedef pair<i64, i64> pi64;
typedef long double ld;
 
template<class T> bool uin(T &a, T b) { return a > b ? (a = b, true) : false; }
template<class T> bool uax(T &a, T b) { return a < b ? (a = b, true) : false; }

ll a[100002];
int main()
{
	ll h,n,s=0;
	cin>>h>>n;

	forn(i,n){
		cin>>a[i];
		s+=a[i];
	}

	if(s<h) cout<<"No";
	else cout<<"Yes";
}

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

#define REP(i,n) for(int (i)=0; i<(int)(n); i++)

long long dp[100010];

int main(void) {
    int N,W;
    cin >> N >> W;
    REP(i,N) {
        int a,b;
        cin >> a >> b;
        for(int k=W-a+1; k>=0; k--) {
            dp[k+a] = max(dp[k+a], dp[k] + b);
        }
    }
    cout << dp[W];
    return 0;
}

Measured memory_bytes: 1024