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

inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> P;
typedef tuple<int,int,int> tpl;

#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define SORT(c) sort((c).begin(),(c).end())
#define REVERSE(c) reverse((c).begin(),(c).end())
#define LB(a,x) lower_bound((a).begin(), (a).end(), x) - (a).begin()
#define UB(a,x) upper_bound((a).begin(), (a).end(), x) - (a).begin()

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

#define en "\n"

const double EPS = 1e-9;
const double PI  = acos(-1.0);
const int INT_INF = 2147483647;
const long long LL_INF = 1LL<<60;
const long long MOD = 1000000007;

#define CLR(a) memset((a), 0, sizeof(a))

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

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

int main(void){
    int N; cin >> N;
    int k = -1;
    for(int i=1; i*(i-1)<=2*N; i++){
        if(i*(i-1) == 2*N){
            k = i;
            break;
        }
    }

    if(k == -1){
        cout << "No" << en;
        return 0;
    }

    vector<vector<int>> S(k);
    int n = 1;
    FOR(i,1,k+1)FOR(j,i+1,k+1){
        S[i-1].push_back(n);
        S[j-1].push_back(n);
        n++;
    }

    cout << "Yes" << en;
    cout << k << en;
    REP(i,k){
        cout << S[i].size() << " ";
        REP(j,S[i].size()) cout << S[i][j] << " ";
        cout << en;
    }
    return 0;
}

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

int main() {
    int R; cin >> R;
    cout << R * R << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using Int = long long;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}


template<typename T,T MOD,T B>
struct RollingHash{
  using ll = long long;
  vector<T> hash,p;
  RollingHash(){}
  RollingHash(vector<T> vs){init(vs);}
  RollingHash(string &s){
    vector<T> vs;
    for(char c:s) vs.emplace_back(c);
    init(vs);
  }
  void init(vector<T> vs){
    int n=vs.size();
    hash.assign(n+1,0);
    p.assign(n+1,1);
    for(int i=0;i<n;i++){
      hash[i+1]=((ll)hash[i]*B+vs[i])%MOD;
      p[i+1]=(ll)p[i]*B%MOD;
    }
  }
  //S[l, r)
  T find(int l,int r){
    T res=(ll)hash[r]+MOD-(ll)hash[l]*p[r-l]%MOD;
    return res>=MOD?res-MOD:res;
  }
};

template<typename T,T MOD,T B1,T B2>
auto rectangle_hash(vector<string> vs,int r,int c){
  vector< RollingHash<T, MOD, B1> > hs;
  for(string s:vs) hs.emplace_back(s);

  int h=vs.size(),w=vs[0].size();
  vector< vector<T> > res(h-r+1,vector<T>(w-c+1));

  for(int j=0;j+c<=w;j++){
    vector<T> ts(h);
    for(int i=0;i<h;i++)
      ts[i]=hs[i].find(j,j+c);

    RollingHash<T, MOD, B2> rh(ts);
    for(int i=0;i+r<=h;i++)
      res[i][j]=rh.find(i,i+r);
  }
  return res;
}

//INSERT ABOVE HERE

signed main(){
  int h,w;
  cin>>h>>w;
  vector<string> ss(h);
  for(int i=0;i<h;i++) cin>>ss[i];

  int r,c;
  cin>>r>>c;
  vector<string> ts(r);
  for(int i=0;i<r;i++) cin>>ts[i];

  const int MOD = 1e9+7;
  const int B1 = 1777771;
  const int B2 = 1e8+7;
  auto srh=rectangle_hash<int, MOD, B1, B2>(ss,r,c);
  auto trh=rectangle_hash<int, MOD, B1, B2>(ts,r,c);

  for(int i=0;i<h-r+1;i++)
    for(int j=0;j<w-c+1;j++)
      if(srh[i][j]==trh[0][0]) cout<<i<<" "<<j<<"\n";

  return 0;
}



Measured memory_bytes: 15820
import java.util.Scanner;
public class Main{
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        while(true){
            String str = sc.next();
            if(str.equals("-")){
                break;
            }
            int num = str.length(),m = sc.nextInt(),h;
            String ar[] =str.split(""),ex[]=new String[num];
            for(int i=0;i<m;i++){
                h=sc.nextInt();
                for(int j=0;j<h;j++){
                    ex[j]=ar[j];
                }
                for(int l=h;l<num;l++){
                    ar[l-h]=ar[l];
                }
                for(int k=0;k<h;k++){
                    ar[k+(num-h)]=ex[k];
                }
            }
            for(int r=0;r<num;r++){
                System.out.print(ar[r]);
            }
            System.out.print("\n");
        }

        sc.close();
    }
}



Measured memory_bytes: 26372
#!/usr/bin/env python3
# -*- coding: utf-8 -*-



def main():
    N = int(input())
    A = tuple(map(int, input().split()))
    A = tuple(a-1 for a in A) # 0-based

    ans = 0
    for i in range(N):
        b = A[i]
        if A[b] == i:
            ans += 1

    ans //= 2
    print(ans)

if __name__ == "__main__": main()


Measured memory_bytes: 14008
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input!(
    n: usize,
    k: usize,
    c: usize,
    s: chars,
    );
    let mut l = vec![];
    let mut r = vec![];
    let mut h = s.iter().map(|&x| x == 'o').collect::<Vec<bool>>();
    let mut i = 0;
    let mut t = 0;
    while t < k {
        if h[i] {
            l.push(i);
            t += 1;
            i += c + 1;
        } else {
            i += 1;
        }
    }
    h.reverse();
    i = 0;
    t = 0;
    while t < k {
        if h[i] {
            r.push(i);
            i += c + 1;
            t += 1;
        } else {
            i += 1;
        }
    }
    r.reverse();
    for (&i, &j) in l.iter().zip(r.iter()) {
        if i == n - 1 - j {
            println!("{}", i + 1);
        }
    }
}


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

