akhauriyash/Code-Regression huggingface dataset:
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.stream.IntStream;
import java.util.StringTokenizer;
import java.io.IOException;
import java.util.InputMismatchException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        BStringRotation solver = new BStringRotation();
        solver.solve(1, in, out);
        out.close();
    }

    static class BStringRotation {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            String s = in.nextString();
            String t = in.nextString();

            out.println(IntStream.range(0, s.length()).anyMatch(i -> t.equals(s.substring(i, s.length()) + s.substring(0, i))) ? "Yes" : "No");
        }

    }

    static class InputReader {
        private BufferedReader br;
        private StringTokenizer st;

        public InputReader(InputStream inputStream) {
            br = new BufferedReader(new InputStreamReader(inputStream));
            st = new StringTokenizer("");
        }

        public String nextString() {
            while (!st.hasMoreTokens()) {
                try {
                    st = new StringTokenizer(br.readLine(), " ");
                } catch (IOException e) {
                    throw new InputMismatchException();
                }
            }
            return st.nextToken();
        }

    }
}



Measured memory_bytes: 26836
#include <bits/stdc++.h>
#include <string>
#include <stdio.h>
#include <cstdlib>

using namespace std;

int main() {
    int a = 0;
    long int b = 0;
    cin >> a;
    for (int i = 0; i < a ; i++){
        if ((i+1) % 5 != 0) {
            if ((i+1) % 3 != 0 ){
                b = b + i + 1;
            }
        }
    }
    cout << b;
}

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

int main() {
  int a, b, c, k;
  cin >> a >> b >> c >> k;
  int xa = min(a,k);
  k -= xa;
  int xb = min(b,k);
  k -= xb;
  int xc = k;
  int ans = xa - xc;
  cout << ans << endl; 
  return 0;
}

