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

using namespace std;
using ll = long long;
using vec = vector<ll>;
using mat = vector<vec>;
using pll = pair<ll,ll>;

#define INF (1LL << 60)
#define MOD 1000000007
#define PI 3.14159265358979323846

#define REP(i,m,n) for(ll (i)=(m),(i_len)=(n);(i)<(i_len);++(i))
#define FORR(i,v) for(auto (i):v)
#define ALL(x) (x).begin(), (x).end()
#define PR(x) cout << (x) << endl
#define PS(x) cout << (x) << " "
#define SZ(x) ((ll)(x).size())
#define MAX(a,b) (((a)>(b))?(a):(b))
#define MIN(a,b) (((a)<(b))?(a):(b))
#define REV(x) reverse(ALL((x)))
#define ASC(x) sort(ALL((x)))
#define DESC(x) ASC((x)); REV((x))
#define pb push_back
#define eb emplace_back

int main()
{
    ll a, b, x;
    cin >> a >> b >> x;
    double ans;
    if(x*1.0 >= a*a*b*0.5) ans = atan(2.0*(a*a*b-x)/(a*a*a))*180.0/PI;
    else ans = atan((a*b*b)/(2.0*x))*180.0/PI;
    cout << setprecision(12) << ans << endl;

    return 0;
}

/*



*/

Measured memory_bytes: 3988
#include <bits/stdc++.h>
#define fi first
#define se second
#define pii pair<int,int>
#define mp make_pair
#define pb push_back
#define space putchar(' ')
#define enter putchar('\n')
#define eps 1e-10
#define MAXN 1005
//#define ivorysi
using namespace std;
typedef long long int64;
typedef unsigned int u32;
typedef double db;
template<class T>
void read(T &res) {
    res = 0;T f = 1;char c = getchar();
    while(c < '0' || c > '9') {
    	if(c == '-') f = -1;
    	c = getchar();
    }
    while(c >= '0' && c <= '9') {
    	res = res * 10 +c - '0';
    	c = getchar();
    }
    res *= f;
}
template<class T>
void out(T x) {
    if(x < 0) {x = -x;putchar('-');}
    if(x >= 10) {
	out(x / 10);
    }
    putchar('0' + x % 10);
}
const int MOD = 1000000007;
int N,A,B,C,D;
int dp[MAXN][MAXN],c[MAXN][MAXN],fac[MAXN],invfac[MAXN],g[MAXN];
int inc(int a,int b) {
    return a + b >= MOD ? a + b - MOD : a + b;
}
int mul(int a,int b) {
    return 1LL * a * b % MOD;
}
void update(int &x,int y) {
    x = inc(x,y);
}
int fpow(int x,int c) {
    int res = 1,t = x;
    while(c) {
        if(c & 1) res = mul(res,t);
        t = mul(t,t);
        c >>= 1;
    }
    return res;
}
void Solve() {
    read(N);read(A);read(B);read(C);read(D);
    c[0][0] = 1;
    for(int i = 1 ; i <= N ; ++i) {
        c[i][0] = 1;
        for(int j = 1 ; j <= i ; ++j) {
            c[i][j] = inc(c[i - 1][j],c[i - 1][j - 1]);
        }
    }
    fac[0] = 1;
    for(int i = 1 ; i <= N ; ++i) fac[i] = mul(fac[i - 1],i);
    invfac[N] = fpow(fac[N],MOD - 2);
    for(int i = N - 1 ; i >= 0 ; --i) {
        invfac[i] = mul(invfac[i + 1],i + 1);
    }
    dp[0][0] = 1;
    for(int i = 1 ; i <= B - A + 1; ++i) {
        int t = i + A - 1;

        for(int j = 0 ; j <= N ; ++j) {
            dp[i][j] = dp[i - 1][j];
            for(int k = C ; k <= D ; ++k) {
                if(k * t > j) break;
                int tmp = mul(dp[i - 1][j - k * t],c[N - j + k * t][k * t]);
                tmp = mul(fac[k * t],tmp);
                tmp = mul(tmp,fpow(invfac[t],k));
                tmp = mul(tmp,invfac[k]);
                update(dp[i][j],tmp);
            }
        }
    }
    out(dp[B - A + 1][N]);enter;
}
int main() {
#ifdef ivorysi
    freopen("f1.in","r",stdin);
#endif
    Solve();
    return 0;
}


Measured memory_bytes: 8192
/*
  AOJ 1042
  Title:Yes, I have a number
  @kankichi573
*/
#include <stdio.h>

char buf[1000];

main()
{
  char *p;
  int cnt;

  while(1)
    {
      fgets(buf,1000,stdin);
      if(0==strncmp("END OF INPUT",buf,12))
	break;
      for(p=buf,cnt=0;;p++)
	if(*p==' ')
	  {
	    printf("%d",cnt);
	    cnt=0;
	  }
	else if(*p<' ')
	  {
	    printf("%d",cnt);
	    break;
	  }
	else
	  cnt++;
      printf("\n");
    }
  return(0);
}

Measured memory_bytes: 524
#include<bits/stdc++.h>
#define lld long long
#define pb push_back
#define mk make_pair
#define MAX 1e9+7
#define lim 1e5
using namespace std;

int main()
{
	int n;
	cin>>n;
	std::vector<int> a(n+1),b(n+1),c(n+1);

	for(int i=1;i<=n;i++)
	{
		cin>>a[i]>>b[i]>>c[i];
	}

	int dp[n+1][3];

	memset(dp,0,sizeof(dp));

	for(int i=1;i<=n;i++)
	{
		dp[i][0] = max(dp[i-1][1],dp[i-1][2])+a[i];
		dp[i][1] = max(dp[i-1][2],dp[i-1][0])+b[i];
		dp[i][2] = max(dp[i-1][1],dp[i-1][0])+c[i];
	}

	cout<<max(max( dp[n][0] , dp[n][1] ) , dp[n][2])<<endl;

}

Measured memory_bytes: 2560
import java.util.*;

class Main{
	public static void main(String[]$){
		Scanner s=new Scanner(System.in);
		int n=s.nextInt(),m=s.nextInt()-1,d=s.nextInt();
		System.out.printf("%.10f\n",
				m*1.0/n*(d==0
				?1
				:(n-d)*2.0/n));
	}
}


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

#define rep(i,n) for(int i = 0; i < (n); ++i)
#define ll long long
#define P pair<ll,ll>
#define all(v) v.begin(),v.end()
const ll mod = 1e9+7;
const ll INF = 1e18;
const double pi = acos(-1.0);

int main(void)
{
   
    while(true){
        ll h,w; cin>>h>>w;
        if(h==0&&w==0) break;
        vector<vector<char>> rect(h,vector<char>(w,'#'));
        
        rep(i,h)rep(j,w){
            cout<<rect[i][j];
            if(j==w-1) cout<<endl;
        }
        cout<<endl;
    }
    return 0;
}