int main() {
    int H,W;
    cin >> H >> W;
    vector<vector<char>> mp(H,vector<char>(W));
    int x=0;
    for(int i=0;i<H;i++){
        for(int j=0;j<W;j++){
            cin >> mp[i][j];
        }
    }     
    for(int i=0;i<H;i++){
        for(int j=0;j<W;j++){    
            if(mp[i][j]=='#'){
                if(x>j) {
                    cout << "Impossible" << endl;
                    return 0;
                }else{
                    x=j;
                }
                ;
            }
        }
    }
    cout << "Possible" << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using LL = long long int;
#define incID(i, l, r) for(int i = (l)    ; i <  (r); ++i)
#define decID(i, l, r) for(int i = (r) - 1; i >= (l); --i)
#define incII(i, l, r) for(int i = (l)    ; i <= (r); ++i)
#define decII(i, l, r) for(int i = (r)    ; i >= (l); --i)
#define inc(i, n)  incID(i, 0, n)
#define dec(i, n)  decID(i, 0, n)
#define inc1(i, n) incII(i, 1, n)
#define dec1(i, n) decII(i, 1, n)
#define inID(v, l, r) ((l) <= (v) && (v) <  (r))
#define inII(v, l, r) ((l) <= (v) && (v) <= (r))
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define FI first
#define SE second
#define FR front()
#define BA back()
#define ALL(v) v.begin(), v.end()
#define RALL(v) v.rbegin(), v.rend()
auto setmin   = [](auto & a, auto b) { return (b <  a ? a = b, true : false); };
auto setmax   = [](auto & a, auto b) { return (b >  a ? a = b, true : false); };
auto setmineq = [](auto & a, auto b) { return (b <= a ? a = b, true : false); };
auto setmaxeq = [](auto & a, auto b) { return (b >= a ? a = b, true : false); };
#define SI(v) static_cast<int>(v.size())
#define RF(e, v) for(auto & e: v)
#define until(e) while(! (e))
#define if_not(e) if(! (e))
#define ef else if
#define UR assert(false)
#define IN(T, ...) T __VA_ARGS__; IN_(__VA_ARGS__);
void IN_() { };
template<typename T, typename ... U> void IN_(T & a, U & ... b) { cin >> a; IN_(b ...); };
template<typename T> void OUT(T && a) { cout << a << endl; }
template<typename T, typename ... U> void OUT(T && a, U && ... b) { cout << a << " "; OUT(b ...); }

// ---- ----

auto fl = [](auto a, auto b) { assert(b != 0); return a / b - (a % b != 0 && ((a >= 0) != (b >= 0)) ? 1 : 0); };
auto ce = [](auto a, auto b) { assert(b != 0); return a / b + (a % b != 0 && ((a >= 0) == (b >= 0)) ? 1 : 0); };
auto mo = [](auto a, auto b) { assert(b != 0); a %= b; if(a < 0) { a += abs(b); } return a; };

int main() {
	IN(int, n);
	OUT(ce(n, 2));
}


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

int main() {
   int n; cin >> n;
   vector<ll> a(n);
   rep(i, n) cin >> a.at(i);

   ll S = 0;
   for(int i=0; i<n; i++){
      S = S ^ a.at(i);
   }

   rep(i, n){
      cout << (S ^ a.at(i)) << " ";
   }
   cout << endl;

   return 0;
}


Measured memory_bytes: 4740
#include<cstdio>
#include<cstdlib>
#include<iostream>
#include<string>
#include<map>
#include<vector>

using namespace std;

int main(){
  
  int nc,n,flag=1;
  char c;
  char pr[100000],af[100000];


  while(1){
    
    scanf("%d",&nc);
    
    if(nc == 0) break;
    
    for(int i=0 ; i<nc ; i++){
      scanf(" %c %c",&pr[i],&af[i]);
    }
    scanf("%d",&n);
    
    for(int i=0 ; i<n ; i++){
      scanf(" %c",&c);
      
      for(int j=0 ; j<nc ; j++){
	if(c == pr[j]) {
	  printf("%c",af[j]);
	  flag = 0;
	break;
	}
      }
      if(flag) printf("%c",c);
      flag = 1;
    }
    
    printf("\n");
    
  }
  
  return 0;
}

Measured memory_bytes: 1168
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
#include<assert.h>
#include<numeric>
using namespace std;
#define REP(i,m,n) for(int i=(int)m ; i < (int) n ; ++i )
#define rep(i,n) REP(i,0,n)
typedef long long ll;
typedef pair<int,int> pint;
typedef pair<ll,int> pli;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=1e9+7;

int main(){
    ll n;
    cin>>n;
    ll k;cin>>k;
    ll a[n];
    rep(i,n)cin>>a[i];
    ll ans=0;
    ll ret=0;
    for(int i=40;i>=0;--i){
        ll mask=1LL<<i;
        ll cnt=0;
        rep(j,n){
            if(a[j]&mask)++cnt;
        }
        if(cnt>=n-cnt){
            ans+=mask*cnt;
        }
        else {
            if(mask+ret<=k){
                ans+=(n-cnt)*mask;
                ret+=mask;
            }
            else ans+=mask*cnt;
        }
    }
    cout<<ans<<endl;
    return 0;
}


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

const int maxn = 1e5+10;
const int mod = 1e9+7;
int n;
int arr[maxn];

int32_t main()
{
    cin >> n;
    for(int i = 1;i<=n;i++){
        cin >> arr[i];
    }
    int dp[maxn];
    dp[2] = abs(arr[2] - arr[1]);
    dp[3] = min(abs(arr[3] - arr[1]),abs(arr[3]- arr[2]));
    for(int i = 3;i<=n;i++){
        dp[i] = min(dp[i-1] + abs(arr[i] - arr[i-1]),dp[i-2] + abs(arr[i] - arr[i-2]));
    }
    cout << dp[n] << endl;
    return 0;
}


Measured memory_bytes: 4404
import java.io.IOException;
import java.io.InputStream;
import java.util.HashMap;
import java.util.NoSuchElementException;

class FastScanner {
    private final InputStream in = System.in;
    private final byte[] buffer = new byte[1024];
    private int ptr = 0;
    private int buflen = 0;

    private boolean hasNextByte() {
        if (ptr < buflen) {
            return true;
        } else {
            ptr = 0;
            try {
                buflen = in.read(buffer);
            } catch (IOException e) {
                e.printStackTrace();
            }
            if (buflen <= 0) {
                return false;
            }
        }
        return true;
    }

    private int readByte() {
        if (hasNextByte())
            return buffer[ptr++];
        else
            return -1;
    }

    private static boolean isPrintableChar(int c) {
        return 33 <= c && c <= 126;
    }

    public boolean hasNext() {
        while (hasNextByte() && !isPrintableChar(buffer[ptr]))
            ptr++;
        return hasNextByte();
    }

    public String next() {
        if (!hasNext())
            throw new NoSuchElementException();
        StringBuilder sb = new StringBuilder();
        int b = readByte();
        while (isPrintableChar(b)) {
            sb.appendCodePoint(b);
            b = readByte();
        }
        return sb.toString();
    }

    public long nextLong() {
        if (!hasNext())
            throw new NoSuchElementException();
        long n = 0;
        boolean minus = false;
        int b = readByte();
        if (b == '-') {
            minus = true;
            b = readByte();
        }
        if (b < '0' || '9' < b) {
            throw new NumberFormatException();
        }
        while (true) {
            if ('0' <= b && b <= '9') {
                n *= 10;
                n += b - '0';
            } else if (b == -1 || !isPrintableChar(b)) {
                return minus ? -n : n;
            } else {
                throw new NumberFormatException();
            }
            b = readByte();
        }
    }

    public int nextInt() {
        long nl = nextLong();
        if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE)
            throw new NumberFormatException();
        return (int) nl;
    }

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

public class Main {
    static int[] w = new int[100010];
    static int[] v = new int[100010];
    static int[][] dp = new int[110][100010];
    static int k;

    static int chmin(int a, int b) {
        if (a > b) {
            a = b;
            return a;
        }
        return a;
    }

    static int chmax(int a, int b) {
        if (a < b) {
            a = b;
            return a;
        }
        return a;
    }

    public static void main(String[] args) {
        FastScanner fs = new FastScanner();
        int x = fs.nextInt();
        int t = fs.nextInt();
        System.out.println(x - t <= 0 ? 0 : x - t);

    }
}


Measured memory_bytes: 82644
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using pli = pair<ll, int>;
using Graph = vector<vector<pii>>;
const int MOD = 1e9 + 7;

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

    int N;
    string S[2];
    cin >> N >> S[0] >> S[1];

    int l = 0;
    ll ans = 0;
    if (S[0][0] == S[1][0]) {
        ans += 3;
        l++;
    } else {
        ans += 6;
        l += 2;
    }

    while (l < N) {
        if (S[0][l] == S[1][l]) {
            ans *= (S[0][l - 1] == S[1][l - 1] ? 2 : 1);
            ans %= MOD;
            l++;
        } else {
            ans *= (S[0][l - 1] == S[1][l - 1] ? 2 : 3);
            ans %= MOD;
            l += 2;
        }
    }

    cout << ans << endl;

    return 0;
}


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