Measured memory_bytes: 3552
n = int(input())
def minustwo(n,l):
    if n == 0:
        if l == []:
            return [0]
        return l
    else:
        odd = n % 2
        l.append(odd)
        return minustwo((-1)*(n-odd)//2,l)
l = minustwo(n,[])
l.reverse()
for c in l:
    print(c, end='')
print()


Measured memory_bytes: 2940
<?php
$sc = new Scanner();

$count = $sc->next();
$train = $sc->next();
$taxi = $sc->next();


$train_total = $train * $count;

$min = $train_total;
if ($train_total > $taxi) {
    $min = $taxi;
}

out::println($min);


class Scanner
{
    private $arr = [];
    private $count = 0;
    private $pointer = 0;

    public function next()
    {
        if ($this->pointer >= $this->count) {
            $str = trim(fgets(STDIN));
            $this->arr = explode(' ', $str);
            $this->count = count($this->arr);
            $this->pointer = 0;
        }
        $result = $this->arr[$this->pointer];
        $this->pointer++;
        return $result;
    }

    public function hasNext()
    {
        return $this->pointer < $this->count;
    }

    public function nextInt()
    {
        return (int)$this->next();
    }

    public function nextDouble()
    {
        return (double)$this->next();
    }
}

class out
{
    public static function println($str = "")
    {
        echo $str . PHP_EOL;
    }
}

Measured memory_bytes: 4728
#include<iostream>
#include<vector>
#include<algorithm>
#include<iomanip>
typedef long long ll;
using namespace std;
#define INF (1 << 30)
#define INFLL (1LL << 60)
#define rep(i, n) for(int i=0; i<(n); ++i)

int main()
{
	int N, Q; cin >> N >> Q;
	vector<ll> A(N);
	rep(i, N) cin >> A[i];

	auto calc = [&](ll x) {
		ll ans = 0, sum = 0;
		int r = 0;
		for (int l = 0; l < N; ++l) {
			while (r < N && sum + A[r] <= x) {
				sum += A[r];
				++r;
			}
			ans += (ll)r - l;
			if (r == l) ++r;
			else sum -= A[l];
		}
		return ans;
	};
	rep(i, Q) {
		ll x; cin >> x;
		cout << calc(x) << endl;
	}
	return 0;
}



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

#define pb push_back
#define ff first
#define ss second

typedef long long ll;
typedef pair<int, int> pii;

char t;

int main() {
	ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
	cin >> t;
	if (t == 'A')
		cout << 'T';
	if (t == 'C')
		cout << 'G';
	if (t == 'G')
		cout << 'C';
	if (t == 'T')
		cout << 'A';
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define debug(x) cerr << #x << " " << (x) << endl
using namespace std;

const int N = 1000005;
const long long mod = 1000000007ll;

int n;
long long fac[N], inv_fac[N], inv[N], pw[N], f[N][3], ans = 0ll;
long long binom (int a, int b) {
	return fac[a] * inv_fac[b] % mod * inv_fac[a - b] % mod;
}
int main () {
	scanf("%d", &n);

	fac[0] = 1ll;
	for (int i = 1; i <= n; i++) fac[i] = fac[i - 1] * i % mod;

	inv[1] = 1ll;
	for (int i = 2; i <= max(n, 3); i++) inv[i] = (mod / i) * (mod - inv[mod % i]) % mod;

	inv_fac[0] = 1ll;
	for (int i = 1; i <= n; i++) inv_fac[i] = inv_fac[i - 1] * inv[i] % mod;

	pw[0] = 1ll;
	for (int i = 1; i <= n; i++) pw[i] = pw[i - 1] * inv[3] % mod;

	f[0][0] = 1ll, f[0][1] = f[0][2] = 0ll;
	for (int i = 1; i <= n; i++) {
		f[i][0] = (f[i - 1][1] + f[i - 1][2]) % mod;
		f[i][1] = (f[i - 1][2] + f[i - 1][0]) % mod;
		f[i][2] = (f[i - 1][0] + f[i - 1][1]) % mod;
	}

	for (int i = 1; i <= n; i++) {
		ans = (ans + binom(n, i) * pw[n - 1] % mod * f[i][1] % mod * inv[3] % mod * inv[n] % mod * inv[i]) % mod;
	}

	printf("%lld\n", ans);
	return 0;
}



Measured memory_bytes: 54912
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define pb push_back
#define fi first
#define se second
typedef pair<ll,ll> P;
#define Mod 1000000007
using VP = vector<P>; using VVP = vector<VP>;
using VI = vector<ll>; using VVI = vector<VI>; using VVVI = vector<VVI>;
#define INF 1ll<<59

int main(){
    ll i,j;
    ll n;
    cin>>n;
    string s;
    cin>>s;  // なんでも関係ない

    VVI dp(n+1,VI(n+2,0));  //dp[i][j] i操作で長さjの押し方
    dp[0][0]=1;
    for(i=1;i<=n;i++){
        for(j=0;j<=n;j++){
            if(j==0) dp[i][j]=dp[i-1][1]+dp[i-1][0];
            else {
                dp[i][j]=2*dp[i-1][j-1]+dp[i-1][j+1];
            }
            dp[i][j]%=Mod;
        }
    }
    ll ans=dp[n][s.size()];

    ll mt=(1000000007+1)/2;
    for(i=0;i<s.size();i++){
        ans*=mt;
        ans%=Mod;
    }
    cout<<ans<<endl;
    
}

Measured memory_bytes: 195968
#include<bits/stdc++.h>
using namespace std;
#define inf 1e9
#define ll long long
#define ull unsigned long long
#define M 1000000007
#define P pair<int,int>
#define PLL pair<ll,ll>
#define FOR(i,m,n) for(int i=m;i<n;i++)
#define RFOR(i,m,n) for(int i=m;i>=n;i--)
#define rep(i,n) FOR(i,0,n)
#define rrep(i,n) RFOR(i,n,0)
#define all(a) a.begin(),a.end()
const int vx[4] = {0,1,0,-1};
const int vy[4] = {1,0,-1,0};
#define PI 3.14159265


void f(int w,int h){
  string s[100];
  int sx,sy;

  rep(i,h){
    cin>>s[i];
    rep(j,w){
      if(s[i][j]=='@'){
        sx=j;sy=i;
      }
    }
  }

  bool a[100][100]={};
  queue<P> p;
  p.push(P(sx,sy));
  int ans=1;
  while(p.size()){
    P q = p.front(); p.pop();
    rep(i,4){
      int x = q.first+vx[i];
      int y = q.second+vy[i];
      if(0<=x&&x<w&&0<=y&&y<h){
        if(s[y][x]=='.'&&!a[y][x]){
          ans++;
          a[y][x]=true;
          p.push(P(x,y));
        }
      }
    }
  }

  cout<<ans<<endl;
}



int main(){
  
  while(1){
    int n,m;
    cin>>n>>m;
    if(n==0) break;
    f(n,m);
  }

  return 0;
}


Measured memory_bytes: 3032
#include <bits/stdc++.h>
using namespace std;
int main(){
  string s;
  cin >> s;
  int kati = 0;
  for(int i=0;i<s.size();i++){
    if(s[i]=='o'){
      kati++;
    }
  }
  if(kati+15-s.size()>=8){
    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);
    int n, m;
    cin >> n >> m;
    if (n == m)
        cout << "Yes" << endl;
    else
        cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define gcd(m,n) __gcd(m,n)
#define lcm(m,n) m*(n/gcd(m,n))
#define fast std::ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define pi acos(-1.0)
#define endl '\n'
#define MOD 1000000007
#define ull unsigned long long
#define ll long long
#define ld long double
#define pb push_back
#define dbg(x) cout << #x << "  " << x << endl;

ll power(ll base, ll exp) 
{ll res=1;while(exp>0) {if(exp%2==1) res=(res*base);base=(base*base);exp/=2;}return res;}
ll mod(ll a, ll b) {return (a % b + b) % b;}
using namespace std;

int main() 
{
	fast; 
	string s1,s2,s3; cin>>s1>>s2>>s3;
	cout << (char)toupper(s1[0]) << (char)toupper(s2[0]) << (char)toupper(s3[0]) << endl;
	return 0;
}

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

using namespace std;

typedef long long int lint;

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

    map <char, int> cnt;
    for (auto it: str)
        cnt[it] |= 1;

    if (cnt['N'] + cnt['S'] == 1)
        cout << "No\n";
    else if (cnt['E'] + cnt['W'] == 1)
        cout << "No\n";
    else
        cout << "Yes\n";
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <string>
#include <queue>
#include <numeric>
#include <ctype.h>
#include <limits>
#include <iomanip>

#define rep(i,n) for (int i = 0; i < n; i++)
#define all(x) (x).begin(),(x).end()
using namespace std;

typedef long long ll;

int main()
{
	int a, b;
	cin >> a >> b;
	int ans = -1;
	if (a < 10 && b < 10)ans = a * b;
	cout << ans;
	return 0;
}

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

#define debug(x) cout <<"DEBUG"<<" "<< #x << ":" << x << '\n'
#define rep(i,n) for(int i = 0; i < ((int)(n)); i++)   // 0-indexed昇順
#define rep1(i,n) for(int i = 1; i <= ((int)(n)); i++) // 1-indexed昇順
#define rrep(i,n) for(int i = ((int)(n)-1); i >= 0; i--)  // 0-indexed降順
#define rrep1(i,n) for(int i = ((int)(n)); i >= 1; i--)   // 1-indexed降順
#define all(x) (x).begin(),(x).end()

using namespace std;

template<typename T>
using vec = vector<T>;
using i32 = int_fast32_t;
using i64 = int_fast64_t;
using u32 = uint_fast32_t;
using u64 = uint_fast64_t;
using ll = long long;
using ld = long double;
using vi = vec<int_fast32_t>;
using vl = vec<int_fast64_t>;
using vld = vec<ld>;
using vii = vec<vi>;  // 2次元配列
using PII = pair<int_fast32_t, int_fast32_t>;

template<class T>
using maxheap = std::priority_queue<T>;
template<class T>
using minheap = std::priority_queue<T, std::vector<T>, std::greater<T>>;

template<class T,class U> inline bool chmax(T &a, const U &b){if(a<b){a=b;return 1;}return 0;}
template<class T,class U> inline bool chmin(T &a, const U &b){if(a>b){a=b;return 1;}return 0;}

const ld Pi = std::acos(-1.0L);
constexpr ll infll = (1LL<<62)-1;
constexpr int inf = (1<<30)-1;
const int mod = 1000000007;
// const int mod = 998244353;


/*FUNCs=================================================*/


/*MAIN==================================================*/
signed main(){
    int START_TIME = clock();
    cin.tie(nullptr);
    ios::sync_with_stdio(false);   //cin cout 高速化
    cout << fixed << setprecision(15);

    string s, t;
    double n,m,x,y;
    cin >>  n;



    cout << n*2*Pi     << '\n';

    // printf("ExecutionTime: %d /ms\n",1000*(int)((clock()-START_TIME)/CLOCKS_PER_SEC));
}


Measured memory_bytes: 3840
#include <bits/stdc++.h>
#define int llint
#define rep(i, a, n) for(int (i) = (int)(a);(i) < (int)(n);++(i))
#define repe(i, a, n) for(int (i) = (int)(a);(i) <= (int)(n);++(i))
#define repif(i, a, x) for(int (i) = (int)(a);(x);++(i))
#define repr(i, a, n) for(int (i) = (int)(a);(i) > (int)(n);--(i))
#define reper(i, a, n) for(int (i) = (int)(a);(i) >= (int)(n);--(i))
#define chmax(a, b) a = max(a, b)
#define chmin(a, b) a = min(a, b)
#define SIZE(x) ((int)(x).size())
#define ALL(x) (x).begin(), (x).end()
#define RNG(x, a, n) &((x)[a]), &((x)[n])
#define ADD(a, b) ((((a)%MOD)+((b)%MOD))%MOD)
#define MUL(a, b) ((((a)%MOD)*((b)%MOD))%MOD)
#define CEIL(x) ((int)ceil(((double)x)))
#define UNIQUE(x) (x).erase(unique(ALL((x))), (x).end())
#define YES cout << "YES" << endl
#define NO cout << "NO" << endl
#define Yes cout << "Yes" << endl
#define No cout << "No" << endl
#define yes cout << "yes" << endl;
#define no cout << "no" << endl;
#define fcout cout << fixed << setprecision(10)
#define pb push_back
#define pf push_front
#define mp make_pair
#define mt make_tuple
#define lb lower_bound
#define ub upper_bound
#define fi first
#define se second
#define EPS (1e-20)
#define INF 2147483647
#define MOD 1000000007
using llint = long long;
using VI = std::vector<int>;
using PII = std::pair<int, int>;
using SI = std::set<int>;
using MII = std::map<int, int>;
using TIII = std::tuple<int, int, int>;
using VLL = std::vector<llint>;
using MCI = std::map<char, int>;
using namespace std;


int N;
vector<PII> g[100010];
int Q, K;
int x, y;
int dist[100010];


void dfs(int v = K, int p = -1LL, int d = 0LL){
	dist[v] = d;
	for(PII n : g[v])
		if(n.fi != p) dfs(n.fi, v, d+n.se);
}


signed main(){
	cin >> N;
	rep(i, 0, N-1){
		int a, b, c;
		cin >> a >> b >> c;
		g[a].pb({ b, c });
		g[b].pb({ a, c });
	}

	cin >> Q >> K;

	dfs();

	rep(i, 0, Q) cin >> x >> y, cout << dist[x]+dist[y] << endl;

	return 0;
}

Measured memory_bytes: 14336
#include <bits/stdc++.h>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cstring>
#include <chrono>
#include <complex>
#define endl "\n"
#define ll long long int
#define vi vector<int>
#define vll vector<ll>
#define vvi vector < vi >
#define pii pair<int,int>
#define pll pair<long long, long long>
#define mod 1000000007
#define inf 1000000000000000001;
#define all(c) c.begin(),c.end()
#define mp(x,y) make_pair(x,y)
#define mem(a,val) memset(a,val,sizeof(a))
#define eb emplace_back
#define pb push_back
#define f first
#define s second

using namespace std;
int main(){
	std::ios::sync_with_stdio(false);
	int n;
	cin >> n;
	int a[n][3];
	for (int i = 0; i < n; ++i)
	{
		for (int j = 0; j < 3; ++j)
		{
			cin >> a[i][j];
		}
	}
	int dp[n][3];
	int ans=0;
	for (int i = 0; i < n; ++i)
	{
		for (int j = 0; j < 3; ++j)
		{
			dp[i][j]=a[i][j];
		}
	}
	for(int i=n-2;i>=0;i--){
		dp[i][0]+=max(dp[i+1][1],dp[i+1][2]);
		dp[i][1]+=max(dp[i+1][0],dp[i+1][2]);
		dp[i][2]+=max(dp[i+1][0],dp[i+1][1]);
	}

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

Measured memory_bytes: 2560
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <iostream>
#include <algorithm>
#define MOD 1000000007
using namespace std;
typedef long long ll;

template <typename Tp> inline void getint(Tp &num){
	register int ch, neg = 0;
	while(!isdigit(ch = getchar())) if(ch == '-') neg = 1;
	num = ch & 15;
	while(isdigit(ch = getchar())) num = num * 10 + (ch & 15);
	if(neg) num = -num;
}

int N, ans = 1;
char str[200005];

int main(){
	getint(N), scanf("%s", str); int cnt = 1;
	if(str[0] == 'W') return puts("0"), 0;
	for(register int i = 1, cur = 1; i < (N << 1); i++){
		cur ^= str[i] == str[i - 1];
		if(cur) cnt++; else ans = ans * (ll)cnt-- % MOD;
	}
	for(register int i = 1; i <= N; i++) ans = ans * (ll)i % MOD;
	return printf("%d\n", cnt ? 0 : ans), 0;
}

Measured memory_bytes: 384
import Data.List

main = do
  li <- getLine
  let n = read li
  let ans = compute n
  print ans

compute :: Int -> Int
compute n = a + b - 2
  where
    pfs = group $ primeFactors n
    (a,b) = getmin $ loop [(1,1)] pfs

loop abs [] = abs
loop abs (ps:pss) = loop abs1 pss
  where
    pns = scanl (*) 1 ps
    abs1 = [ (a*p,b*q) | (a,b) <- abs, (p,q) <- zip pns (reverse pns) ]

getmin ps = snd $ minimum [ (abs (a-b),(a,b)) | (a,b) <- ps ]

primes = 2 : 3 : 5 : sieve [(9,3),(10,5)] [7,9..]

sieve ((q,p):qps) xxs@(x:xs) =
  case compare q x of
    LT -> sieve qps1 xxs
    EQ -> sieve qps1 xs
    GT -> x : sieve (insert (x+x,x) qps) xs
  where
    qps1 = insert (q+p,p) qps

primeFactors n = loop n primes
  where
    loop 1 _ = []
    loop n pps@(p:ps)
      | r == 0 = p : loop q pps
      | q < p  = [n]
      | True   = loop n ps
      where (q,r) = divMod n p

Measured memory_bytes: 1020
n = int(input())
As = list(map(int,input().split()))

tmp_sum = 0
diffs_by_plus = 0
for i in range(n):
    min_val = (-1) ** i  # start by plus
    tmp_sum += As[i]
    if i % 2 == 0 and tmp_sum <= 0:
        diffs_by_plus += abs(min_val - tmp_sum)
        tmp_sum = min_val
    elif i % 2 != 0 and tmp_sum >= 0:
        diffs_by_plus += abs(min_val - tmp_sum)
        tmp_sum = min_val


tmp_sum = 0
diffs_by_minus = 0
for i in range(n):
    min_val = (-1) ** (i + 1)  # start by plus
    tmp_sum += As[i]
    if i % 2 != 0 and tmp_sum <= 0:
        diffs_by_minus += abs(min_val - tmp_sum)
        tmp_sum = min_val
    elif i % 2 == 0 and tmp_sum >= 0:
        diffs_by_minus += abs(min_val - tmp_sum)
        tmp_sum = min_val


print(min(diffs_by_minus,diffs_by_plus))

Measured memory_bytes: 14468
#include <iostream>
#include <algorithm>
#include<cmath>
#include<cstring>
#include<cstdio>
#include<cstdlib>
#include<vector>
#include<iomanip>
#define sqr(x) (x)*(x)
using namespace std;
long long n,m,i,j,dp[1005],a[1005],pre[1005],ans=0;
bool bo;
vector<long long> ss,ss2;
void get(int x,int y)
{
	ss2.push_back(x);
	if (x<=0) return;
	get(pre[x],y-1);
}
int main()
{
	ios_base::sync_with_stdio(0);
	cin>>n;
	for (i=1;i<=n;i++)
	{
		cin>>a[i];
		if (a[i]>0) bo=1;
	}
	if (bo==0)
	{
		long long mx=1;
		for (i=2;i<=n;i++) if (a[i]>a[mx]) mx=i;
		cout<<a[mx]<<endl;
		cout<<n-1<<endl;
		for (i=1;i<mx;i++) cout<<1<<' ';
		for (i=n-mx+1;i>1;i--) cout<<i<<endl;
		return 0;
	}
	for (i=1;i<=n;i++)
	{
		for (j=1;i-j>=0;j+=2)
		{
			if (i-j-1==-1)
			{
				if (0>dp[i])
				{
					pre[i]=-1;
					dp[i]=0;
				}
			}
			else
			{
				if (dp[i-j-1]>dp[i])
				{
					pre[i]=i-j-1;
					dp[i]=dp[i-j-1];
				}
			}
		}
		dp[i]+=a[i];
		if (dp[i]>dp[ans]) ans=i;
	}
	cout<<dp[ans]<<endl;
	for (i=n;i>ans;i--) ss.push_back(i);
	i=ans;
	if (pre[ans]>0) for (i=ans;pre[i]>0;i=pre[i])
	{
		for (j=(i+pre[i])/2;j>pre[i];j--)
		{
			ss.push_back(j);
		}
	}
	for (j=1;j<i;j++) ss.push_back(1);
	cout<<ss.size()<<endl;
	for (i=0;i<ss.size();i++) cout<<ss[i]<<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++)
typedef long long unsigned int llong;
int a_max = 1e5;

int main(){
    int n;
    cin >> n ;
    int tmp;
    vector<int> A(a_max + 1,0);
    REP(i,n){
        scanf("%d",&tmp);
        if(tmp!=0) A[tmp-1]+=1;
        A[tmp]+=1;
        if(tmp!=a_max) A[tmp+1]+=1;
    }

    auto itr = max_element(A.begin(),A.end());
    cout << *itr << endl;
    
}

Measured memory_bytes: 640
import java.util.*;

public class Main {
	public static void main(String[] args) throws Exception{
		Scanner scn = new Scanner(System.in);
		int k = scn.nextInt();
		int s = scn.nextInt();
      	int count = 0;
      	for(int x=0; x<=k; ++x){
        	for(int y=0; y<=k; ++y){
	    		if(s>=x+y && s-(x+y)<=k){
            		count = count + 1;
           		}
        	}
    	}
      	System.out.println(count);
	}
}


Measured memory_bytes: 35644
#include<iostream>
#include <list>
#include<stack>
#include<queue>
#include <vector>
#include <set>
#include<algorithm>
#include<math.h>
#include<stdlib.h>
#include<string>
#include <functional>
#include<fstream>
#include<numeric>

#define FOR(k,m,n) for(int (k)=(m);(k)<(n);(k)++)
#define REP(i,n) FOR((i),0,(n))
#define LL long long
#define CLR(a) memset((a),0,sizeof(a))
#define SZ(x) (int((x).size()))
#define WAITING(str) int str;std::cin>>str;
#define DEBUGING(str) cout<<str<<endl
using namespace std;

const LL MOD = 1000000007;// 10^9+7
const int INF = (1 << 30);

struct Team {
	Team(int id_, int P) {
		id = id_;
		times.resize(P, INF);
		penalties.resize(P, 0);
	}

	int id;
	vector<int> times;
	vector<int> penalties;

	pair<int, int> score() const{
		int solveNum = 0;
		int penalty = 0;

		for (int time : times) {
			if (time != INF) {
				solveNum++;
				penalty += time;
			}
		}
		REP(i, times.size()) {
			if (times[i] != INF) {
				penalty += 20 * penalties[i];
			}
		}

		return { -solveNum,penalty };
	}

	const bool operator < (const Team r)const {
		if (score() == r.score()) {
			return id > r.id;
		}
		else {
			return score() < r.score();
		}
	}
};

//デバッグ
void debug()
{
	int N;
	cin>>N;
}


//メイン関数
int main()
{
	while (true) {
		int M, T, P, R;
		cin >> M >> T >> P >> R;
		if (M == 0)break;

		vector<Team> teams;
		REP(i, T) {
			teams.push_back(Team(i + 1, P));
		}
		REP(i, R) {
			int m, t, p, j;
			cin >> m >> t >> p >> j;
			t--;
			p--;
			if (j == 0) {
				teams[t].times[p] = m;
			}
			else {
				teams[t].penalties[p]++;
			}
		}
		sort(teams.begin(), teams.end());

		//output
		REP(i, T) {
			cout << teams[i].id;
			if (i != T - 1) {
				if (teams[i].score() == teams[i + 1].score()) {
					cout << "=";
				}
				else {
					cout << ",";
				}
			}
		}
		cout << endl;
	}
	//debug();
	
	return 0;
}




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

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

using namespace std;

const int inf = ((1 << 30) - 1) * 2 + 1;

int n;
int t[(1 << 18) - 1];

void init(int* t){
	fill_n(t, (1 << 18) - 1, inf);
}

int updt(int* t, int i, int x, int k, int l, int r){
	if(r <= i || i < l){
		return t[k];
	}
	if(i <= l && r <= i + 1){
		return t[k] = x;
	}
	int m = (l + r) / 2;
	return t[k] = min(
		updt(t, i, x, 2 * k + 1, l, m),
		updt(t, i, x, 2 * k + 2, m, r)
	);
}
void updt(int* t, int i, int x){
	updt(t, i, x, 0, 0, n);
}

int qry(int* t, int a, int b, int k, int l, int r){
	if(r <= a || b <= l){
		return inf;
	}
	if(a <= l && r <= b){
		return t[k];
	}
	int m = (l + r) / 2;
	return min(
		qry(t, a, b, 2 * k + 1, l, m),
		qry(t, a, b, 2 * k + 2, m, r)
	);
}
int qry(int* t, int a, int b){
	return qry(t, a, b, 0, 0, n);
}

int main(){
	int q;
	cin >> n >> q;
	init(t);
	rep(i, q){
		int c, x, y;
		cin >> c >> x >> y;
		if(c){
			cout << qry(t, x, y + 1) << endl;
		}
		else{
			updt(t, x, y);
		}
	}
	return 0;
}

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

int main(){
  int goukei = 0,n;
  int a[100100] = {0};
  cin >> n;
  for(int i = 1;i <= n;i++){
    cin >> a[i];
    goukei += abs(a[i-1] - a[i]);
  }
  goukei += abs(a[n]);
  int kekka[100100];
  for(int i = 1;i <= n;i++){
    kekka[i] = goukei - abs(a[i+1] -a[i]) - abs(a[i] - a[i-1]) + abs(a[i+1] - a[i-1]);
    cout << kekka[i] << endl;
  }
}

Measured memory_bytes: 1664
#include <bits/stdc++.h>
#define MOD 1000000007
#define INF 1001001001
#define LINF 1001001001001001001
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define bit(n) (1LL<<(n))
using namespace std;

typedef pair<int, int> P;
typedef pair<long long, long long> LLP;
typedef long long ll;

int main() {

    int a;
    cin >> a;
    int ans = a + a * a + a * a * a;
    cout << ans << endl;
    return 0;
}

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

#define pb push_back
#define mk make_pair
#define sc second
#define fr first

using namespace std;

typedef long long ll;

const int N = (int) 1e6 + 5;
const int mod = (int) 1e9 + 7;

int n,c,k,a[N],ans;

int main(){
        cin >> n >> c >> k;

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

        sort(a + 1,a + n + 1);

        int i = 1;

        while(i <= n){
                int pos = upper_bound(a + 1,a + n + 1,a[i] + k) - a - 1;
                if(pos - i + 1 > c)
                        i += c,ans ++;
                else{
                        if(pos != i)
                                i = pos + 1,ans ++;
                        else
                                i ++,ans ++;
                }
        }
        cout << ans << endl;
        return 0;
}


Measured memory_bytes: 640
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int main(void) {
    int n,i,j,k;
    long long int ans,r=0,g=0,b=0;
    char s[4100];
    (void)scanf("%d",&n);
    (void)scanf("%s",&s[1]);
    for(i=1;i<=n;i++){
      if(s[i]=='R')r++;
      if(s[i]=='G')g++;
      if(s[i]=='B')b++;
    }
    ans=r*g*b;
    for(i=1;i<=n-2;i++){
      for(j=i+1;j<=n-1;j++){
        k=2*j-i;
        if(j<k&&k<=n){
          if((s[i]!=s[j])&&(s[i]!=s[k])&&(s[j]!=s[k]))
            ans--;
        }
      }
    }
    printf("%lld\n",ans);
    return 0;
}

Measured memory_bytes: 1732
#include<iostream>
using namespace std;
char cc[100005];
int main() {
	int N,cnt=0;
	char c;
	cin >> N;
	cin >> cc[1];
	for (int i = 2; i <= N; i++) {
		cin >> c;
		cc[i] = c;
		if (c != cc[i - 1])
			cnt++;
	}
	cout << cnt+1;
	return 0;
}

Measured memory_bytes: 384
import scala.collection.mutable.ArrayBuffer
import scala.io.StdIn

object Main extends App {
  val Array(n, m) = StdIn.readLine().split(" ").map(_.toInt)
  val h = StdIn.readLine().split(" ").map(_.toInt)
  val g = new Array[ArrayBuffer[Int]](n).map(_ => new ArrayBuffer[Int](0).addOne(0))
  for (_ <- 0 until m) {
    val (x, y) = readIntPair
    g(x - 1) += h(y - 1)
    g(y - 1) += h(x - 1)
  }

  val cnt = g
    .zipWithIndex
    .map { case (list, v) => list.max < h(v) }
    .count(identity)

  println(cnt)

  def readIntPair: (Int, Int) = {
    val Array(x, y) = StdIn.readLine().split(" ").map(_.toInt)
    (x, y)
  }
}

Measured memory_bytes: 83780
#include<stdio.h>

int pnCheck(int);

int main() {
	int i,j;
	int data ,cod;

	scanf("%d", &data);
	printf("%d:", data);
	cod = data;
	i = 2;
	while (data%i==0) {
		data /= 2;
		printf(" 2");
	}

	for (i = 3; i <= data && i*i<=cod; i+=2) {	//?´???°?????????????????????
		if (pnCheck(i)) {
			while (data%i==0) {
				data /= i;
				printf(" %d", i);
			}
		}
	}
	if (data != 1)printf(" %d", data);
	printf("\n");
	return 0;
}

int pnCheck(int x) {	//depth??????????????????
	//if(x<2)return 0;	//?????°???????????????????????´??°??¨????????¨???????¨????
	int i;
	int fl = 0;

	for (i = 3; i*i <= x; i += 2) {
		if (pnCheck(i)) {
			if (fl = (x % i == 0)) break;
		}
	}
	return !fl;
}

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

int main(){
	ios_base::sync_with_stdio(0);cin.tie(0);
	int q,i,j,k,h;
	long long a,b,btop=0,yaz,sagtop=0,soltop=0,say=0;
	multiset<long long> ms;
	cin>>q;
	auto it=ms.begin();
	for(i=1;i<=q;i++)
	{
		cin>>h;
		if(h==1)
		{
			say++;
			cin>>a>>b;
			btop+=b;
			ms.insert(a);
			if(say==1) { it=ms.begin(); soltop+=a; }
			else
			{
				if(a>*it)
				{
					sagtop+=a;
					if(say%2==1) { it++; sagtop-=*it; soltop+=*it; }
				}
				else
				{
					soltop+=a;
					if(say%2==0) 
					{  
						sagtop+=*it; soltop-=*it; 
						if(a!=*it && say%2==0) it--;
					}
					else if(a==*it) it++;	
				}
			}
			yaz=(*it * ((say+1)/2) - soltop) + (sagtop - *it * (say/2)) + btop;
			
		}
		else
		{
			cout <<*it<<' '<<yaz<<endl;
		}
	}
	//  for (auto it = ms.begin(); it != ms.end(); it++) 
    //    cout << *it << " "; 
	return 0;
}

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

vector<vector<vector<int>>> a(2, vector<vector<int>>(0, vector<int>(0)));
int f(int n){
    a.at(0).push_back({1});
    rep(ii, n-1){
    int k = a.at(ii%2).size();
    int l = a.at(ii%2).at(0).size();
    rep(i, k) a.at(ii%2).at(i).push_back(l+1);
    rep(i, k){//2
      rep(j, l+1){//3
        a.at((ii+1)%2).push_back({});
        rep(m, l+1) a.at((ii+1)%2).at(i*(l+1)+j).push_back(a.at(ii%2).at(i).at((m+j)%(l+1)));
      }
    }
    while(a.at(ii%2).size() != 0){
      a.at(ii%2).pop_back();
    }
  }
  sort(a.at((n+1)%2).begin(), a.at((n+1)%2).end());
  return 0;
}

int main(){
	int n;
	cin >> n;
    vector<int> ns0(n);
    vector<int> ns1(n);
    rep(i, n) cin >> ns0.at(i);
    rep(i, n) cin >> ns1.at(i);
    f(n);
    int c, d;
    int f0 = 0;
    int f1 = 0;
    rep(i, a.at((n+1)%2).size()){
      f0 = 0;
      f1 = 0;
      rep(j, n){
        if(a.at((n+1)%2).at(i).at(j) != ns0.at(j)) f0 = 1;
        if(a.at((n+1)%2).at(i).at(j) != ns1.at(j)) f1 = 1;
      }
      if(f0 == 0) c = i+1;
      if(f1 == 0) d = i+1;
    }
    cout << abs(c-d) << endl;
    return 0;
}

Measured memory_bytes: 3640
#include "bits/stdc++.h"
#define FI first.first
#define SE first.second
#define TH second
#define fi first
#define se second
#define th second

using namespace std;

template<typename T>
string to_string(const vector<T>& vc, int w) {
	if(vc.empty()) return "";
	if(w + 1 == vc.size()) return to_string(vc[w]);
	return to_string(vc[w]) + "," + to_string(vc, w + 1);
}

template<typename T>
string to_string(const vector<T>& vc) {
	return "{" + to_string(vc, 0) + "}";
}

void debug_out() { cerr << endl; }
 
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cerr << " " << to_string(H);
  debug_out(T...);
}
 
#ifdef DEBUG
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif

class DebugStream {}LOG;
template <typename T>DebugStream &operator<<(DebugStream &s, const T&) { return s; }
#ifdef DEBUG
#define LOG clog
#endif

typedef long long ll;
typedef pair<ll, ll> ii;
typedef long double ld;
mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());

const int maxN = 1e5 + 9, maxV = 1e6 + 9, MOD = 1e9 + 7, SQ = 335, lg = 20, bs = 29;

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	#ifdef DEBUG
	freopen("input.txt", "r", stdin);
	#endif

	string str;
	cin >> str;
	int ans;
	if(str == "RRR") ans = 3;
	else if(str == "RSR") ans = 1;
	else ans = count(str.begin(), str.end(), 'R');
	cout << ans << '\n';
}



Measured memory_bytes: 3644
#include <cstdio>
#include <queue>
#include <iostream>
#include <bits/stdc++.h>
#include<stdio.h>
#include<string.h>
#include<fstream>

#define F first
#define S second
#define R cin>>
#define Z class
#define ll long long
#define ln cout<<'\n'
#define in(a) insert(a)
#define pb(a) push_back(a)
#define pd(a) printf("%.10f\n",a)
#define mem(a) memset(a,0,sizeof(a))
#define all(c) (c).begin(),(c).end()
#define iter(c) __typeof((c).begin())
#define rrep(i,n) for(ll i=(ll)(n)-1;i>=0;i--)
#define REP(i,m,n) for(ll i=(ll)(m);i<(ll)(n);i++)
#define rep(i,n) REP(i,0,n)
#define tr(it,c) for(iter(c) it=(c).begin();it!=(c).end();it++)
using namespace std;

int main() {
    cin.tie(0);
   	ios::sync_with_stdio(false);
       
    ll i,j,k,x,y,z;//p,q;
    ll n,m,tmp;
    string s[200000];
    string str;
    ll sum=0;
    ll strr[200005];
    cin>>n;
    double p=(double)n/3;
    
    printf("%.12f",p*p*p);

    return 0;
}

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

#define int long long
#define ll long long
#define f1(i,a,b) for(i=a;i<b;i++)
#define f2(i,a,b) for(i=a;i>=b;i--)
#define endl '\n'
#define pb push_back
#define gp " "
#define ff first
#define ss second
#define mp make_pair

const int mod=1000000007;
int i,j;
ll temp;

int32_t main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    // #ifndef ONLINE_JUDGE
    // 	freopen("/home/akmittal/Desktop/Competitive Programming/in.txt","r",stdin);
    // 	freopen("/home/akmittal/Desktop/Competitive Programming/out.txt","w",stdout);
    // #endif
    int n;
    cin>>n;
    n=n*(n-1)/2;
    cout<<n;
    return 0;
}