Measured memory_bytes: 3164
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int N;
    cin >> N;
    int A[N];
    vector<vector<int>> x(N), y(N);
    for (int i = 0; i < N; i++)
    {
        cin >> A[i];
        x[i].resize(A[i]);
        y[i].resize(A[i]);
        for (int j = 0; j < A[i]; j++)
        {
            cin >> x[i][j] >> y[i][j];
        }
    }
    int ans = 0;
    for (int bit = 0; bit < (1 << N); bit++)
    {
        int num = 0;
        bool is_allcorrect = true;
        for (int j = 0; j < N; j++)
        {
            if (!(bit & (1 << j)))
            {
                continue;
            }
            bool is_correct = true;
            for (int k = 0; k < A[j]; k++)
            {
                if (((bit >> (x[j][k] - 1)) & 1) && y[j][k] == 1 || !((bit >> (x[j][k] - 1)) & 1) && y[j][k] == 0)
                {
                    continue;
                }
                else
                {
                    is_correct = false;
                }
            }
            if (!is_correct)
            {
                is_allcorrect = false;
            }
            else
            {
                num++;
            }
        }
        if (is_allcorrect)
        {
            ans = max(ans, num);
        }
    }
    cout << ans << endl;
}

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

int main() {
	cin.tie(0);
   	ios::sync_with_stdio(false);
	string S;
	cin >> S;
	int ans = 0;
	int cnt = 1;
	char now = S[0];
	for (int i = 1; i < S.length(); i++)
	{
		if(S[i]==now){
			cnt++;
		}else{
			if(cnt>0){
				cnt--;
				ans+=2;
			}else{
				now=S[i];
				cnt++;
			}
		}
	}
	
	cout << ans << endl;
	 
}

Measured memory_bytes: 512
-- AtCoder My Practice
-- author: Leonardone @ NEETSDKASU
 
-- 解説読後
-- http://agc004.contest.atcoder.jp/data/agc/004/editorial.pdf

import qualified Data.ByteString.Char8 as C
import Data.Array (listArray, accumArray, (!))
 
main = print . solve . fmap red . C.words =<< C.getContents
    where
        red x = case C.readInteger x of Just v -> fst v

solve (n:x:a) = ans where
    ans = f (n - 1) (sum a) a x
    f 0 r _ _ = r
    f c r ar xx = f (c - 1) r2 ar2 (xx + x) where
        ar2 = zipWith min a $ [last ar] ++ ar
        r2 = min r (xx + sum ar2)


Measured memory_bytes: 1276
#include <bits/stdc++.h>
#define enter putchar('\n')
#define space putchar(' ')
#define pii pair<int,int>
#define fi first
#define se second
#define mp make_pair
#define MAXN 1000005
#define mo 999999137
#define pb push_back
//#define ivorysi
using namespace std;
typedef long long int64;
typedef double db;
template<class T>
void read(T &res) {
    res = 0;T f = 1;char c = getchar();
    while(c < '0' || c > '9') {
        if(c == '-') f = -1;
        c = getchar();
    }
    while(c >= '0' && c <= '9') {
        res = res * 10 + c - '0';
        c = getchar();
    }
    res *= f;
}
template<class T>
void out(T x) {
    if(x < 0) {x = -x;putchar('-');}
    if(x >= 10) out(x / 10);
    putchar('0' + x % 10);
}
int N;
int64 M;
int a[100005],num[100005],cnt;
int sum[100005][2],c[200005];
int tr[200005];
int lowbit(int x) {return x & -x;}
void Insert(int x,int v) {
    while(x <= 2 * N + 1) {
        tr[x] += v;
        x += lowbit(x);
    }
}
int Query(int x) {
    int res = 0;
    while(x > 0) {
        res += tr[x];
        x -= lowbit(x);
    }
    return res;
}
bool check(int x) {
    for(int i = 1 ; i <= N ; ++i) {
        sum[i][0] = sum[i - 1][0] + (a[i] <= x);
        sum[i][1] = sum[i - 1][1] + (a[i] > x);
    }
    memset(tr,0,sizeof(tr));
    for(int i = 1 ; i <= N ; ++i) Insert(sum[i][1] - sum[i][0] + N + 1,1);
    int64 res = 0;
    for(int i = 1 ; i <= N ; ++i) {
        int t = sum[i - 1][1] - sum[i - 1][0] + N + 1;
        res += Query(t - 1);
        Insert(sum[i][1] - sum[i][0] + N + 1,-1);
    }
    return res >= M;
}
int main() {
#ifdef ivorysi
    freopen("f1.in","r",stdin);
#endif
    read(N);
    for(int i = 1 ; i <= N ; ++i) {read(a[i]);num[i] = a[i];}
    M = 1LL * N * (N + 1) / 2;
    M = M / 2 + 1;
    sort(num + 1,num + N + 1);
    cnt = unique(num + 1,num + N + 1) - num - 1;
    int L = 1,R = cnt;
    while(L < R) {
        int mid = (L + R) >> 1;
        if(check(num[mid])) R = mid;
        else L = mid + 1;
    }
    out(num[L]);enter;
    return 0;
}


Measured memory_bytes: 2560
#!/usr/bin/env python3

import sys
import math
from bisect import bisect_right as br
from bisect import bisect_left as bl
sys.setrecursionlimit(2147483647)
from heapq import heappush, heappop,heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7
inf = float('inf')
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))

s = input()
print(s[:3])

Measured memory_bytes: 65268
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <unordered_map>
#include <unordered_set>

using namespace std;

typedef unsigned long long ull;
typedef unsigned int uint;
typedef unsigned char uchar;
#define umap unordered_map
const static ull INVALID_DIGIT = ~(ull)0;

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

    int first = (s[0] - '0') * 10 + (s[1] - '0');
    int second = (s[2] - '0') * 10 + (s[3] - '0');

    auto isPossibleYY = [](int num) {
        return num < 100 && num >= 0;
    };
    auto isPossibleMM = [](int num) {
        return num <= 12 && num >= 1;
    };

    bool firstPossibleYY = isPossibleYY(first);
    bool firstPossibleMM = isPossibleMM(first);
    bool secondPossibleYY = isPossibleYY(second);
    bool secondPossibleMM = isPossibleMM(second);

    bool possibleYYMM = firstPossibleYY && secondPossibleMM;
    bool possibleMMYY = firstPossibleMM && secondPossibleYY;

    if (possibleYYMM && !possibleMMYY)
    {
        cout << "YYMM" << endl;
    }
    else if (!possibleYYMM && possibleMMYY)
    {
        cout << "MMYY" << endl;
    }
    else if (possibleYYMM || possibleMMYY)
    {
        cout << "AMBIGUOUS" << endl;
    }
    else
    {
        cout << "NA" << endl;
    }


    return 0;
}

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

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

  ll ans = 0;
  for(ll i=1;i<n;++i){
    if( a.at(i-1) > a.at(i) ){
      ans += a.at(i-1)-a.at(i);
      a.at(i) = a.at(i-1);
    }
  }
  cout << ans << endl;
  return 0;
}

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

using namespace std;

int my_abs(int x) {
  return x < 0 ? -x : x;
}