using namespace std;

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    int N;
    cin >> N;
    vector<int> nums;
    int a;
    for (int i = 0; i < N; i++) {
        cin >> a;
        nums.push_back(a);
    }
    vector<int> sols;
    a = 0;
    for (int i = 1; i < N; i++) {
        a ^= nums[i];
    }
    sols.push_back(a);
    for (int i = 0; i < N - 1; i++) {
        int b = nums[0] ^ nums[i+1];
        int c = sols[0] ^ b;
        sols.push_back(c);
    }
    for (int i = 0; i < N; i++) {
        cout << sols[i] << " ";
    }
}


Measured memory_bytes: 5524
#include <iostream>
#include <math.h>
using namespace std;

int main()
{
    int a,b,c,d;
    cin >> a >> b >> c >> d;
    if (a+b>c+d)
        cout << "Left" << endl;
    else if (a+b<c+d)
        cout << "Right" << endl;
    else
        cout << "Balanced" << endl;
}

Measured memory_bytes: 256
#define w vector
#define z double
#define q int
#define ar begin()
#define ae end()
#include<iostream>
#include<vector>
#include<algorithm>
#include<limits>
using namespace std;z inf=numeric_limits<z>::infinity();q main(){q n,m,r;cin>>n>>m>>r;w<w<z>>d=w<w<z>>(n,w<z>(n,inf));w<q>v;for(q i=0;i<r;i++){q l;cin>>l;v.push_back(l-1);}
sort(v.ar,v.ae);for(q i=0;i<m;i++){q a,b,c;cin>>a>>b>>c;d[a-1][b-1]=c;d[b-1][a-1]=c;}
for(q k=0;k<n;k++)for(q i=0;i<n;i++)for(q j=0;j<n;j++){d[i][j]=min(d[i][j],d[i][k]+d[k][j]);}
q aa=1e9;do{q bb=0;for(q i=0;i<v.size()-1;i++){bb+=d[v[i]][v[i+1]];}aa=min(aa,bb);}while(next_permutation(v.ar,v.ae));cout<<aa<<endl;}

Measured memory_bytes: 512
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
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; }
typedef long long ll;
const int MAX_N = 60;
int par[MAX_N];//親
int pank[MAX_N];//木の深さ

//n要素で初期化
void init(int n){
    for(int i=0;i<n;i++){
        par[i]=i;
        pank[i]=0;
    }
}

//木の根を求める
int find(int x){
    if(par[x]==x){
        return x;
    }else{
        return par[x]=find(par[x]);
    }
}

//xとyの属する集合を併合
void unite(int x,int y){
    x = find(x);
    y = find(y);
    if(x==y)return;
    if(pank[x]<pank[y]){
        par[x]=y;
    }else{
        par[y]=x;
        if(pank[x]==pank[y])pank[x]++;
    }
}

//xとyが同じ集合に属するか否か
bool same(int x,int y){
    return find(x)==find(y);
}
int main(void){
    int n,m;cin>>n>>m;
    vector<pair<int,int>> p(m);
    int res=0;
    rep(i,m){
        int a,b;cin>>a>>b;a--;b--;
        p[i]={a,b};
    }
    rep(i,m){
        init(n);
        bool ok=true;
        rep(j,m){
            if(i==j)continue;
            int a=p[j].first,b=p[j].second;
            unite(a,b);
        }
        rep(j,n)rep(k,n) if(!same(j,k))ok=false;
        if(!ok)res++;
    }
    cout<<res<<endl;
}

Measured memory_bytes: 256
#include <float.h>
#include <limits.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>

// 内部変数
static FILE *szpFpI;											// 入力
static int siACnt;												// 配列数

// 内部変数 - テスト用
#ifdef D_TEST
	static int siRes;
	static FILE *szpFpA;
	static int siTNo;
#endif

// １行出力
int
fOutLine(
	char *pcpLine				// <I> １行
)
{
	char lc1Buf[1024];

#ifdef D_TEST
	lc1Buf[0] = '\0';
	fgets(lc1Buf, sizeof(lc1Buf), szpFpA);
	if (strcmp(lc1Buf, pcpLine)) {
		siRes = -1;
	}
#else
	printf("%s", pcpLine);
#endif

	return 0;
}