Measured memory_bytes: 256
N, P = map(int, input().split())
S = input()

if P == 2:
    ans = 0
    for i, d in enumerate(map(int, S)):
        if d % 2 == 0:
            ans += i+1
    print(ans)
elif P == 5:
    ans = 0
    for i, d in enumerate(map(int, S)):
        if d % 5 == 0:
            ans += i+1
    print(ans)
else:
    mods = [0] * P
    mods[0] = 1
    cur_mod = 0
    for i, digit in enumerate(map(int, S)):
        cur_mod += pow(10, N-i-1, P) * digit
        cur_mod %= P
        mods[cur_mod] += 1

    ans = 0
    for count in mods:
        ans += count * (count - 1) // 2

    print(ans)

Measured memory_bytes: 9440
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define M (2019)
ll l,r,ans=1e9;

int main(){
	scanf("%lld%lld",&l,&r);
	if (r-l>=2019){
		printf("0"); return 0;
	}
	l%=M; r%=M;
	if (l>=r) r+=M;
	for (int i=l;i<r;i++)
		for (int j=i+1;j<=r;j++)
			ans=min(ans,(1ll*i*j)%M);
	printf("%lld",ans);
}


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


int main()
{
	int N;
	cin>>N;
	vector<vector<ll>> a(N,vector<ll>(N));
	vector<vector<ll>> d(N,vector<ll>(N));
	rep(i,N)
	{
		rep(j,N)
		{
			cin>>a[i][j];
			d[i][j]=a[i][j];
		}
	}
	vector<vector<bool>> is_via(N,vector<bool>(N));
	rep(k,N)
	{
		rep(i,N)
		{
			Rep(j,i+1,N)
			{
				if(d[i][k]!=0&&d[k][j]!=0)
				{
					if(d[i][j]==d[i][k]+d[k][j])
					{
						is_via[i][j]=true;
						d[i][j]=d[i][k]+d[k][j];
					}
					else if(d[i][j]>d[i][k]+d[k][j])
					{
						cout<<-1<<endl;
						return 0;
					}
				}
			}
		}
	}
	ll ans=0;
	rep(i,N)
	{
		Rep(j,i+1,N)
		{
			if(!is_via[i][j]) ans+=d[i][j];
		}
	}
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 5024
#!/usr/bin/env python3
from collections import defaultdict
import sys
try:
    from typing import List
except ImportError:
    pass


def solve(N: int, M: int, A: "List[int]", B: "List[int]", C: "List[int]"):
    d = defaultdict(int)
    for Bi, Ci in zip(B, C):
        d[Ci] += Bi

    k = [0] * N
    i = 0
    for key in sorted(d.keys(), reverse=True):
        newi = min(N, i + d[key])
        for j in range(i, newi):
            k[j] = key
        i = newi
        if newi > N:
            break
    print(sum(sorted(A + k, reverse=True)[:N]))


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    M = int(next(tokens))  # type: int
    A = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    B = [int()] * (M)  # type: "List[int]"
    C = [int()] * (M)  # type: "List[int]"
    for i in range(M):
        B[i] = int(next(tokens))
        C[i] = int(next(tokens))
    solve(N, M, A, B, C)


if __name__ == '__main__':
    main()


Measured memory_bytes: 29228
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<utility>
#include<set>
#include<stack>
#include<list>
#include<deque>
#include<bitset>
#include<iomanip>
#include<cstring>
#include<sstream>
#include<cstdio>
#include<cstdlib>
#include<climits>
#include<cmath>
#include<cctype>


#define pb push_back
#define mp make_pair
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define ren(i,a,b) for(int i=a;i>=b;i--)
#define ff first
#define ss second
#define pll pair<long long int,long long int>
#define pii pair<int,int>
#define vll vector<long long int>
#define vii vector<int>
#define gi(n) scanf("%d",&n)
#define gll(n) scanf("%lld",&n)
#define gstr(n) scanf("%s",n)
#define gl(n) cin >> n
#define oi(n) printf("%d",n)
#define oll(n) printf("%lld",n)
#define ostr(n) printf("%s",n)
#define ol(n) cout << n
#define os cout<<" "
#define on cout<<"\n"
#define o2(a,b) cout<<a<<" "<<b
#define all(n) n.begin(),n.end()
#define present(s,x) (s.find(x) != s.end())
#define cpresent(s,x) (find(all(s),x) != s.end())
#define tr(container, it) for(__typeof(container.begin()) it = container.begin(); it != container.end(); it++)
using namespace std;

typedef unsigned long long int ull;
typedef long long int ll;
typedef long double ld;
typedef vector<vector<ll> > mat;

int pr[1000005];

int main()
{ios_base::sync_with_stdio(false);
ll a,b,ans=1;
cin>>a>>b;
pr[0]=1,pr[1]=1;
rep(i,2,1000004)
{
	if(pr[i])continue;
	int c1=0,c2=0;
	while(a%i==0)
	{
		a/=i;
		c1++;
	}
	while(b%i==0)
	{
		b/=i;
		c2++;
	}
	if(c1>0&&c2>0)ans++;
	for(int j=2*i;j<=1000004;j+=i)pr[j]=1;
}
if(a==b&&a>1)ans++;
ol(ans);
return 0;
}



Measured memory_bytes: 4224
import sys
import itertools
input = sys.stdin.readline
sys.setrecursionlimit(100000)


def read_values():
    return map(int, input().split())


def read_index():
    return map(lambda x: x - 1, map(int, input().split()))


def read_list():
    return list(read_values())


def read_lists(N):
    return [read_list() for n in range(N)]


def functional(N, mod):
    F = [1] * (N + 1)
    for i in range(N):
        F[i + 1] = (i + 1) * F[i] % mod
    return F


def main():
    N, M = read_values()
    F = read_lists(M)
    r = range(10) if N == 1 else (range(10, 100) if N == 2 else range(100, 1000))
    for i in r:
        if all(str(i)[f[0] - 1] == str(f[1]) for f in F):
            print(i)
            return
    print(-1)


if __name__ == "__main__":
    main()

Measured memory_bytes: 3064
#include<stdio.h>
int isprime(int n){
    int i;
    for(i = 2; i * i <= n; i ++ ){
        if(n % i == 0)return 0;
    }
    return 1;
}
int main(void){
    const int NUM = 10001;
    int i,n,prime[NUM],p1,q1;
    for(i = 2; i < NUM; i ++ ){
        prime[i] = isprime(i);
    }
    
    while(1){
        scanf("%d",&n);
        if(n == 0)break;
        for(i = n; i >= 2; i --){
            if(prime[i] == 1 && prime[i - 2] == 1){
                    q1 = i;
                    p1 = i - 2;
                    printf("%d %d\n",p1,q1);
                    break;
            }
        }
    }
    return 0;
}

Measured memory_bytes: 640
#include <iostream>
#include <stdlib.h>
#include <string.h>
#include <sstream>
#include <iostream>
#include <math.h>
#include <iomanip>

using namespace std;

string float_to_string(float f, int digits)
{
  if (f == 0) {
    f = 0;
  }
  ostringstream oss;
  oss << setprecision(digits) << setiosflags(ios::fixed) << f;
  return oss.str();
}

void calc_and_output(int *c)
{
  float x = (float)(c[1]*c[5]-c[2]*c[4])/(c[1]*c[3]-c[0]*c[4]);
  float y = (float)(c[0]*c[5]-c[2]*c[3])/(c[0]*c[4]-c[1]*c[3]);

  cout << float_to_string(x, 3) << " " << float_to_string(y, 3) << endl;
}

int main(int argc, char const* argv[])
{
  int c[6];

  string line;
  while (getline(cin, line)) {
    istringstream iss(line);
    int val;
    int c[6];
    for (int i = 0; i < 6; i++) {
      iss >> val;
      c[i] = val;
    };

    calc_and_output(c);
  }

  return 0;
}

Measured memory_bytes: 1304
n = int(input())
a = []
for i in range(n):
  a.append(int(input()))
b = a[0]
c = []
while True:
  if b == 2:
    print(len(c)+1)
    exit()
  if len(c)> n:
    print(-1)
    exit()
  else:
    c.append(b)
    b = a[c[-1]-1]


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

const int DIM = 2005;

int arr[DIM];

int main(void)
{
    ios :: sync_with_stdio(false);
    cin.tie(0); cout.tie(0);
    
    int n, x, y;
    cin >> n >> x >> y;
    
    for (int i = 1; i <= n; ++i)
        cin >> arr[i];
    
    cout << max(abs(arr[n] - y), (n == 1) ? -1 : abs(arr[n - 1] - arr[n]));
    
    return 0;
}


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

int main() {
    ll n, a, b;
    cin >> n >> a >> b;

    ll ans = b * (n - 1) + a - (a * (n - 1) + b) + 1;

    cout << max(ans, 0ll) << endl;
    return 0;
}


Measured memory_bytes: 256
import java.lang.*;
import java.io.*;
import java.util.*;


public class Main {
	
	public static void main(String[] args) throws java.lang.Exception {
		InputStream inputStream = System.in;
		OutputStream outputStream = System.out;
		InputReader in = new InputReader(inputStream);
		PrintWriter out = new PrintWriter(outputStream);
		TaskA solver = new TaskA();
		solver.solve(in, out);
		out.close();
	}
}

class TaskA {
	
	public void solve(InputReader in, PrintWriter out) {
		String sa = in.next(), sb = in.next(), sc = in.next();
		
		if (sa.charAt(sa.length()-1)==sb.charAt(0) && sb.charAt(sb.length()-1)==sc.charAt(0))
			out.println("YES");
		else
			out.println("NO");
	}
}

class InputReader {
	public BufferedReader reader;
	public StringTokenizer tokenizer;
	
	public InputReader(InputStream stream) {
		reader = new BufferedReader(new InputStreamReader(stream), 32768);
		tokenizer = null;
	}
	
	public String next() {
		while (tokenizer==null || !tokenizer.hasMoreTokens()) {
			try {
				tokenizer = new StringTokenizer(reader.readLine());
			} catch (IOException e) {
				throw new RuntimeException(e);
			}
		}
		return tokenizer.nextToken();
	}
	
	public int nextInt() {
		return Integer.parseInt(next());
	}
	
	public long nextLong() {
		return Long.parseLong(next());
	}
	
	public double nextDouble() {
		return Double.parseDouble(next());
	}
}

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

if c == 1 or d == 1:
    print(0)
    exit()

def gcd(a, b):
    while b:
        a, b = b, a % b
    return a

def lcm(a, b):
    return a * b // gcd(a, b)

e = lcm(c, d)

bCount = b // c + b // d - b // lcm(c, d)
aCount = (a - 1) // c + (a - 1) // d - (a - 1) // lcm(c, d)

print(b - a - (bCount - aCount) + 1)

Measured memory_bytes: 3064
import numpy as np
N, M, Q = map(int, input().split())

#input
lst = [[0] * (N + 1) for _ in range(N + 1)]
for _ in range(M):
    L, R = map(int, input().split())
    lst[R][L] += 1

lst = np.array(lst)
# print (lst)

#2次元累積和
for i in range(1, N + 1):
    lst[:,i] += lst[:, i - 1]
for j in range(1, N + 1):
    lst[j,:] += lst[j - 1, :]


#output
for _ in range(Q):
    p, q = map(int, input().split())
    print (lst[q, q] - lst[p-1, q] - lst[q, p-1] + lst[p-1, p-1])

# print (lst)


Measured memory_bytes: 16348
using System;
using System.Collections.Generic;
using System.Linq;

namespace ABC
{
    class Program
    {
        static void Main(string[] args)
        {
            ABC095_B();
        }

        static void ABC095_B()
        {
            var NX = Console.ReadLine().Split(' ').Select(int.Parse).ToList();
            var N = NX[0];
            var X = NX[1];

            var ans = 0;
            var m = new List<int>();
            for (var n = 0; n < N; n++)
            {
                var value = int.Parse(Console.ReadLine());
                m.Add(value);
                X -= value;
                ans++;
            }

            var minm = m.Min();
            while (minm <= X)
            {
                X -= minm;
                ans++;
            }
            Console.WriteLine(ans);
        }
    }
}

Measured memory_bytes: 13396
import java.util.*;

public class Main{      
    public static void main(String[] args)
    {
        Scanner sc = new Scanner(System.in);
        
        String str = sc.nextLine();
        char[] chars = str.toCharArray();
        for (int i=0;i<str.length();i++) {
            if('a'<=chars[i]&&chars[i]<='z')
                chars[i]= Character.toUpperCase(chars[i]);
            else if('A'<=chars[i]&&chars[i]<='Z')
                chars[i]= Character.toLowerCase(chars[i]);
        }
        String str2 = String.valueOf(chars);
        System.out.println(str2);
    }
}



Measured memory_bytes: 25976
#include<stdio.h>

int main(void){

	long int N, i, j;
	long int A[200001], B[200001] = {0};

	scanf("%ld", &N);

	for(i = 1; i < N; i++)
		scanf("%ld", &A[i]);

	for(i = 0; i < N; i++){
		j = A[i] - 1;
		B[j]++;
	}

	for(i = 0; i < N; i++)
		printf("%ld\n", B[i]);

	return 0;

}

Measured memory_bytes: 4852
import java.util.Arrays;

public class Main {

  private static void solve() {
    int n = ni();

    long[] a = nal(n);
    
    
    //x0 + x1 = 2a1
    //x1 + x2 = 2a2
    //xn-1 + x0 = 2an
    
    long x = Arrays.stream(a).sum();
    for (int i = 1; i < n; i += 2) {
      x -= a[i] * 2;
    }
    
    StringBuilder sb = new StringBuilder();
    for (int i = 0; i < n; i ++) {
      sb.append(x + " ");
      x = 2 * a[i] - x;
    }
    
    System.out.println(sb.substring(0, sb.length() - 1));
    
  }

  public static void main(String[] args) {
    new Thread(null, new Runnable() {
      @Override
      public void run() {
        long start = System.currentTimeMillis();
        String debug = args.length > 0 ? args[0] : null;
        if (debug != null) {
          try {
            is = java.nio.file.Files.newInputStream(java.nio.file.Paths.get(debug));
          } catch (Exception e) {
            throw new RuntimeException(e);
          }
        }
        reader = new java.io.BufferedReader(new java.io.InputStreamReader(is), 32768);
        solve();
        out.flush();
        tr((System.currentTimeMillis() - start) + "ms");
      }
    }, "", 64000000).start();
  }

  private static java.io.InputStream is = System.in;
  private static java.io.PrintWriter out = new java.io.PrintWriter(System.out);
  private static java.util.StringTokenizer tokenizer = null;
  private static java.io.BufferedReader reader;

  public static String next() {
    while (tokenizer == null || !tokenizer.hasMoreTokens()) {
      try {
        tokenizer = new java.util.StringTokenizer(reader.readLine());
      } catch (Exception e) {
        throw new RuntimeException(e);
      }
    }
    return tokenizer.nextToken();
  }

  private static double nd() {
    return Double.parseDouble(next());
  }

  private static long nl() {
    return Long.parseLong(next());
  }

  private static int[] na(int n) {
    int[] a = new int[n];
    for (int i = 0; i < n; i++)
      a[i] = ni();
    return a;
  }

  private static char[] ns() {
    return next().toCharArray();
  }

  private static long[] nal(int n) {
    long[] a = new long[n];
    for (int i = 0; i < n; i++)
      a[i] = nl();
    return a;
  }

  private static int[][] ntable(int n, int m) {
    int[][] table = new int[n][m];
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        table[i][j] = ni();
      }
    }
    return table;
  }

  private static int[][] nlist(int n, int m) {
    int[][] table = new int[m][n];
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        table[j][i] = ni();
      }
    }
    return table;
  }

  private static int ni() {
    return Integer.parseInt(next());
  }

  private static void tr(Object... o) {
    if (is != System.in)
      System.out.println(java.util.Arrays.deepToString(o));
  }
}



Measured memory_bytes: 51824
const MOD: usize = 1000000007;

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, ) => {};
    // var... 変数の識別子, $t...型を一つよむ
    ($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
    };
    // 配列の最後のNestではここで型が指定されてparseされる
    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input! {
        n: usize,
        k: usize,
        h: [usize;n],
    }
    let mut h = h;
    h.sort();
    // println!("{:?}", h);
    let mut ans = std::usize::MAX;
    for i in (0..(n - k + 1)) {
        ans = std::cmp::min(h[i + k - 1] - h[i], ans);
    }
    println!("{}", ans);
}


Measured memory_bytes: 6396