int main() {

  int n, k;
  cin >> n >> k;
  vector<int> h(n);
  for(int i=0; i<n; i++) {
    cin >> h[i];
  }

  unsigned long long dp[100010];
  dp[0] = 0;
  dp[1] = my_abs(h[1]-h[0]);

  for(int i=2; i<n; i++) {
    dp[i] = my_abs(h[i]-h[i-1]) + dp[i-1];
    for(int j=2; j<=k; j++) {
      if(i-j>=0) {
        if(my_abs(h[i]-h[i-j]) + dp[i-j] < dp[i]) dp[i] = my_abs(h[i]-h[i-j]) + dp[i-j];
      }
    }
  }

  cout << dp[n-1] << endl;

  return 0;
}


Measured memory_bytes: 1408
/**
SXR0aXAkI0JwbXptI3FhI3Z3I293bCNqY2IjUG0jMCNicG0jVHFkcXZvLyNCcG0jQW10bjBhY2phcWFicXZvLyNNYm16dml0MSNWdyNhdGN1am16I2tpdiNhbXF9bSNQcXUjVnd6I0F0bW14MSNQcWEjaXptI2l0dCNicHF2b2EjUXYjYnBtI3BtaWRtdmEjaXZsI3d2I21pemJwMSNFcHcjcWEjYnBtem0ja2l2I3F2Ym16a21sbSNRdiNQcWEjeHptYW12a20jbXtrbXhiI0lhI3BtI3htenVxYmJtYnBHI1BtI3N2d2VtYnAjRXBpYiMraXh4bWl6bWJwI2J3I1BxYSNrem1pYmN6bWEjSWEsI0ptbnd6bSN3eiNJbmJteiN3eiNKbXBxdmwjYnBtdTEjVnd6I2FwaXR0I2JwbXwja3d1eGlhYSNJY29wYiN3biNwcWEjc3Z3ZXRtbG9tI017a214YiNpYSNQbSNlcXR0bWJwMSNQcWEjYnB6d3ZtI2x3YnAjbXtibXZsI1dkbXojYnBtI3BtaWRtdmEjSXZsI3d2I21pemJwLyNpdmwjUG0jbm1tdG1icCNWdyNuaWJxb2NtI3F2I29jaXpscXZvI0l2bCN4em1hbXpkcXZvI2JwbXUvI053eiNQbSNxYSNicG0jVXdhYiNQcW9wMSNCcG0jQWN4em11bSMrcXYjb3R3enwsMQ==
*/
#include <cstring>
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <queue>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cassert>

#define F first
#define S second
#define endl '\n'
#define deb(x) cout<<#x<<' '<<x<<endl;
#define pb push_back

/*
#ifdef IZI_KATKA
#define int __int64_t
#else
#define int __int64
#endif
*/

const long long MOD = 1e9 + 7;
const long long MAXN = 1e6 + 1;
using namespace std;

typedef long long ll;

long long readInt() {
    bool minus1 = false;
    long long result = 0;
    char ch;
    ch = getchar();
    while (true) {
        if (ch == '-') break;
        if (ch >= '0' && ch <= '9') break;
        ch = getchar();
    }
    if (ch == '-') minus1 = true; else result = ch-'0';
    while (true) {
        ch = getchar();
        if (ch < '0' || ch > '9') break;
        result = result*10 + (ch - '0');
    }
    if (minus1)
        return -result;
    else
        return result;
}

int x[MAXN];
int y[MAXN];

double D(int id1, int id2) {
    double X = x[id1] - x[id2];
    double Y = y[id1] - y[id2];
	return sqrt(X*X+Y*Y);
}

double ans[MAXN];

const double pi = acos(-1.0);

int main() {
	#ifdef IZI_KATKA
	assert(freopen("input", "r", stdin));
    assert(freopen("output", "w", stdout));
    #endif
    int n = readInt();
    for (int i = 0; i < n; i++) {
    	x[i] = readInt(), y[i] = readInt();
    }
    for (int i = 0; i < n; i++) {
    	vector<double> ang;
    	for (int j = 0; j < n; j++) {
      		if (i != j) {
        		ang.push_back(atan2(y[j] - y[i], x[j] - x[i]));
      		}
    	}
		sort(ang.begin(), ang.end());
		double mx = 0.0;
    	for (int j = 0; j < n - 2; j++) {
      		mx = max(mx, ang[j + 1] - ang[j]);
    	}   	
    	mx = max(mx, ang[0] + 2 * pi - ang[n - 2]);
    	double res = (mx > pi ? (mx - pi) / 2 / pi : 0.0);
    	cout << fixed << setprecision(17) << res << '\n';
	}
	return 0;
}

Measured memory_bytes: 4608
#include <bits/stdc++.h>
#define REP(i,n) for (int i = 0; i < (n); i++)
#define RREP(i, s, n) for (int i = s; i < (n); i++)
#define ALL(a) a.begin(), a.end()
#define RALL(a) a.rbegin(), a.rend()
using namespace std;
using ll = long long;
typedef pair<int, int> pint;
typedef pair<ll, ll> pll;
const ll MOD = 1000000007;
const ll INF = MOD * MOD;
const int inf = (1<<29);