// 実行メイン
int
fMain(
)
{
	int i;
	char lc1Buf[1024];

	// 配列数 - 取得
	fgets(lc1Buf, sizeof(lc1Buf), szpFpI);
	sscanf(lc1Buf, "%d", &siACnt);

	// 配列 - 取得
	int liCnt = 0;
	int liMin = INT_MAX;
	for (i = 0; i < siACnt; i++) {
		int liVal;
		fscanf(szpFpI, "%d", &liVal);

		// 最小値 - 更新
		if (liMin >= liVal) {
			liMin = liVal;
		}

		// 個数
		if (liVal <= liMin) {
			liCnt++;
		}
	}
	fgets(lc1Buf, sizeof(lc1Buf), szpFpI);

	return liCnt;
}

// １回実行
int
fOne(
)
{
	int liRet;
	char lc1Buf[1024];

	// 入力 - セット
#ifdef D_TEST
	sprintf(lc1Buf, ".\\Test\\T%d.txt", siTNo);
	szpFpI = fopen(lc1Buf, "r");
	sprintf(lc1Buf, ".\\Test\\A%d.txt", siTNo);
	szpFpA = fopen(lc1Buf, "r");
	siRes = 0;
#else
	szpFpI = stdin;
#endif

	// 実行メイン
	liRet = fMain();

	// 出力
	sprintf(lc1Buf, "%d\n", liRet);
	fOutLine(lc1Buf);

	// 残データ有無
#ifdef D_TEST
	lc1Buf[0] = '\0';
	fgets(lc1Buf, sizeof(lc1Buf), szpFpA);
	if (strcmp(lc1Buf, "")) {
		siRes = -1;
	}
#endif

	// テストファイルクローズ
#ifdef D_TEST
	fclose(szpFpI);
	fclose(szpFpA);
#endif

	// テスト結果
#ifdef D_TEST
	if (siRes == 0) {
		printf("OK %d\n", siTNo);
	}
	else {
		printf("NG %d\n", siTNo);
	}
#endif

	return 0;
}

// プログラム開始
int
main()
{

#ifdef D_TEST
	int i;
	for (i = D_TEST_SNO; i <= D_TEST_ENO; i++) {
		siTNo = i;
		fOne();
	}
#else
	fOne();
#endif

	return 0;
}



Measured memory_bytes: 128
import java.util.*
import kotlin.math.min

fun main(args : Array<String>) {
    val t = readLine()!!.toInt()

    repeat(t) {
        val (n, a, b, c, d) = readLine()!!.split(" ").map { it.toLong() }
        val divs = longArrayOf(2L, 3L, 5L)
        val costs = longArrayOf(a, b, c)

        val dfs = PriorityQueue<State>()
        dfs.add(State(n, 0))

        var seen = mutableMapOf<Long, Long>()
        seen[0] = Long.MAX_VALUE

        fun pushIfNecessary(nextNum: Long, totalCoins: Long) {
            if ((seen[nextNum] ?: Long.MAX_VALUE) <= totalCoins) return
            seen[nextNum] = totalCoins
            dfs.add(State(nextNum, totalCoins))
        }

        while (dfs.isNotEmpty()) {
            val state = dfs.poll()

            if (state.currentNum == 0L) {
                break
            }

            if ((seen[state.currentNum] ?: Long.MAX_VALUE) < state.totalCoins) {
                continue
            }

            if (state.currentNum == 1L) {
                pushIfNecessary(0, state.totalCoins+d)
                continue
            }

            (0..2).forEach { idx ->
                val div = divs[idx]
                val cost = costs[idx]

                if (state.currentNum % div == 0L) {
                    val nextCost = calcCost (state.currentNum, div, cost, d)
                    pushIfNecessary(state.currentNum/div, state.totalCoins+nextCost)
                } else {
                    val rest = state.currentNum % div
                    val nextCostF = calcCost(state.currentNum-rest, div, cost, d)
                    val nextCostC = calcCost(state.currentNum+(div-rest), div, cost, d)
                    pushIfNecessary((state.currentNum-rest)/div, state.totalCoins+nextCostF+(d*rest))
                    pushIfNecessary((state.currentNum+(div-rest))/div, state.totalCoins+nextCostC+(d*(div-rest)))
                }
            }
        }

        println(seen[0])
    }
}

data class State(val currentNum: Long, val totalCoins: Long): Comparable<State> {
    override fun compareTo(other: State): Int {
        if (totalCoins == other.totalCoins) {
            return currentNum.compareTo(other.currentNum)
        }
        return totalCoins.compareTo(other.totalCoins)
    }
}

fun calcCost(currentNum: Long, divider: Long, mCost: Long, dCost: Long): Long {
    val diff = currentNum - (currentNum/divider)
    if (diff > Int.MAX_VALUE) {
        return mCost
    } else {
        return min(diff * dCost, mCost)
    }
}

Measured memory_bytes: 51324
#include<iostream>

using ull = unsigned long long;

auto process() {
	ull A, B;
	std::cin >> A >> B;
	auto b = (A % 3 == 0 && 3 <= A)
		|| (B % 3 == 0 && 3 <= B)
		|| ((A + B) % 3 == 0);

	auto r = b? "Possible" : "Impossible";

	std::cout << r << "\n";
}

int main() {
	//while (true) {
		process();
	//}
	return 0;
}


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

 ll MOD = 1000000007;

 ll N;

 void dfs(ll cur, int use, ll &count) {
   if (cur > N) return;
   if (use == 0b111) count++;

   dfs(cur * 10 + 3, use | 0b001, count);
   dfs(cur * 10 + 5, use | 0b010, count);
   dfs(cur * 10 + 7, use | 0b100, count);
 }

 int main() {
   cin >> N;

   ll ans = 0;

   dfs(0, 0, ans);

   cout << ans << endl;
 }


Measured memory_bytes: 256
using System;
using System.Linq;

namespace ITP1_10_C
{
    class Program
    {
        static void Main(string[] args)
        {
            while (true)
            {
                int n = int.Parse(Console.ReadLine());
                if (n == 0) break;
                int[] x = Console.ReadLine().Split().Select(int.Parse).ToArray();
                double a = 0; double ave = x.Sum(); ave /= n;
                for (int i = 0; i < n; i++)
                {
                    a += Math.Pow(ave - x[i],2);
                }
                a /= n;
                Console.WriteLine(Math.Sqrt(a));
            }
        }
    }
}


Measured memory_bytes: 9828
#include<stdio.h>
int main()
{
	int a,b,c,n;
	scanf("%d %d %d",&n,&a,&b);
	if(n==2){
		for (int i=1; i < a ;i++) {
			if(a%i+b%i==0){
				printf("%d\n",i);
			}
		}
	}else if(n==3){
		scanf("%d",&c);
		for (int i=1; i < a ;i++) {
			if(a%i+b%i+c%i==0){
				printf("%d\n",i);
			}
		}
	}
	return 0;
}

Measured memory_bytes: 2728
# -*- coding: utf-8 -*-

import bisect

n = int(input())
A = [int(input()) for _ in range(n)]

# last[m] == A[:i]中の長さmの増加部分列の末尾 (の最小値)
last = [-1]

for a in A:
    m = bisect.bisect_left(last, a)
    if m >= len(last):
        last.append(a)
    else:
        last[m] = min(last[m], a)

print(len(last) - 1)



Measured memory_bytes: 10364
#include <iostream>
#include <vector>
using namespace std;
int main() {
        int n,app=1;
        cin >> n;    
        vector<int> a(n);
        for (int i = 0; i < n; i++) {
                cin >> a[i];
                if (a[i] % 2 == 0) 
                        if (a[i] % 3 != 0 && a[i] % 5 != 0)
                                app = 0;
        }   
        if (app)
                cout << "APPROVED" << endl;
        else
                cout << "DENIED" << endl;
        return 0;
}

Measured memory_bytes: 256
N = gets.to_i
a, b = N.times.map{gets.split.map(&:to_i)}.transpose


kaisuu = 0
for i in 0..N-3
    if a[i] == b[i] && a[i+1] == b[i+1] && a[i+2] == b[i+2] then
        puts 'Yes'
        exit
    end
end
puts "No"

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

const int N = 1e5 + 5;

int n, Q, m = 0; ll a[N], f[N], ans[N];

void Solve(ll x, ll v) {
	if (! x) return;
	int pos = upper_bound(a + 1, a + 1 + m, x) - a - 1;
	if (pos == 0) ans[1] += v, ans[x + 1] -= v;
	else {
		f[pos] += (x / a[pos]) * v;
		Solve(x % a[pos], v);
	}
}

int main(void) {
	scanf("%d%d", &n, &Q);
	a[++ m] = n;
	for (int i = 1; i <= Q; ++ i) {
		ll val; scanf("%lld", &val);
		while (m && a[m] >= val) -- m;
		a[++ m] = val;
	}
	f[m] = 1;
	for (int i = m; i >= 2; -- i) {
		f[i - 1] += f[i] * (a[i] / a[i - 1]);
		Solve(a[i] % a[i - 1], f[i]);
	}
	
	ans[1] += f[1];
	ans[a[1] + 1] -= f[1];
	for (int i = 2; i <= n; ++ i) ans[i] += ans[i - 1];
	for (int i = 1; i <= n; ++ i) printf("%lld\n", ans[i]);
	return 0;
} 

Measured memory_bytes: 4096
# -*- coding: utf-8 -*-
# map(int, input().split())
N = int(input())
A = list(map(int, input().split()))

mod = pow(10,9)+7

ruiseki = [0]
for a in A:
    ruiseki.append((ruiseki[-1]+a)%mod)

total = 0
for i in range(1,N+1):
    bubun_sum = (ruiseki[-1]-ruiseki[i])%mod
    bubun_total = (A[i-1]*bubun_sum)%mod
    total = (total+bubun_total)%mod

print(total)

Measured memory_bytes: 102156
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

public class Test
{
	public static void Main()
	{
		int n = int.Parse(Console.ReadLine());
        int[] A = Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse);
        
        Dictionary<int, int> T = new Dictionary<int, int>();
        var tmp = A.OrderBy(a => a).ToArray();
        for(int i = 0; i < n; i++) { T[tmp[i]] = i; }
        
        bool[] V = new bool[n];
        
        int s = A.Min();
        int result = 0;
        
        for (int i = 0; i < n; i++) {
        	if (V[i]) { continue; }
        	
        	int cur = i;
        	int sum = 0;
        	int min = A[cur];
        	int an = 0;
        	
        	while(!V[cur]) {
        		V[cur] = true;
        		an++;
        		
        		if (min > A[cur]) min = A[cur];
        		sum += A[cur];
        		cur = T[A[cur]];
        	}
        	result += Math.Min(sum + (an - 2) * min, min + sum + (an + 1) * s);
        }
        Console.WriteLine(result);
	}
}

Measured memory_bytes: 10304
import math

n = int(input())

tmpn = n

dic = dict([])

for i in range(2, int(math.sqrt(n))+1):
    if tmpn%i == 0 and tmpn/i > 0:
        divided = True
        while divided:
            tmpn = tmpn/i
            if i in dic.keys():
                dic[i] += 1
            else:
                dic[i] = 1
            if tmpn != 1 and tmpn not in dic.keys():
                dic[int(tmpn)] = 1
            if tmpn%i == 0 and tmpn/i > 0:
                divided = True
            else:
                divided = False

keyls = list(dic.keys())

# print (keyls)

for key1 in keyls:
    for key2 in keyls:
        if key1 < key2:
            if key2%key1 == 0 and key2/key1 > 0:
                if key2 in dic.keys():
                    dic.pop(key2)

if len(dic.keys()) == 0 and n != 1:
    ans = 1
else:
    ans = 0
    for key in dic.keys():
        num = dic[key]
        i = 1
        while num > 0:
            num -= i
            if num >= 0:
                ans += 1
            i += 1

print(ans)
# print(dic)

Measured memory_bytes: 9328
class Dice      
    @face = nil         
                        
    def initialize ary   
        @face = ary        
    end                     

    def top
        @face[0]
    end

    def rotate news     
        f = @face.dup
        case news
        when "N"
            @face = [f[1],f[5],f[2],f[3],f[0],f[4]]
        when "E"
            @face = [f[3],f[1],f[0],f[5],f[4],f[2]]
        when "W"
            @face = [f[2],f[1],f[5],f[0],f[4],f[3]]
        when "S"
            @face = [f[4],f[0],f[2],f[3],f[5],f[1]]
        end
    end

    def right top,front
        "SWSWS".each_char do |c|
            if @face[0] == top
                break 
            end
            rotate c
        end
        rotate "N"
        "WWW".each_char do |c|
            if @face[0] == front
                break 
            end
            rotate c
        end
    @face[2]
    end


    def same? face2
        return true if @face == face2
        "WWWWSWWWWSWWWWSWWWWSWSWWWWSSWWW".each_char { |c|
            rotate c
            return true if @face == face2
        }
        return false
    end