int main() {

    string S;
    cin >> S;
    
    int ans = 1;
    int flg = 0;
    for(int i = 1; i < S.size(); i++) {
        if (!flg) {
            if (i == S.size()-1 && S[i] == S[i-1]) break;
            if (S[i] == S[i-1]) {
                i++;
                flg = 1;
            }
            ans++;
        }else {
            flg = 0;
            ans++;
        }
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 640
#include<cstdio>
#include<cstdlib>
#include<iostream>
#include<vector>
#include<queue>
#include<bitset>
#include<string>
#include<stack>
#include<set>
#include<unordered_set>
#include<map>
#include<unordered_map>
#include<cstring>
#include<complex>
#include<cmath>
#include<iomanip>
#include<numeric>
#include<algorithm>
#include<list>
#include<functional>
#include<cassert>
#define mp make_pair
#define pb push_back
#define X first
#define Y second
#define y0 y12
#define y1 y22
#define INF 1987654321987654321
#define PI 3.141592653589793238462643383279502884
#define fup(i,a,b,c) for(int (i)=(a);(i)<=(b);(i)+=(c))
#define fdn(i,a,b,c) for(int (i)=(a);(i)>=(b);(i)-=(c))
#define MEM0(a) memset((a),0,sizeof(a));
#define MEM_1(a) memset((a),-1,sizeof(a));
#define ALL(a) a.begin(),a.end()
#define SYNC ios_base::sync_with_stdio(false);cin.tie(0)
using namespace std;
typedef long long ll;
typedef long double ld;
typedef double db;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef pair<int, int> Pi;
typedef pair<ll, ll> Pll;
typedef pair<double, double> Pd;
typedef vector<int> Vi;
typedef vector<ll> Vll;
typedef vector<double> Vd;
typedef vector<Pi> VPi;
typedef vector<Pll> VPll;
typedef vector<Pd> VPd;
typedef tuple<int, int, int> iii;
typedef tuple<ll, ll, ll> LLL;
typedef vector<iii> Viii;
typedef vector<LLL> VLLL;
typedef complex<double> base;
const ll MOD = 1000000007;
ll POW(ll a, ll b, ll MMM = MOD) {ll ret=1; for(;b;b>>=1,a=(a*a)%MMM)if(b&1)ret=(ret*a)% MMM; return ret; }
ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
ll lcm(ll a, ll b) { if (a == 0 || b == 0)return a + b; return a*(b / gcd(a, b)); }
int dx[] = { 0,1,0,-1,1,1,-1,-1 }, dy[] = { 1,0,-1,0,1,-1,1,-1 };

vector<pair<int,db> > v[1002];
db dist[1002];
bool chk[1002];
int S=0,E=1;
ll x[1002],y[1002],r[1002];
db dd(int i,int j)
{
	db t1=sqrt((x[i]-x[j])*(x[i]-x[j])+(y[i]-y[j])*(y[i]-y[j]));
	db t2=r[i]+r[j];
	return max(0.0,t1-t2);
}
int main() {
	fill(dist,dist+1002,INF);
	scanf("%lld%lld%lld%lld",x+S,y+S,x+E,y+E);
	int n;
	scanf("%d",&n);
	fup(i,2,n+1,1)scanf("%lld%lld%lld",x+i,y+i,r+i);
	fup(i,0,n+1,1)
		fup(j,i+1,n+1,1)
	{
		db d=dd(i,j);
		v[i].pb(mp(j,d));
		v[j].pb(mp(i,d));
	}
	priority_queue<pair<db,int> > q;
	dist[S] = 0;
	q.push({ 0,S });
	while (!q.empty())
	{
		int x = q.top().Y;
		q.pop();
		if (chk[x])continue;
		chk[x] = 1;
		for (const auto& p : v[x])
		{
			int next = p.X;
			db cost = p.Y;
			if (dist[next] > dist[x]+cost)
			{
				dist[next] = dist[x] + cost;
				q.push({ -dist[next],next });
			}
		}
	}
	printf("%.10f",dist[E]);
}

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

using namespace std;
typedef pair<int,int> PII;
#define MP make_pair

int N, W, H;
int f(int x, int y){
  if(y == 0) return x;
  if(x == W) return y+W;
  if(y == H) return W-x+W+H;
  return H-y+W+H+W;
}

int main(){
  cin >> N >> W >> H;
  vector<PII> range(N*2);
  for(int i=0;i<N;++i){
	int x, y; char c; cin >> x >> y >> c;
	y = H - y;
	vector<int> xs(4);
	int d = min(x, y);
	xs[0] = f(x-d, y-d);
	d = min(W-x, y);
	xs[1] = f(x+d, y-d);
	d = min(W-x, H-y);
	xs[2] = f(x+d, y+d);
	d = min(x, H-y);
	xs[3] = f(x-d, y+d);
	for(int i=0;i<4;++i)
	  if(c == "NESW"[i]){
		c = i;
		break;
	  }
	range[i] = MP(xs[c], xs[(c+1)%4]+1);
	//cout << range[i].first << "," << range[i].second << endl;
  }
  int HW = 2 * (H+W);
  for(int i=0;i<N;++i){
	if(range[i].first >= range[i].second){
	  range[i] = MP(range[i].first, range[i].second+HW);
	  range[N+i] = MP(range[i].first+HW, 2*HW+1);
	}
	else
	  range[N+i] = MP(range[i].first+HW, range[i].second+HW);
  }
  sort(range.begin(), range.end());
  //for(int i=0;i<N*2;++i)
  //cout << range[i].first << "," << range[i].second << endl;

  int ans = 1e9;
  for(int i=0;i<N;++i){
	int tmp = 0;
	int last = -1;
	for(int j=i;j<i+N;++j){
	  if(range[j].second <= last)
		last = range[j].second;
	  else if(last <= range[j].first){
		++tmp;
		last = range[j].second;
	  }
	}
	ans = min(ans, tmp);
  }
  cout << ans << endl;
  
  return 0;
}

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

using namespace std;

void solve()
{
	int N, K;
	while(cin >> N >> K, N || K)
	{
		vector<int> S(K);
		for(int i = 0; i < K; ++i)
		{
			cin >> S[i];
		}
		vector< vector<int> > B(N, vector<int>(K));
		for(int i = 0; i < N; ++i)
		{
			for(int j = 0; j < K; ++j)
			{
				cin >> B[i][j];
			}
		}
		bool ok = true;
		vector<int> Sum(K);
		for(int i = 0; i < K; ++i)
		{
			for(int j = 0; j < N; ++j)
			{
				Sum[i] += B[j][i];
			}
			if(S[i] < Sum[i])
			{
				ok = false;
			}
		}
		if(ok)
		{
			cout << "Yes" << endl;
		}
		else
		{
			cout << "No" << endl;
		}
	}
}

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

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

long long gcd(long long m, long long n) {
	long long tmp;
	while (m % n != 0) {
		tmp = n;
		n = m % n;
		m = tmp;
	}
	return n;
}

int main() {
  long long a, b, c, d, cd;
  cin >> a >> b >> c >> d;
  cd = c*d/gcd(c, d);
  long long nc, nd, ncd;
  nc = b/c - (a-1)/c;
  nd = b/d - (a-1)/d;
  ncd = b/cd - (a-1)/cd;
  cout << (b-a+1) - (nc+nd-ncd) << endl;
  return 0;
}

Measured memory_bytes: 256
import java.util.*

val sc = Scanner(System.`in`)
val X = sc.nextInt()

fun main(args: Array<String>) {
    var ans = 1

    for (i in 2..Int.MAX_VALUE) {
        if (pow(i, 2) > X) {
            break
        }
        for (j in 1..Int.MAX_VALUE) {
            if (pow(i, j) > X) {
                break
            }
            ans = Math.max(ans, pow(i, j))
        }
    }
    println(ans)
}

fun pow(a: Int, n: Int): Int {
    var result = 1
    repeat(n) {
        result *= a
    }
    return result
}


Measured memory_bytes: 31264
#include<bits/stdc++.h>
using namespace std;
typedef pair<int,int> P;
typedef pair<P,int> T;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
#define pb push_back
#define mp make_pair
#define eps 1e-9
#define INF 2000000000
#define sz(x) ((int)(x).size())
#define fi first
#define sec second
#define all(x) (x).begin(),(x).end()
#define sq(x) ((x)*(x))
#define rep(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define repn(i,a,n) for(int (i)=(a);(i)<(int)(n);(i)++)
#define EQ(a,b) (abs((a)-(b))<eps)
template<class T> void chmin(T& a,const T& b){if(a>b)a=b;}
template<class T> void chmax(T& a,const T& b){if(a<b)a=b;}
int H,W,h,w;
ll a[505][505];
const ll A = 300000ll;
int main(){
	cin >> H >> W >> h >> w;
	if(H%h==0&&W%w==0){
		cout << "No" << endl;
		return 0;
	}
	memset(a,0,sizeof(a));
	if(h==1){
		for(int i=0;i<H;i++){
			for(int j=0;j<W;j++){
				if(j%w==(w-1))a[i][j]=-(A*(ll)(w-1)+1ll);
				else a[i][j]=A;
			}
		}
	}else if(w==1){
		for(int i=0;i<H;i++){
			for(int j=0;j<W;j++){
				if(i%h==(h-1))a[i][j]=-(A*(ll)(h-1)+1ll);
				else a[i][j]=A;
			}
		}
	}else{
		for(int i=0;i<H;i++){
			for(int j=0;j<W;j++){
				if(i%h==0||j%w==0)a[i][j]=A;
				if(i%h==(h-1)&&j%w==(w-1))a[i][j]=-(A*(ll)(h+w-1)+1ll);
			}
		}
	}
	cout << "Yes" << endl;
	for(int i=0;i<H;i++){
		for(int j=0;j<W;j++){
			printf("%lld",a[i][j]);
			if(j==W-1)printf("\n");
			else printf(" ");
		}
	}
	return 0;
}

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

int main() {
  int N;
  cin >> N;
  int ans = 0;
  
  for(int i=0; i<N; i++) {
    int l, r;
    cin >> l >> r;
    ans += r - l + 1;
  }
  
  cout << ans << endl;
}

Measured memory_bytes: 3544
import { readFileSync } from "fs";

const read = () =>
  readFileSync(0, "utf8")
    .split("\n")
    .map((line) => line.split(" "));

const main = (input: string[][]) => {
  const X = Number(input[0][0]);

  let answer = 1;

  for (let i = 2; i <= Math.sqrt(X); i++) {
    let power = i ** 2;

    while (power * i <= X) {
      power *= i;
    }

    answer = Math.max(answer, power);
  }

  return answer;
};

console.log(main(read()));


Measured memory_bytes: 29680
program main
    implicit none
    integer(4):: n, hp(100),i
    integer(4),allocatable:: x(:)

    read*, n
    allocate(x(n))
    read*, x(:)

    do i = 1, 100
        hp(i) = sum((x(:)-i)*(x(:)-i))
    end do

    print*, minval(hp(:))


end program

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define FOR(var, begin, end) for (int var = (begin); var <= (end); var++)
#define RFOR(var, begin, end) for (int var = (begin); var >= (end); var--)
#define REP(var, length) FOR(var, 0, length - 1)
#define RREP(var, length) RFOR(var, length - 1, 0)
#define EACH(value, var) for (auto value : var)
#define SORT(var) sort(var.begin(), var.end())
#define REVERSE(var) reverse(var.begin(), var.end())
#define RSORT(var) SORT(var); REVERSE(var)
#define OPTIMIZE_STDIO ios::sync_with_stdio(false); cin.tie(0); cout.precision(10); cout << fixed
#define endl '\n'

const int INF = 1e9;
const int MOD = 1e9 + 7;
const ll LINF = 1e18;

int n, a, b, c, d;
string s;

void solve(istream& cin, ostream& cout) {
  cin >> n >> a >> b >> c >> d;
  a--, b--, c--, d--;
  cin >> s;
  bool ans = true;
  FOR(i, a, c - 2) {
    if (s[i] == '#' && s[i + 1] == '#') ans = false;
  }
  FOR(i, b, d - 2) {
    if (s[i] == '#' && s[i + 1] == '#') ans = false;
  }
  if (c > d) {
    bool tmp = false;
    FOR(i, b - 1, d - 1) {
      if (s[i] == '.' && s[i + 1] == '.' && s[i + 2] == '.') tmp = true;
    }
    if (!tmp) ans = false;
  }
  if (ans) cout << "Yes" << endl;
  else
    cout << "No" << endl;
}

#ifndef TEST
int main() {
  OPTIMIZE_STDIO;
  solve(cin, cout);
  return 0;
}
#endif


Measured memory_bytes: 3760
#include<stdio.h>

int main(){
	int x,y;
	scanf("%d %d",&x,&y);
	
	int b = y/2 - x;
	int a = 2*x - y/2;
	
	if(a < 0 || b < 0 || y%2 == 1)
		printf("No\n");
	else
		printf("Yes\n");  
}

Measured memory_bytes: 1632
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int N = 2e5 + 10;
ll n,k;
ll v[N];
int main() {
	cin>>n>>k;
	for(int i = 0; i < n; ++i) {
		cin>>v[i];
	}
	sort(v, v + n);
	reverse(v, v + n);
	ll ans = 0;
	for(int i = k; i < n; ++i) {
		ans += v[i];
	}
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 1792
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
int main()
{
    long long n, m;
    cin >> n >> m;
    long long x = min(n, m), y = max(n, m);
    long long ans = n * m;
    //long long ans;
    if (x==1 && y == 1)
    {
        ans = 1;
    }
    else if (x == 1 && y!= 1)
    {
        ans -= 2;
    }
    else
    {
        ans -= 2*(x+y)-4;
    }
    cout << ans << endl;
}

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

int main(){
    int d;
    cin >> d;

    if(d == 25){
        cout << "Christmas" << endl;
    }else if(d == 24){
        cout << "Christmas Eve" << endl;
    }else if(d == 23){
        cout << "Christmas Eve Eve" << endl;
    }else if(d == 22){
        cout << "Christmas Eve Eve Eve" << endl;
    }

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define INF 1000000005
#define MOD 1000000007
#define EPS 1e-10
#define rep(i,n) for(int i=0;i<(int)(n);++i)
#define rrep(i,n) for(int i=(int)(n)-1;i>=0;--i)
#define srep(i,s,t) for(int i=(int)(s);i<(int)(t);++i)
#define each(a,b) for(auto& (a): (b))
#define all(v) (v).begin(),(v).end()
#define len(v) (int)(v).size()
#define zip(v) sort(all(v)),v.erase(unique(all(v)),v.end())
#define cmx(x,y) x=max(x,y)
#define cmn(x,y) x=min(x,y)
#define fi first
#define se second
#define pb push_back
#define show(x) cout<<#x<<" = "<<(x)<<endl
#define spair(p) cout<<#p<<": "<<p.fi<<" "<<p.se<<endl
#define sar(a,n) cout<<#a<<":";rep(kbrni,n)cout<<" "<<a[kbrni];cout<<endl
#define svec(v) cout<<#v<<":";rep(kbrni,v.size())cout<<" "<<v[kbrni];cout<<endl
#define svecp(v) cout<<#v<<":";each(kbrni,v)cout<<" {"<<kbrni.first<<":"<<kbrni.second<<"}";cout<<endl
#define sset(s) cout<<#s<<":";each(kbrni,s)cout<<" "<<kbrni;cout<<endl
#define smap(m) cout<<#m<<":";each(kbrni,m)cout<<" {"<<kbrni.first<<":"<<kbrni.second<<"}";cout<<endl

using namespace std;

typedef pair<int,int> P;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<double> vd;
typedef vector<P> vp;
typedef vector<string> vs;

const int MAX_N = 100005;

map<ll,ll> mp2[15][130][3];

void solve(int& sm,ll& mul,string& s)
{
    sm = 0,mul = 1;
    rep(i,len(s)){
        sm += (s[i]-'0');
        mul *= (s[i]-'0')+1;
    }
}

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    string s;
    cin >> s;
    int keta = len(s);
    int sm;
    ll mul;
    solve(sm,mul,s);
    mp2[0][0][0][1] = 1;
    rep(i,keta){
        rep(j,sm+1){
            each(it,mp2[i][j][0]){
                rep(k,min(sm+1-j,10)){
                    if(k < s[i]-'0'){
                        mp2[i+1][j+k][1][it.fi*(k+1)] += it.se;
                    }else if(k == s[i]-'0'){
                        mp2[i+1][j+k][0][it.fi*(k+1)] += it.se;
                    }else{
                        mp2[i+1][j+k][2][it.fi*(k+1)] += it.se;
                    }
                }
            }
            srep(k,1,3){
                each(it,mp2[i][j][k]){
                    rep(l,min(sm+1-j,10)){
                        mp2[i+1][j+l][k][it.fi*(l+1)] += it.se;
                    }
                }
            }
        }
    }
    ll ans = 0;
    rep(i,sm){
        rep(j,3){
            each(it,mp2[keta][i][j]){
                ans += it.se;
            }
        }
    }
    rep(i,3){
        each(it,mp2[keta][sm][i]){
            if(it.fi >= mul){
                break;
            }
            ans += it.se;
        }
    }
    ans += mp2[keta][sm][1][mul];
    cout << ans << "\n";
    return 0;
}



Measured memory_bytes: 55552
from fractions import gcd


N = int(input())
A = list(map(int, input().split()))

G_FW    = [None] * N
G_FW[0] = A[0]

for i in range(1, N):
    G_FW[i] = gcd(G_FW[i-1], A[i])

G_RV     = [None] * N
G_RV[-1] = A[-1]

for i in reversed(range(0, N-1)):
    G_RV[i] = gcd(G_RV[i+1], A[i])

G     = [None] * N
G[ 0] = G_RV[1]
G[-1] = G_FW[-2]

for i in range(1, N-1):
    G[i] = gcd(G_FW[i-1], G_RV[i+1])

print(max(G))


Measured memory_bytes: 16616
N=int(input())
a=list(map(int,input().split()))
arr=[]
for A in a:
    if A%2==0:
        arr.append(A)
    else:
        pass

for n in arr:
    if n%3==0 or n%5==0:
        pass
    else:
        print('DENIED')
        exit()
print('APPROVED')

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


int main() {
  int n, a, b;
  cin >> n >> a >> b;
  cout << min(a*n,b) << endl;
  return 0;
}

Measured memory_bytes: 256
// https://atcoder.jp/contests/abc128/tasks/abc128_a
//
#![allow(unused_imports)]
use std::io::*;
use std::fmt::*;
use std::str::*;
use std::cmp::*;
use std::collections::*;

macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

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

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

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

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

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

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

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

#[allow(unused_macros)]
macro_rules! dvec {
    ($t:expr ; $len:expr) => {
        vec![$t; $len]
    };

    ($t:expr ; $len:expr, $($rest:expr),*) => {
        vec![dvec!($t; $($rest),*); $len]
    };
}

#[allow(unused_macros)]
macro_rules! ifv {
    ($t:expr, $a:expr, $b: expr) => {
        if $t { $a } else { $b }
    }
}

#[allow(unused_macros)]
macro_rules! fill {
    ($t:expr, $v:expr) => {
        for i in 0..$t.len() {
            $t[i] = $v;
        }
    };
}

#[allow(unused_macros)]
macro_rules! debug {
    ($($a:expr),*) => {
        println!(concat!($(stringify!($a), " = {:?}, "),*), $($a),*);
    }
}

fn main() {
    input! {
        a: usize, p: usize
    };

    println!("{}", (3*a+p)/2);
}


Measured memory_bytes: 4352
#include<bits/stdc++.h>
#define rep(i,n) for(int (i) = 0;(i) < (n);(i)++)
#define SORT(c) sort((c).begin(),(c).end())
#define MOD 1000000007
//S.size()
//配列名.Length()
using namespace std;

typedef vector<int> VI;
typedef vector<string> VS;
typedef vector<char> VC;
typedef vector<bool> VB;
typedef unsigned long long ll;


int main(void){
	int N; cin>>N;
	int a[N]; rep(i , N)cin>>a[i];
	int num = a[0];
	int cnt = 0;
	bool jud = true;

  if(a[0] == 2){
		cout<<1;
		jud = false;
	}
	while(jud){
		if(a[num - 1] == 2){
			cout<<cnt + 2;
			break;
		}
		else num = a[num - 1];
		cnt++;
		if(cnt == N ){
			cout<<-1;
			break;
		}
	}

}


Measured memory_bytes: 640
#include <iostream>
#include <string>
#include <algorithm>
#include <set>
#include <map>
#include <vector>
#include <queue>
using namespace std;
const long long inf = 1e10;
const long long mod = 1e9+7;

int main(void){
    int n, t[200005], d[200005];
    cin >> n;
    for(int i=0; i<n; i++){
        cin >> d[i];
    }
    int m;
    cin >> m;
    for(int i=0; i<m; i++){
        cin >> t[i];
    }
    sort(d, d+n);
    sort(t, t+m);
    int ite = 0, cnt=0, ite2;
    while(ite < n){
        if(t[ite2] == d[ite]){
            ite2++;
            ite++;
            cnt++;
        }else{
            ite++;
        }
    }
    if(cnt == m){
        cout << "YES" << endl;
    }else{
        cout << "NO" << endl; 
    }
    return 0;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
// std::numeric_limits<int>::max(), min()
// std::setprecision(X)
// std::islower(), std::isupper(), std::tolower, std::toupper
// std::accumulate(m.begin(), m.end(), 0LL);
// std::sort(begin(),end()) // 0, 1, 2, 3 ,4 (default, less);
// std::priority_queue<int, vector<int>, less<int>> que; // 4, 3, 2, 1 (defualt, less) : 
// if ( std::regex_match(S, std::regex("(dream|dreamer|erase|eraser)*")) ) std::cout << "YES" << std::endl;
 
#define rep(i, n) for(int i = 0; i < (int)(n);    i++)
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
typedef long long ll;
typedef std::vector<int> vi;
typedef std::vector<std::vector<int>> vvi;

ll gcd ( ll a, ll b ) { if ( b == 0 ) return a; else return gcd ( b, a%b ); }
ll lcm ( ll a, ll b ) { return a * b / gcd(a, b); }

int main (void) {
  std::cin.tie(0);  std::ios::sync_with_stdio(false);
  ll a, b, c; std::cin >> a >> b >> c;
  ll t = c - a - b;
  if ( t <= 0 ) {
    std::cout << "No" << std::endl;
    return 0;
  }
  else {
    if ( 4*a*b < t*t ) {
      std::cout << "Yes" << std::endl;
    }
    else {
      std::cout << "No" << std::endl;
    }
  }
  //a + b + 2 sqrt(ab) < c ? 
  // 2 sqrt(ab) < c - a - b ?
  return 0;
}



Measured memory_bytes: 256
#include<stdio.h>
int main(){
  long long n,i,k,a=7;
  scanf("%lld",&k);
  for(i=0;i<k;i++){
    if(a%k==0){
      printf("%lld\n",i+1);
      return 0;
    }
    a=a%k;
    a=a*10+7;
  }
  printf("-1\n");
  return 0;
}


Measured memory_bytes: 1732
#include<bits/stdc++.h>
using namespace std;
#define endl '\n'
#define optimize() ios_base::sync_with_stdio(0);
int n;
int arr[100000][3];
int point[100000][3];

int p(int row,int col)
{

    if(row == n-1)
    {
        return arr[n-1][col];
    }
    if(point[row][col]>0)
    {
        return point[row][col];
    }

    else if(col==0)
    {
        return point[row][col]=arr[row][col]+max(p(row+1,1),p(row+1,2));
    }

    else if(col==1)
    {
        return point[row][col]=arr[row][col]+max(p(row+1,0),p(row+1,2));
    }
    else if(col==2)
    {
        return point[row][col]=arr[row][col]+max(p(row+1,0),p(row+1,1));
    }

}




int main()
{
    optimize();

    cin>>n;



    for(int i=0; i<n; i++)
    {
        for(int j=0; j<3; j++)
        {
            cin>>arr[i][j];
        }
    }

    int res=max(p(0,0),max(p(0,1),p(0,2)));
    cout<<res;

}



Measured memory_bytes: 10568
def city_savers(N: int, A: list, B: list)->int:
    ans = 0
    for i in range(N):
        attacked = min(B[i], A[i])
        B[i] -= attacked
        A[i] -= attacked
        ans += attacked

        attacked = min(B[i], A[i+1])
        B[i] -= attacked
        A[i+1] -= attacked
        ans += attacked

    # print(A)
    # print(B)
    return ans


if __name__ == "__main__":
    N = int(input())
    A = list(map(int, input().split()))
    B = list(map(int, input().split()))
    ans = city_savers(N, A, B)
    print(ans)


Measured memory_bytes: 18624
#include<bits/stdc++.h>
#define f(i,a,b) for(long long i=a;i<b;i++)
#define pb(i) push_back(i)
#define mk(x,y) make_pair(x,y)
#define F first
#define S second
#define FIO ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
typedef long long ll;
using namespace std;

ll digsum(ll n){
	return n==0 ? n:n%10+digsum(n/10);
}
int main(){
	FIO;
	ll n;cin>>n;
	if(n%(digsum(n))==0) cout<<"Yes\n";
	else cout<<"No\n";
	return 0;
}

Measured memory_bytes: 384
#include <iostream>

using namespace std;

int main(){
    string s;
    getline(cin,s);
    int i,l=s.length();
    for (i=0;i<l;i++){
        if (s[i]>='A'&&s[i]<='Z'){
            s[i]+='a'-'A';
        }else if (s[i]>='a'&&s[i]<='z'){
            s[i]+='A'-'a';
        }
        cout<<s[i];
    }
    cout<<endl;
    return 0;
}

Measured memory_bytes: 1172
#include <bits/stdc++.h>
using namespace std;
#define rep(i,N) for(int i=0;i<int(N);++i)
using ll = long long;
const int INF = 2147483647;
// const ll INF = 1000000000000000000LL;
int main() {
	int x,n;
	cin >> x >> n;
	vector<int> p(n);
	rep(i,n) cin >> p[i];
	sort(p.begin(),p.end());
	int ans;
	int nin = INF;
	for(int i=1;i<=101;i++){
		//同じ数だったらなにもしない
		bool flag=false;
		rep(j,n){
			if(i==p[j])
				flag = true;
		}
		if(flag) continue;

		if(nin>abs(i-x)){
			nin = abs(i-x);
			ans = i;
		}
	}
	if(x<=ans-x)
		ans = 0;
	// if(x==abs(ans-x)) ans=0;
	cout << ans << endl;
	return 0;
}


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

int main(){
  int n,a[2]={1,1};
  cin>>n;

  int c=0;
  for(int i=1;i<n;i++)a[c]=a[0]+a[1],c=!c;
  cout << a[!c]<<endl;
  return 0;
}

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

N, K, Q = map(int, input().split())
A = list(map(int, input().split()))
cannot_use = set([-1])
ans = float('inf')
for i in sorted(A):
    tmp = []
    use = []
    for a in A + [-1]:
        if a not in cannot_use:
            tmp.append(a)
        else:
            if len(tmp) >= K:
                tmp.sort()
                use += tmp[:len(tmp)-K+1]
            tmp = []
    use.sort()
    if len(use) < Q:
        break
    ans = min(ans, use[Q-1] - i)
    cannot_use.add(i)
print(ans)

Measured memory_bytes: 45084
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Numerics; 

class _Class
{
  void _Do()
  {
    var ABCK = Split.longs();
    var a = ABCK[0] - ABCK[1];
    if (ABCK[3] % 2 == 0)
    {
      Console.WriteLine(a);
    }
    else
    {
      Console.WriteLine(-a);
    }
  }

  //
  static void Main(string[] args)
  {
    _(args);
    new _Class()._Do();
  }
  [Conditional("DEBUG")]
  static void _(string[] args)
  {
    if (args.Length != 0 && File.Exists(args[0]))
      Console.SetIn(new StreamReader(args[0]));
    else
      Console.Error.WriteLine("in");
  }
}

static class Split
{


  // 1
  public static string[] strings()
  {
    return Console.ReadLine().Split();
  }


  // [2.1] -2,147,483,648 ~ +2,147,483,647
  public static int[] ints()
  {
    var _s = Console.ReadLine().Split();

    var x = new int[_s.Length];
    for (var i = 0; i < _s.Length; i++)
      x[i] = int.Parse(_s[i]);

    return x;
  }

  // [2.2] 
  // -9,223,372,036,854,775,808 ~ 
  // +9,223,372,036,854,775,807
  public static long[] longs()
  {
    var _s = Console.ReadLine().Split();

    var x = new long[_s.Length];
    for (var i = 0; i < _s.Length; i++)
      x[i] = long.Parse(_s[i]);

    return x;
  }

  public static double[] doubles()
  {
    var _s = Console.ReadLine().Split();

    var x = new double[_s.Length];
    for (var i = 0; i < _s.Length; i++)
      x[i] = double.Parse(_s[i]);

    return x;
  }

  public static BigInteger[] bigs()
  {
    var _s = Console.ReadLine().Split();

    var x = new BigInteger[_s.Length];
    for (var i = 0; i < _s.Length; i++)
      x[i] = BigInteger.Parse(_s[i]);

    return x;
  }
}


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

vector<vector<int>> ord;
int nxt[6][6];

void init(){
	{
		vector<int> a = { 0,1,2 };
		do{
			ord.push_back(a);
		} while(next_permutation(a.begin(), a.end()));
	}
	for(int i = 0; i < 6; i++){
		for(int j = 0; j < 6; j++){
			vector<int> v1 = ord[i], v2 = ord[j];
			vector<int> res(3);
			for(int k = 0; k < 3; k++){
				res[k] = v2[v1[k]];
			}
			nxt[i][j] = find(ord.begin(), ord.end(), res) - ord.begin();
		}
	}
}

bool dp[110][6][2];
int id[100];

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
#ifdef LOCAL
	std::ifstream in("in");
	std::cin.rdbuf(in.rdbuf());
#endif

	init();

	int N;
	cin >> N;
	for(int i = 0; i < N; i++){
		int w;
		cin >> w;
		vector<int> v = { 0,1,2 };
		while(w--){
			int a;
			cin >> a;
			if(a == 0) swap(v[0], v[1]);
			else swap(v[1], v[2]);
		}
		id[i] = find(ord.begin(), ord.end(), v) - ord.begin();
	}

	dp[0][0][0] = 1;
	for(int i = 0; i < N; i++){
		for(int j = 0; j < 6; j++){
			for(int k = 0; k < 2; k++){
				if(!dp[i][j][k]) continue;
				dp[i + 1][j][k] = 1;
				int to = nxt[j][id[i]];
				dp[i + 1][to][1] = 1;
			}
		}
	}

	if(dp[N][0][1]) cout << "yes" << endl;
	else cout << "no" << endl;
}



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

using namespace std;
const int maxn = 2e5 + 10;

int c[maxn][2];
int main() {
    ios_base::sync_with_stdio(0);
    int n, m;
    cin >> n >> m;
    memset(c, 0, sizeof(c));
    int x, y;
    int flag = 0;
    for(int i = 0; i < m; ++i){
        cin >> x >> y;
        int a, b;
        a = min(x, y);
        b = max(x, y);
        if(a == 1)c[b][0] = 1;
        else if(b == n)c[a][1] = 1;
    }
    for(int i = 1; i <= n; ++ i){
        if(c[i][0] && c[i][1]){flag = 1;break;}
    }
    if(flag)cout << "POSSIBLE" << endl;
    else cout << "IMPOSSIBLE" <<endl;
    return 0;
}



Measured memory_bytes: 1792
#include <iostream>

using namespace std;

int func(int n, int s)
{
	if(n >= 0 && s == 1){
		return 1;
	}
	if(n == 0){
		return 1;
	}
	if(n < 0){
		return 0;
	}
	int r = 0;
	for(int i = s; i > 0; i--){
		r += func(n-i*i, i);
	}
	
	return r;
}

int main()
{
	int n, c, t;
	
	while(1){
		cin >> n;
		if(n == 0){
			break;
		}
		c = 0;
		
		for(int i = 1; i*i <= n; i++){
			t = i;
		}
		
		for(int i = t; i > 0; i--){
			c += func(n-i*i, i);
		}
		
		cout << c << endl;
	}
	
	return 0;
}

Measured memory_bytes: 0
def main():
    S = input()
    for bit in range(1 << 3):
        ans = int(S[0])
        T = S[0]
        for i in range(3):
            if bit & (1 << i):
                ans += int(S[i+1])
                T += "+"+S[i+1]
            else:
                ans -= int(S[i+1])
                T += "-"+S[i+1]
        if ans == 7:
            return print(T+"=7")


if __name__ == '__main__':
    main()


Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(ll i = 0, i##_len = (n); i < i##_len; i++)
#define reps(i, s, n) for(ll i = (s), i##_len = (n); i < i##_len; i++)
#define rrep(i, n) for(ll i = (n) - 1; i >= 0; i--)
#define rreps(i, e, n) for(ll i = (n) - 1; i >= (e); i--)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) ((ll)(x).size())
#define len(x) ((ll)(x).length())
#define endl "\n"

ll f(ll a, ll b, ll v) {
    return b / v - (a - 1) / v;
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    // ifstream in("input.txt");
    // cin.rdbuf(in.rdbuf());
    ll a, b, c, d;
    cin >> a >> b >> c >> d;
    cout << ((b - a + 1) - f(a, b, c) - f(a, b, d) + f(a, b, c / __gcd(c, d) * d)) << endl;
    return 0;
}


Measured memory_bytes: 384
#include <algorithm>
#include <bits/stdc++.h>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
using namespace std;

#define rep(X, S, E) for (int(X) = (S); (X) < (E); ++(X))
#define rrep(X, S, E) for (int(X) = (E)-1; (X) >= (S); --(X))
#define itrep(X, Y) for (auto(X) = (Y).begin(); (X) != (Y).end(); (X)++)
#define all(X) (X).begin(), (X).end()
#define pb push_back
#define mp make_pair
#define fi first
#define sc second
#define print(x) cout << x << endl

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef priority_queue<ll, vl> decendingQueue;              //降順
typedef priority_queue<ll, vl, greater<ll>> ascendingQueue; //昇順
const int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
const ll INF = 9 * 1e18;
const ll MOD = 1e9 + 7;

void solve(long long N, std::vector<long long> W) {
  ll sumL = 0;
  ll sumR = 0;
  rep(i, 0, N) { sumR += W[i]; }

  ll ans = sumR;
  rep(i, 0, N - 1) {
    sumL += W[i];
    sumR -= W[i];
    ans = min(ans, abs(sumR - sumL));
  }

  print(ans);
}

int main() {
  long long N;
  scanf("%lld", &N);
  std::vector<long long> W(N);
  for (int i = 0; i < N; i++) {
    scanf("%lld", &W[i]);
  }
  solve(N, std::move(W));
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll   long long int
#define T int t; cin>>t; while(t--)
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL);cout.tie(NULL)
#define PI 3.141592653589793238462643383
vector<ll> grp;
vector<ll> parent;
ll get(ll x){
    if(x == parent[x]) return parent[x];
    else return parent[x] = get(parent[x]);
}

void unite(ll x, ll y){
    ll x1 = get(x);
    ll y1 = get(y);

    if(x1!=y1){
        parent[y1] = min(x1,y1);
        parent[x1] = min(x1,y1);
        grp[(min(x1,y1))]++;
    }
}

int main (){
    fast;
    ll n,m;
    cin>>n>>m;
    ll x,y;
    parent.resize(n+1);
    grp.resize(n+1);
    for(ll i=0;i<=n;i++){
        parent[i] = i;
        grp[i] = 1;
    } 
    for(ll i=0;i<m;i++){
        cin>>x>>y;
        unite(x,y);
    }
    ll ans = 1;
    // for(ll i=1;i<=n;i++){
    //     ans = max(ans,grp[i]);
    // }
    // vector<ll> temp;
    unordered_map<ll,ll> mp;
    for(ll i=1;i<=n;i++){
        mp[get(i)]++;
    }
    for(auto i : mp){
        ans = max(ans, i.second);
    }

    cout<<ans<<endl;
    grp.clear();
    parent.clear();
}











Measured memory_bytes: 14552
def bubbleSort(A, N):
    cnum = 0
    flag = True
    while flag:
        flag = False
        for j in range(N - 1, 0, -1):
            if A[j] < A[j - 1]:
                tmp = A[j]
                A[j] = A[j - 1]
                A[j - 1] = tmp
                cnum += 1
                flag = True
    print " ".join([str(t) for t in A])
    print cnum

if __name__ == "__main__":
    N = input()
    A = map(int, raw_input().split())
    bubbleSort(A, N)

Measured memory_bytes: 6332
N = int(input())
An = list(map(int, input().split()))
An = [-1] + An
Bn = list(map(int, input().split()))
Bn = [-1] + Bn
Cn = list(map(int, input().split()))
Cn = [-1] + Cn

count = 0
for i in range(1, N + 1):
    count += Bn[An[i]]
    if i > 1 and An[i] == An[i - 1] + 1:
        count += Cn[An[i - 1]]

print(count)


Measured memory_bytes: 38256