end

numbers1 = gets.chomp.split
numbers2 = gets.chomp.split
dice1 = Dice.new numbers1
puts (dice1.same? numbers2)? "Yes" : "No"


Measured memory_bytes: 6880
#include<stdio.h>
 
#define MAX 10000
#define NIL -1
 
typedef struct{
  int parent,left,right;
}Node;
 
Node T[MAX];
int D[MAX],H[MAX],n;
 
void setDepth(int,int);
int setHeight(int);
int getSibling(int);
void print(int);
 
int main(){
  int i,v,l,r,root = 0;
 
  scanf("%d",&n);
  
  for(i=0;i<n;i++){
    T[i].parent = NIL;
  }
  for(i=0;i<n;i++){
    scanf("%d %d %d",&v,&l,&r);
    T[v].left = l;
    T[v].right = r;
    if(l != NIL)T[l].parent = v;
    if(r != NIL)T[r].parent = v;
  }
 
  for(i=0;i<n;i++){
    if(T[i].parent == NIL)root = i;
  }
  
  setDepth(root,0);
  setHeight(root);
 
  for(i=0;i<n;i++){
    print(i);
  }
  return 0;
}
 
void setDepth(int u, int d){
 
  if(u == NIL)return;
  D[u] = d;
  setDepth(T[u].left,d+1);
  setDepth(T[u].right,d+1);
}
 
int setHeight(int u){
  int h1,h2;
 
  h1 = h2 = 0;
  if(T[u].left != NIL)h1 = setHeight(T[u].left) + 1;
  if(T[u].right != NIL)h2 = setHeight(T[u].right) + 1;
  return H[u] = (h1 > h2 ? h1 : h2); 
}
 
int getSibling(int u){
 
  if(T[u].parent == NIL)return NIL;
  if(T[T[u].parent].left != u && T[T[u].parent].left != NIL)
    return T[T[u].parent].left;
  if(T[T[u].parent].right != u && T[T[u].parent].right != NIL)
    return T[T[u].parent].right;
  return NIL;
}
 
void print(int u){
  int deg;
 
  printf("node %d: parent = %d, sibling = %d, ",u,T[u].parent,getSibling(u));
 
  deg = 0;
 
  if(T[u].left != NIL)deg++;
  if(T[u].right != NIL)deg++;
 
  printf("degree = %d, depth = %d, height = %d, ",deg,D[u],H[u]);
 
  if(T[u].parent == NIL)printf("root\n");
  else if(T[u].left == NIL && T[u].right == NIL)printf("leaf\n");
  else printf("internal node\n");
}

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

using namespace std;
using ll = long long;
using ull = unsigned long long;
constexpr int inf = 1<<30;
constexpr int mo = 1e9+7;
constexpr ll infl = 1ll<<60;


int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    
    int n;
    cin>>n;
    map<int,int> m;
    for(int i=2;i<=n;++i){
        int cur = i;
        for(int j=2;j<i+1;++j){
        while(cur%j==0){
            m[j]++;
            cur/=j;
        }
    }
    }
    auto num = [&](int n){
        int count = 0;
        for(auto & a : m){
            if(a.second >= n-1){
                count++;
            }
        }
        return count;
    };
    cout << num(75) + num(25) * (num(3)-1) + num(15) * (num(5)-1) + num(5)*(num(5)-1)*(num(3)-2)/2 << endl;
    return 0;
}

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

using ll = long long;
using P = pair<ll, ll>;

const ll MOD = 1e9+7;
// const ll MOD = 998244353;
const ll INF = 1ll<<60;

#define FOR(i,a,b) for (ll i=(a);i<(ll)(b);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()

struct Comb
{
	const long long mod;
	vector<long long> fac, ifac;

	Comb(long long n, long long m) : mod(m)
	{
		fac.resize(n+1);
		ifac.resize(n+1);

		fac[0] = 1;
		ifac[0] = 1;
		for (long long i = 0; i < n; ++i)
		{
			(fac[i+1] = fac[i]*(i+1)) %= mod;
			(ifac[i+1] = ifac[i]*mpow(i+1, mod-2)) %= mod;
		}
		
	}

	long long mpow(long long x, long long n)
	{ 
		long long ans = 1;
		while(n != 0){
			if(n&1) ans = ans*x % mod;
			x = x*x % mod;
			n = n >> 1;
		}
		return ans;
	}

	long long comb(long long a, long long b)
	{ 
		if(a == 0 && b == 0)return 1;
		if(a < b || a < 0)return 0;
		long long tmp = ifac[a-b]* ifac[b] % mod;
		return tmp * fac[a] % mod;
	}
};


int main(int argc, char **argv)
{
	ll n, k; cin >> n >> k;
	Comb c(2*100010, MOD);
	ll res{0};
	REP(i, min(n-1, k)+1)
	{
		(res += c.comb(n, i) * c.comb(n-1, n-i-1)) %= MOD;
	}
	std::cout << res << std::endl;
}


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

// types
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<ld,ld> pdd;
typedef vector<ll> vll;

// macros
#define ALL(a) a.begin(),a.end()
#define SZ(a) ((int)a.size())
#define FI first
#define SE second
#define REP(i,n) for(int i=0;i<((int)n);i++)
#define REP1(i,n) for(int i=1;i<((int)n);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define PB push_back
#define EB emplace_back
#define MP(a,b) make_pair(a,b)
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
#define Decimal fixed<<setprecision(20)
#define INF 1000000000
#define LLINF 1000000000000000000LL

// constants
const int inf = 1e9;
const ll linf = 1LL << 50;
const double eps = 1e-10;
const int MOD = 1e9 + 7;
const int dx[4] = {-1, 0, 1, 0};
const int dy[4] = {0, -1, 0, 1};

ll func(ll x){
  ll sum = 0;
  while(x != 0){
    sum += x % 10;
    x /= 10;
  }

  return sum;
}

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

  ll n;
  cin >> n;

  if(n % func(n) == 0)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;


}


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

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

    int N;
    long long W;
    
    cin >> N >> W;

    vector<long long> weight(N);
    vector<long long> value(N);

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

    vector<long long> dp(100000+1,1LL<<59);
    dp[0] = 0;

    for(int i=0;i<N;i++) {
        for(int val=100000;val>=0;val--) {
            if(val-value[i]>=0) dp[val] = min(dp[val-value[i]]+weight[i],dp[val]);
        }
    }

    long long v = 0;
    for(long long i=0;i<100000+1;i++) {
        if(dp[i]<=W) v = max(v,i);
    } 

    cout << v << endl;
    



    return 0;
}

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

#define rep(i, n) for (int i = 0; i < n; ++i)
#define all(x) (x).begin(),(x).end()
#define endl "\n"

using ll = long long;
using P = pair<int,int>;
using mp =  map<int,int>;

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

int solve(int n, string &s, string &t){
    int res = 0;
    rep(i, n){
        int cnt = 0;

        string u = s.substr(n-i-1), v = t.substr(0, i+1);
        if(u == v) {
            res = max(res, i+1);
        }

        res = max(res, cnt);
    }

    return 2 * n - res;
}

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

    int n;
    string s, t;
    cin >> n >> s >> t;

    cout << solve(n, s, t) << endl;

    return 0;
}



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

#define REP(i,n) for(int i=0; i < (n); ++i)
#define REPR(i,n) for(int i=(n); i >= 0; --i)
#define FOR(i, m, n) for(int i = (m); i < (n); ++i)

using ll = long long;
#define INF 1e9

int N;
vector<int> L;

int main(){
  cin >> N;
  L.resize(N);
  REP(i, N){
    cin >> L[i];
  }
  sort(L.begin(), L.end());
  vector<int> sum(2010, 0);
  REP(i, N){
    FOR(j, i+1, N){
      sum[L[i]+L[j]]++;
    }
  }
  int ans = 0, diff = N-1;
  REP(i, N){
    FOR(j, L[i]+1, 2002){
      ans += sum[j];
    }
    ans -= diff;
    diff+= N-(i+2);
  }
  cout << ans << endl;  
  return 0;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef long double ld;
#define AORD(f) puts((f)?"APPROVED":"DENIED")
ll n,k;
//ld ;
//string s;
 
int main() {
  cin >> n >> k;
  ll a = 0;
  ll b = 1;
  while(b<=n){
    b*=k;
    a++;
  }
  cout << a << endl;
  return 0;
}

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

using namespace std;

typedef long long ll;
typedef vector<ll> vi;
typedef pair<ll, ll> pii;
typedef vector<pii> vpii;

int main() {
  ll A, B, C;
  cin >> A >> B >> C;
  cout << B + min(C, A + B + 1) << endl;
}


Measured memory_bytes: 256
n,m = map(int,input().split())
x = list(map(int,input().split()))
dist = []
x.sort()
if n > m:
    print(0)
else:
    for i in range(m-1):
        dist.append(x[i+1] -x[i])
    dist.sort()
    print(sum(dist[:m-n]))


Measured memory_bytes: 13968
// in the name if Allah
// YA Ali!
#include <bits/stdc++.h>
using namespace std;
typedef long long ll ;
const ll INF = 1<<30 ;
const ll N= 1e6 ;
#define f first
#define s second
#pragma GCC optimize("O1")
#pragma GCC optimize("O2")
#pragma GCC optimize("O3")
#pragma GCC optimize("O4")
#pragma GCC optimize("O5")
#pragma GCC optimize("O6")
#pragma GCC optimize("O7")
#pragma GCC optimize("O8")
#pragma GCC optimize("Ofast")
#pragma GCC target("avx2")
ll n , d;
int main()
{
std::ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
cin >> n >> d;
ll x = (2*d)+1 ;
cout << n/x + (n%x!=0) ;
    return 0;
}
 /*
              _     _   __
        /_\  (_    (_)  __)
       /   \  _) . (_) (__
 */


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



int main() {

  int N;
  cin >> N;

  vector<tuple<string, int, int>> shop;
  for(int i=0; i<N; i++){
    string name;
    int score;
    cin >> name >> score;
    shop.push_back(make_tuple(name, score*-1, i+1));
  }

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

  for(int i=0; i<N; i++){
    cout << get<2>(shop.at(i)) << endl;
  }
  
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define endl '\n'

using namespace std;
const int MAXN = (1 << 20);

string s;

void read()
{
	cin >> s;
}

void solve()
{
    deque<char> Q;

    int cnt = 0;
    for(int i = 0; i < s.size(); i++)
		Q.push_back(s[i]);

	while(!Q.empty())
	{
        char L = Q.front();
        while(!Q.empty() && L == Q.front())
			Q.pop_front();

		if(Q.empty()) break;
		cnt++;
	}

	cout << cnt << endl;
}

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

	read();
	solve();
	return 0;
}


Measured memory_bytes: 512
a,b,c,d = map(int, input().split())

if a >= c:
    if a >= d:
        print(0)
    elif b >= d:
        print(d-a)
    else:
        print(b-a)
else:
    if b <= c:
        print(0)
    elif b <= d:
        print(b-c)
    else:
        print(d-c)
    




Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define repp(i,l,r)for(long long i=(l);i<(r);i++)
#define rep(i,n) for (long long i = 0; i < (n); ++i)
#define per(i,n) for (long long i = (n); i >= 0; --i)
const int INF = 2147483647;//int max
const long long int MOD = 1000000007;
using namespace std;
using ll = long long;
using P = pair<int,int>;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
//ミョ(-ω- ?)
int main() {
    int a,b,h,m;
    cin >> a >> b >> h >> m;
    ll minu = h*60 + m;
    double hoge = min((minu*0.5 - m*6),360-(minu*0.5 - m*6));
    double p = M_PI * hoge/180;
    cout << fixed << setprecision(20) << sqrt(a*a + b*b - 2*a*b*cos(p)) << endl;
    return 0;
}

Measured memory_bytes: 4212
/*
 * Pawan Harendra Mishra
 */

/*
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <algorithm>
#include <sstream>
#include <queue>
#include <deque>
#include <bitset>
#include <iterator>
#include <list>
#include <stack>
#include <map>
#include <set>
#include <functional>
#include <numeric>
#include <utility>
#include <limits>
*/

/*
 * Windows Powershell
 * Get-Content input.txt | ./a.exe > output.txt
 */

#include <bits/stdc++.h>

using namespace std;

#define X first
#define Y second
#define mod 1000000007
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

#define N 11
ll n, m;
ll b[N][N];
ll k[N];
ll p[N];

int main(int argc, char const *argv[])
{
    //ios::sync_with_stdio(false);
    //cin.tie(NULL);

    // #ifndef ONLINE_JUDGE
    // freopen("input.txt", "r", stdin);
    // //freopen("output.txt", "w", stdout);
    // #else
    // // online submission
    // #endif

    cin >> n >> m;
    for (ll i=0; i<m; i++) {
        cin >> k[i];
        for (ll j=0; j<k[i]; j++) cin >> b[i][j];
        sort(b[i], b[i]+k[i]);
    }
    for (ll i=0; i<m; i++) cin >> p[i];

    ll ans = 0;
    //cout << pow(2,n)-1 << endl;
    for (ll t=0; t<pow(2,n); t++) {
        bool light = true;
        for (ll i=0; i<m; i++) {
            ll count = 0;
            for (ll j=0; j<k[i]; j++) {
                //cout << t << ' ' << (1<<(b[i][j]-1)) << ' ' << (t&(1<<b[i][j])) << endl;
                if (t&(1<<(b[i][j]-1))) count++;
            }
            if (p[i]==0 && count%2==1) light = false;
            else if (p[i]==1 && count%2==0) light = false;

            if (!light) break;
        }
        if (light) ans++;
    }
    cout << ans << endl;
    
    return 0;
}

Measured memory_bytes: 256
#pragma GCC optimize(2)
#pragma GCC optimize(3)
#include <bits/stdc++.h>
using namespace std;
#define clr(s, x) memset(s, x, sizeof(s))
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
inline int read(){int r=0;char c=getchar();while(c<'0'||c>'9') {c=getchar();}while(c>='0'&&c<='9') {r=r*10+c-'0';c=getchar();}return r;}
inline ll readll(){ll r=0;char c=getchar();while(c<'0'||c>'9') {c=getchar();}while(c>='0'&&c<='9') {r=r*10+c-'0';c=getchar();}return r;}
inline ll qpow(ll a,ll b,ll mod){ll res=1;while(b){if(b&1)res = (res*a)%mod;a=(a*a)%mod;b>>=1;}return res;}
inline ll gcd(ll a,ll b){while(b^=a^=b^=a%=b);return a;}
const double eps = 1e-8;
const ll LLINF = 0x3f3f3f3f3f3f3f3f;
const int INF = 0x3f3f3f3f;
const int mod = 1e9+7;
const int MAXN = 1e6+100;
const int MAXM = 1e5;
ll a[MAXN];
int main(){
	int n;
	cin>>n;
	ll ans=0;
	for(int i=1;i<=n;i++){
		 cin>>a[i];
		 ans+=a[i];
	}
	sort(a+1,a+n+1); 
	cout<<(a[n]<ans-a[n]?"Yes":"No")<<endl;
	return 0;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
	int n;cin>>n;
	vector<int> mp(n+2);
	for(int i=1;i<=n;++i){
		int curr;cin>>curr;
		mp[curr] = i;
	}

	long long result = 0;
	set<int> st;
	st.insert(0);st.insert(-1);
	st.insert(n+1);st.insert(n+2);

  	st.insert(mp[n]);
	for(int i=n-1;i>0;--i){
		// i is certain number
		int index = mp[i];
		int l1,l2;
		int r1,r2;
		auto low = st.lower_bound(index);
		low--; l1 = *low; low--; l2 = *low;
		auto up = st.upper_bound(index);
		r1 = *up; up++; r2 = *up;

		// 1 5 2 4 3
		// l2 l1 index r1 r2

		if(l2<1) l2=0;
		if(r2>n) r2=n+1;
      
		//cout<<l2<<" "<<l1<<" "<<index<<" "<<r1<<" "<<r2<<endl;
      
		if(l1 != index){
			result += 1LL * (r1-index) * (l1-l2) * i;
		}

		if(r1 != index){
			result += 1LL * (index-l1) * (r2-r1) * i;
		}
		
		st.insert(mp[i]);
	}

	cout<<result<<endl;
	return 0;
}

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

int main() {
  string S; cin >>S;
  if (S=="ABC") cout <<"ARC" <<endl;
  else cout <<"ABC" <<endl;
  return 0;
}


Measured memory_bytes: 3640
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;++i)
#define rrep(i,n) for(int i=n-1;i>=0;--i)
#define yesno(flg) if(flg){cout<<"YES"<<endl;}else{cout<<"NO"<<endl;}
#define MAX_N 1002
#define i197 1000000007

using namespace std;

typedef long long ll;
typedef pair<ll,ll> P1;
typedef pair<int,int> Pi;
typedef pair<double,Pi> Pdi;
typedef pair<ll,int>Pli;
typedef pair<P1,ll> P2;
const ll INF=1000000000000000001;
struct edge{int to,cost;};
int dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0};
struct Road{double cost;int a,b;};

int main() {

	string s;

	cin>>s;

	int t=0,t2=0;
	rep(i,s.size()){
		if(s[i]=='A'||s[i]=='T'){
			t++;
		}else if(s[i]=='G'||s[i]=='C'){
			t++;
		}else{
			t2=max(t2,t);
			t=0;
		}
	}
	t2=max(t2,t);
	cout<<t2<<endl;
	return 0;

}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <utility>

using namespace std;

int main()
{
  string s, t;
  cin >> s >> t;

  pair<int, int> range = make_pair(-1, -1);
  for (int i = s.size() - 1; i >= 0; --i)
  {
    //
    if (i - (t.size() - 1) < 0)
    {
      break;
    }
    bool result = true;
    for (int j = 0; j < t.size(); ++j)
    {
      int si = i - j;
      int ti = (t.size() - 1) - j;

      if (s[si] != '?' && s[si] != t[ti])
      {
        result = false;
        break;
      }
    }
    if (result)
    {
      range = make_pair(i - (t.size() - 1), i);
      break;
    }
  }

  if (range.first != -1 && range.second != -1)
  {
    for (int i = 0; i < s.size(); ++i)
    {
      if (range.first <= i && i <= range.second)
      {
        cout << t[i - range.first];
      }
      else if (s[i] == '?')
      {
        cout << 'a';
      }
      else
      {
        cout << s[i];
      }
    }
    cout << endl;
  }
  else
  {
    cout << "UNRESTORABLE" << endl;
  }
  return 0;
}

Measured memory_bytes: 256