akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define ALL(v) v.begin(), v.end()
#define MOD 1000000007
#define MAX 510000
#define rrep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define rep(i, n) for(ll i = 1; i <= (ll)(n); i++)
#define dcout cout<<fixed<<setprecision(15);


using namespace std;
typedef long long int  ll;
typedef pair<int, int> P;


//lcm//
ll gcd(ll x, ll y) {
	if (x == 0) return y;
	return gcd(y%x, x);
}
ll lcm(ll x, ll y) { return x * y / gcd(x, y); }

//a^n mod p//
ll modpow(ll a, ll n, ll p) {
  if (n == 1) return a % p;
  if (n % 2 == 1) return (a * modpow(a, n - 1, p)) % p;
  ll t = modpow(a, n / 2, p);
  return (t * t) % p;
}

//inversemod//
long long modinv(long long a, long long m) {
	long long b = m, u = 1, v = 0;
	while (b) {
		long long t = a / b;
		a -= t * b; swap(a, b);
		u -= t * v; swap(u, v);
	}
	u %= m;
	if (u < 0) u += m;
	return u;
}

//Cmonp//
ll fac[MAX], finv[MAX], inv[MAX];
// 
void COMinit() {
	fac[0] = fac[1] = 1;
	finv[0] = finv[1] = 1;
	inv[1] = 1;
	for (int i = 2; i < MAX; i++) {
		fac[i] = fac[i - 1] * i % MOD;
		inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
		finv[i] = finv[i - 1] * inv[i] % MOD;
	}
}

// 
ll COM(ll n, ll k) {
	if (n < k) return 0;
	if (n < 0 || k < 0) return 0;
	return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

//LARGE n
ll com(ll n,ll m){
    if(n<m || n<=0 ||m<0){
		return 0;
	}
	if( m==0 || n==m){
		return 1;
	}
	ll k=1;
	for(ll i=1;i<=m;i++){
       k*=(n-i+1); 
	   k%=MOD;
	   k*=modinv(i,MOD);
	   k%=MOD;
	}
	return k;
}


////////////////////////////////////////////////////////////////////


ll rad(ll u, ll p){
ll cnt=0;
	while(u%p==0){
		u/=p;
		cnt++;
	}
	return cnt;
}




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

string st;

cout<<0<<endl;
cout<<flush;
cin>>st;
if(st=="Vacant"){
	return 0;
}


int pre=0;
int small=0;
int large=n;
rep(z,19){
	string u;
	int mid=(small+large)/2;
	cout<<mid<<endl;
	cout<<flush;

	cin>>u;
	if(u=="Vacant"){
		return 0;
	}
	if(pre>mid){
		if((pre-mid)%2==0 && u!=st){small=mid;}
		if((pre-mid)%2==0 && u==st){large=mid;}
		if((pre-mid)%2==1 && u!=st){large=mid;}
		if((pre-mid)%2==1 && u==st){small=mid;}
	}
	if(pre<mid){
		if((mid-pre)%2==0 && u!=st){large=mid;}
		if((mid-pre)%2==0 && u==st){small=mid;}
		if((mid-pre)%2==1 && u!=st){small=mid;}
		if((mid-pre)%2==1 && u==st){large=mid;}
	}
	st=u;
	pre=mid;
	}


return 0;

}





Measured memory_bytes: 852
#include <bits/stdc++.h>
#define sz(v)   ((int)(v).size())
#define  all(v)    ((v).begin()),((v).end())
#define  allr(v)    ((v).rbegin()),((v).rend())
#define   pb         push_back
#define   mp         make_pair
#define   mt         make_tuple
//#define   Y            imag()
//#define   X            real()
#define    clr(v,d)      memset( v, d ,sizeof(v))
#define   angle(n)      atan2((n.imag()),(n.real()))
#define   vec(a,b)       ((b)-(a))
//#define   length(a)      hypot( (a.imag()),(a.real()) )
#define   normalize(a)      (a)/(length(a))
//#define    dp(a,b)          (((conj(a))*(b)).real())
//#define    cp(a,b)          (((conj(a))*(b)).imag())
#define    lengthsqrt(a)       dp(a,a)
#define    rotate0( a,ang)    ((a)*exp( point(0,ang) ))
#define    rotateA(about,p,ang)   (rotate0(vec(about,p),ang)+about)
#define    reflection0(m,v)         (conj((v)/(m))*(m))
#define     reflectionA(m,v,p0)     (conj( (vec(p0,v))/(vec(p0,m)) ) * (vec(p0,m)) ) + p0
//#define     same(p1,p2)               ( dp(  vec(p1,p2),vec(p1,p2)) < eps )
#define     PT                    complex<double>
#define outfile freopen("out.out", "w", stdout);
#define infile  freopen("in.in", "r", stdin);
#define PI acos(-1)
typedef  long long     ll ;
typedef  unsigned long long ull;
const double eps= (1e-9);
using namespace std;
int dcmp(long double a,long double b){   return fabsl(a-b)<=eps ? 0: (a>b)? 1:-1  ;}
int getBit(int num, int idx) {return ((num >> idx) & 1) == 1;}
int setBit1(int num, int idx) {return num | (1<<idx);}
ll setBit0(ll num, int idx) {return num & ~(1ll<<idx);}
ll flipBit(int num, int idx) {return num ^ (1<<idx);}
void FS(){ ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);}

int main()
{
    int n,k;
    cin>>n>>k;
    if(k==1)
        cout<<"0\n";
    else
    cout<<(n-k)<<endl;
}






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

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

  
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<string>
#include<numeric>
#define int long long
#define all(x) x.begin(),x.end()
#define maxn 1000000
#define what_is(x) cerr << #x << " is " << x << endl;
const int MOD = 1e9 + 7;
using namespace std;
string abc="abcdefghijklmnopqrstuvwxyz";
int powmod(int a, int b, int MOD = MOD){
    if(!a and !b)    return 1ll;
    if(!a)    return a;
    int res = 1ll;
    b %= (MOD - 1ll), a %= MOD;
    while(b){
        if(b%2 == 1)    res = (res * a) % MOD;
        a = (a * a) % MOD;
        b /= 2;
    }
    return res;
}
int popcount(uint32_t n)
{
    n = n - ((n >> 1) & 0x55555555);
    n = (n & 0x33333333) + ((n >> 2) & 0x33333333);
    return ((n + (n >> 4) & 0xF0F0F0F) * 0x1010101) >> 24;
}
bool check(int n) {return (((double)sqrt(n)-floor((double)sqrt(n)))==0);}
vector<bool> sieve(maxn + 1, true);

void fillprime() {
    sieve[0] = sieve[1] = false;
    for (int i = 2; i <= maxn; ++i) {
        if (sieve[i] && (int) i * i <= maxn) {
            for (int j = i * i; j <= maxn; j += i) {
                sieve[j] = false;
            }
        }
    }
}
void solve() {
     int n;
     cin>>n;
     string s;
     cin>>s;
     int cnt=1;
     for(int i=1;i<n;++i)
     {
         if(s[i]!=s[i-1]) cnt++;
     }
     cout<<cnt;
}
int32_t main() {
    ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);
    //cout<<"Hello World"<<"\n";
    //int t;cin>>t;while(t--)
    solve();

}

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

using namespace std;

int n;
string s;

int main()
{
  cin >> n >> s;
  if((n%2)||(s.substr(0,n/2)!=s.substr(n/2,n/2)))
     cout << "No" << endl;
  else
     cout << "Yes" << endl;
}

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

int main(){
    cin.tie(0);
   	ios::sync_with_stdio(false);
    int imp1,imp2;
    cin >>imp1>>imp2;
    int a[imp1][imp2];
    int b[imp2];
    int c[imp1];
    for (int i = 0; i < imp1; i++){
        for (int j = 0; j < imp2; j++){
            int n;
            cin >> n;
            a[i][j]=n;
        }
    }
    for (int i = 0; i < imp2; i++){
        int n;
        cin >> n;
        b[i]=n;
    }
    for (int i = 0; i < imp1; i++){
        c[i]=0;
        for (int j = 0; j < imp2; j++){
            c[i]+=(a[i][j]*b[j]);
        }
        cout << c[i] << '\n';
    }
}


Measured memory_bytes: 3212
#include<bits/stdc++.h>
#define float double

using namespace std;
float a[3001];
float f[3001][1501];

int main()
{

    int n;
    cin>>n;
    for(int i=1;i<=n;i++)
        cin>>a[i];
    for(int j=0;j<=n/2;j++)
        f[0][j]=1.0;
    for(int i=1;i<=n;i++)
        for(int j=0;j<=n/2;j++)
        {
            if(j>0)
            f[i][j]+=f[i-1][j-1]*(1.0-a[i]);
            f[i][j]+=f[i-1][j]*a[i];
          //  cerr<<i<<" "<<j<<" "<<f[i][j]<<endl;
        }
    float res=0;
    cout<<setprecision(10)<<f[n][n/2];

}


Measured memory_bytes: 35456
#include<bits/stdc++.h>
using namespace std;
const int N=2e5+10;
string s[N];
int n,l;
int main(){
	scanf("%d%d",&n,&l);
	for(int i=1;i<=n;i++)
		cin>>s[i];
	sort(s+1,s+1+n);
	for(int i=1;i<=n;i++)
		cout<<s[i];
	return 0;
}

Measured memory_bytes: 10012
use std::io::{stdin, Read, StdinLock};
use std::str::FromStr;

#[allow(dead_code)]
struct Scanner<'a> {
    cin: StdinLock<'a>,
}
#[allow(dead_code)]
impl<'a> Scanner<'a> {
    fn new(cin: StdinLock<'a>) -> Scanner<'a> {
        Scanner { cin: cin }
    }

    fn read<T: FromStr>(&mut self) -> Option<T> {
        let token = self.cin.by_ref().bytes().map(|c| c.unwrap() as char)
            .skip_while(|c| c.is_whitespace())
            .take_while(|c| !c.is_whitespace())
            .collect::<String>();
        token.parse::<T>().ok()
    }

    fn input<T: FromStr>(&mut self) -> T {
        self.read().unwrap()
    }

    fn vec<T: FromStr>(&mut self, len: usize) -> Vec<T> {
        (0..len).map(|_| self.input()).collect()
    }

    fn mat<T: FromStr>(&mut self, row: usize, col: usize) -> Vec<Vec<T>> {
        (0..row).map(|_| self.vec(col)).collect()
    }
}

fn main() {
    let cin = stdin();
    let cin = cin.lock();
    let mut sc = Scanner::new(cin);

    let (n, m): (usize, usize) = (sc.input(), sc.input());
    let mut uf = UnionFind::new(n);
    for _ in 0..m {
        let (x, y): (usize, usize) = (sc.input(), sc.input());
        let (x, y) = (x - 1, y - 1);
        uf.merge(x, y);
    }

    let mut ans = 0;
    for x in 0..n {
        ans = std::cmp::max(ans, uf.tree_size(x));
    }
    println!("{}", ans);
}

struct UnionFind {
    par: Vec<usize>,
    size: Vec<usize>,
}

impl UnionFind {
    fn new(n: usize) -> Self {
        let mut par = vec![0; n];
        let mut size = vec![0; n];
        for i in 0..n {
            par[i] = i;
            size[i] = 1;
        }
        Self { par, size }
    }

    fn is_same(&mut self, x: usize, y: usize) -> bool {
        self.find_root(x) == self.find_root(y)
    }

    fn find_root(&mut self, x: usize) -> usize {
        if x != self.par[x] {
            self.par[x] = self.find_root(self.par[x]);
        }
        self.par[x]
    }

    fn merge(&mut self, x: usize, y: usize) {
        let x = self.find_root(x);
        let y = self.find_root(y);
        if x == y {
            return;
        }

        if self.size[x] > self.size[y] {
            self.par[y] = x;
            self.size[x] += self.size[y];
        } else {
            self.par[x] = y;
            self.size[y] += self.size[x];
        }
    }

    fn tree_size(&mut self, x: usize) -> usize {
        let root = self.find_root(x);
        self.size[root]
    }
}


Measured memory_bytes: 5088
#include<bits/stdc++.h>
using namespace std;
#define FAST ios_base::sync_with_stdio(false);cin.tie(NULL);
#define ll long long int
#define ull unsigned long long int
#define ld long double
#define mod 1000000007
#define inf 1000000000000000007
#define eps 0.000001
#define pi 3.141592653589793
#define pii pair<int , int>
#define pdd pair<ld,ld>
#define pll pair<ll,ll>
#define ff first
#define ss second
#define vii vector<int>
#define vpl vector<pll>
#define vll vector<ll>
#define sti stack <int>
#define stll stack <ll>
#define mseti set <ll>
#define msetd multiset <ll, greater <ll> >
#define mp make_pair
#define pb push_back
#define lb lower_bound
#define ub upper_bound 
#define stp setprecision(20)//use fixed before stp
#define endl '\n'
int main()
{  
    FAST
    ll n;
    cin>>n;
    ll a[n],dp[n];
    for(ll i=0;i<n;i++)
    {
        cin>>a[i];
        dp[i]=inf;
    }
    dp[0]=0;
    dp[1]=abs(a[1]-a[0]);
    for(ll i=2;i<n;i++)
    {
        dp[i]=min(abs(a[i]-a[i-1])+dp[i-1],abs(a[i]-a[i-2])+dp[i-2]);
    }
    cout<<dp[n-1];
}

Measured memory_bytes: 1792
#include<bits/stdc++.h>
#define int long long
#define pb push_back
using namespace std;
int32_t main()
{
    int n,i,j,w;
        cin>>n>>w;
            vector<long long> v(n) , wt(n);
    vector<vector<int> > dp(n + 1 , vector<long long>(w + 1 , 0));

         for(int i = 0 ; i < n ; ++i){
      cin >> wt[i] >> v[i];
    }
    for(int i = 1 ; i <= n ; ++i){
      for(int j = 1; j <= w ; ++j){
        if(wt[i - 1] <= j){
          dp[i][j] = max(dp[i - 1][j] , v[i - 1] + dp[i - 1][j - wt[i - 1]]);
        }
        else{
          dp[i][j] = dp[i - 1][j];
        }
      }
    }

  cout << dp[n][w];
    return 0;
}



Measured memory_bytes: 83036
#include<bits/stdc++.h>
using namespace std;
#define ll long long
const int N=25;
int a[N],b[N],c[N];
int main()
{
	int n,sum=0;
	cin>>n;
	for(int i=1;i<=n;i++)
	{
		cin>>a[i];
	}
	for(int i=1;i<=n;i++)
	{
		cin>>b[i];
		sum=sum+b[i];
	}
	for(int i=1;i<=n-1;i++)
	{
		cin>>c[i];
	} 
	for(int i=1;i<=n-1;i++)
	{
		if(a[i]==a[i+1]-1)
		{
			sum=sum+c[a[i]];
		}
	}
	cout<<sum<<'\n';
   return 0;
}

Measured memory_bytes: 256
N = int(input())
A = list(map(int, input().split()))
all = abs(A[0]) + abs(A[N-1])
for i in range(1, N):
    all += abs(A[i] - A[i-1])

for i in range(N):
    answer = all
    if i == 0:
        prev = 0
    else:
        prev = A[i-1]
    if i == N-1:
        next = 0
    else:
        next = A[i+1]
    curr = A[i]
    if prev > curr and curr < next:
        if prev >= next:
            answer -= abs(curr - next) * 2
        else:
            answer -= abs(curr - prev) * 2
    elif prev < curr and curr > next:
        if prev >= next:
            answer -= abs(curr - prev) * 2
        else:
            answer -= abs(curr - next) * 2
    print(answer)

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

ll a[200020],f[200020];

int main(){
  int n;
  ll k;
  cin >> n >> k;
  rep(i,n)cin >> a[i];
  rep(i,n)cin >> f[i];
  sort(a,a+n,greater<ll>());
  sort(f,f+n);
  ll ok=(ll)1,ng=(ll)-1;
  rep(i,13)ok*=(ll)10;
  while(ok-ng>1){
    ll mid=(ok+ng)/2;
    ll sum=0;
    rep(i,n)sum+=max(a[i]-mid/f[i],0LL);
    if(sum<=k){
      ok=mid;
    }else ng=mid;
  }
  cout << ok << endl;
return 0;}

Measured memory_bytes: 3328
#include "bits/stdc++.h"

using namespace std;

typedef long long ll;
typedef pair<int,int> P;
constexpr double EPS = 1e-12;
constexpr int INF = numeric_limits<int>::max()/2;
constexpr int MOD = 1e9+7;

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

    int a,b;cin>>a>>b;
    if(a%3!=0 && b%3!=0 && (a+b)%3!=0) cout<<"Impossible"<<endl;
    else cout<<"Possible"<<endl;
}


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

using namespace std;

int main()
{
	int a=0, b=0, c=0;

	cin >> a >> b >> c;

	if ((a + b == c) || (b + c == a) || (c + a == b)) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}
	
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i,n) for(int i=0;i<(n);i++)
#define ALL(a)  (a).begin(),(a).end()
#define SORT(c) sort((c).begin(),(c).end())
#define REV(c) reverse((c).begin(),(c).end())

using namespace std;
typedef pair<int,int> P;

// 最大公約数
int64_t gcd(int64_t a, int64_t b) {
  return b != 0 ? gcd(b, a % b) : a;
}

// 最小公倍数
int64_t lcm(int64_t a, int64_t b) {
  return a * b / gcd(a, b);
}

int ctoi(char c){
  return c - '0';
}

vector<int64_t> a;
int n;

int64_t Go(int from, int to, int64_t ca, int64_t cb) {
  if (to - from == 1) {
    return 0;
  }
  int64_t best;
  best = (int64_t) 1e18;
  for (int i = from + 1; i < to; i++) {
    int64_t cur = a[i] * (ca + cb) + Go(from, i, ca, ca + cb) + Go(i, to, ca + cb, cb);
    best = min(best, cur);
  }
  return best;
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cin >> n;
  a.resize(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  cout << Go(0, n - 1, 1, 1) + a[0] + a[n - 1] << '\n';
  return 0;
}



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

/***Crazy Macros***/
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define reu(i,a,b) for (ll i = (a); i <= (b); ++i)
#define red(i,a,b) for (ll i = (a); i >= (b); --i)
typedef int64_t ll;
typedef pair<ll,ll> ii;
typedef vector<ll> vi;
typedef vector<ii> vii;
const ll inf = 1e18;
const ll mod = 998244353;

/***Graph Variables***/
vector<vi> adj;
vector<vi> radj;
vi visited;
vi level;

/***Common Functions***/
ll inp() {ll x; cin >> x; return x;}
string inpStr() {string x; cin >> x; return x;}

ll power(ll a, ll b) {
    a %= mod;
    ll res = 1;
    reu(i, 0, log2(b)) {
        if (b & (1<<i)) res = (res*a) % mod;
        a = (a*a) % mod;
    }
    return res;
}
ll gcd(ll a, ll b) {
    while (b > 0) {ll tmp = a%b; a = b; b = tmp;}
    return a;
}
void fast_io() {ios::sync_with_stdio(0); cin.tie(0);}

void file_io(string in, string out) {
    freopen(in.c_str(), "r", stdin);
    freopen(out.c_str(), "w", stdout);
}
/***Main Code***/
vi ok;

void dfs(ll u) {
    visited[u] = true;
    for (auto v : adj[u]) {
        ok[u] = true;
        ok[v] = true;
        if (!visited[v]) dfs(v);
    }
}
int main()
{
    fast_io();
    ll n = inp(), m = inp();
    ll res = n*(n-1)/2 + m*(m-1)/2;
    cout << res;
    return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
#define FOR(i, a, b) for (int i = (a); i <= (b); i++)
#define RFOR(i, a, b) for (int i = (a); i >= (b); i--)
#define LFOR(i, a, b) for (long long int i = (a); i <= (b); i++)
#define LRFOR(i, a, b) for (long long int i = (a); i >= (b); i--)
#define MOD 1000000007
#define INF 1000000000           // 2000000000
#define LINF 1000000000000000000 // 9000000000000000000
#define DINF 1000000000000000.0
#define PI 3.14159265358979

//.size()はunsigned int　0-1をするとオーバーフローする

using namespace std;
typedef long long int ll;
typedef pair<long long int, long long int> P;

int dy[5] = {-1, 0, 1, 0, 0};
int dx[5] = {0, -1, 0, 1, 0};

int main(void) {
    long long int a,b;

    cin>>a>>b;

    if((a+b)%2==0){
        cout<<(a+b)/2<<endl;
    }else {
        cout<<"IMPOSSIBLE"<<endl;
    }
}


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

using namespace std;

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

int main(){
  int k, x, y;
  cin >> k >> x >> y;
  if((x-y&1) && k % 2 == 0){
    cout << -1 << endl;
    return 0;
  }
  if(abs(x) + abs(y) == k){
    cout << 1 << endl;
    cout << x << " " << y << endl;
    return 0;
  }
  vector<int> a, b;
  while(abs(x) + abs(y) > 2 * k){
    if(x >= k){
      a.push_back(k), b.push_back(0);
      x -= k;
    }else if(x <= -k){
      a.push_back(-k), b.push_back(0);
      x += k;
    }else if(y >= k){
      b.push_back(k), a.push_back(0);
      y -= k;
    }else if(y <= -k){
      b.push_back(-k), a.push_back(0);
      y += k;
    }
  }
  if(k&x-y&1){
    if(abs(x+k) + abs(y) <= 2 * k){
      a.push_back(-k), b.push_back(0);
      x += k;
    }else if(abs(x-k) + abs(y) <= 2 * k){
      a.push_back(k), b.push_back(0);
      x -= k;
    }else if(abs(x) + abs(y+k) <= 2 * k){
      b.push_back(-k), a.push_back(0);
      y += k;
    }else if(abs(x) + abs(y-k) <= 2 * k){
      b.push_back(k), a.push_back(0);
      y -= k;
    }else{
      assert(false);
    }
  }
  if(abs(x) >= abs(y)){
    int p = (abs(x) + abs(y)) / 2;
    int q = (abs(x) - abs(y)) / 2;
    a.push_back(x < 0 ? -p : p), b.push_back(y < 0 ? k - p : p - k);
    a.push_back(x < 0 ? -q : q), b.push_back(y < 0 ? q - k : k - q);
  }else{
    int p = (abs(y) + abs(x)) / 2;
    int q = (abs(y) - abs(x)) / 2;
    b.push_back(y < 0 ? -p : p), a.push_back(x < 0 ? k - p : p - k);
    b.push_back(y < 0 ? -q : q), a.push_back(x < 0 ? q - k : k - q);
  }
  cout << a.size() << endl;
  int p = 0, q = 0;
  REP(i, a.size()){
    p += a[i], q += b[i];
    cout << p << " " << q << endl;
  }
  return 0;
}


Measured memory_bytes: 4076
#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define sz(x) ((int)(x).size())
typedef vector<int> vi;
typedef long long ll;
typedef pair<int,int> pii;
typedef double db;
const ll mod=1000000007;
ll powmod(ll a,ll b) {ll res=1;a%=mod;assert(b>=0);for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}
int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	ll x,y,z;
	cin>>x>>y>>z;
	for(int i =0; i < 10; i++){
		z = z*x-y;
		cout<<z<<"\n";
	}
	return 0;
}

Measured memory_bytes: 3608
/* package whatever; // don't place package name! */

import java.util.*;
import java.lang.*;
import java.io.*;

/* Name of the class has to be "Main" only if the class is public. */
class Main
{
	public static void main (String[] args) throws java.lang.Exception
	{
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
        int k = sc.nextInt();
		System.out.println(n >= k * 2 - 1 ? "YES" : "NO");
	}
}

Measured memory_bytes: 22484
#include <stdio.h>
int main()
{
  int i, j, k, num[100], tmp, x=0;
  
  scanf("%d", &k);
  for(i=0; i < k; i++)
    {
    scanf("%d", &num[i]);
  }
  
  for(i=0; i<k-1; i++)
    {
    for(j = k-1; j>i; j--)
      {
	if(num[j-1]>num[j])
	  {
	tmp = num[j-1];
	num[j-1] = num[j];
	num[j] = tmp;
	x++;
      }
    }
  }
  
  for(i=0; i<k; ++i)
    {
  printf("%d", num[i]);
  if(i+1>=k) break;
  printf(" ");
  }
  printf("\n%d\n", x);
  
  return 0;
}

Measured memory_bytes: 604
fun main(args: Array<String>) {
    var n = readLine()!!.toInt()
    var ans=0
    repeat(n){
        var (x,y) = readLine()!!.split(" ").map(String::toInt)
        if (ans==3) {
            println("Yes")
            return
        }
        if (x==y){
            ans+=1
        }else{
            ans=0
        }
    }
    if (ans>=3) {
        println("Yes")
    }else{
        println("No")

    }
}

Measured memory_bytes: 37968
#include <bits/stdc++.h>
#define N 2002
#define PB push_back
#define MP make_pair
#define F first
#define S second
using namespace std;
int n, m, k, i, j, l, r, t, fix[N], fox[N], a[N][N], d, ans, w, pro[N][N], fex[N];
vector<int>v[N];
pair<int,int>p;
queue<pair<int,int> >q;
int main() {
    cin>>n>>k;
    ans=0;
    if(k==1){
        cout<<n-2<<endl;
        return 0;
    }
    for(i=0;i<n-1;i++){
        cin>>l>>r;
        v[r].PB(l);
        v[l].PB(r);
    }
    for(i=1;i<=n;i++){
        for(j=1;j<=n;j++)a[i][j]=-1;
    }
    for(i=1;i<=n;i++){
        a[i][i]=0;
        q.push(MP(i,0));
        while(q.size()){
            p=q.front();
            t=p.F;
            w=p.S;
            pro[i][t]=w;
            q.pop();
            d=max(d,a[i][t]);
            for(j=0;j<v[t].size();j++){
                if(a[i][v[t][j]]!=-1)continue;
                if(w==0){
                    if(t==i)q.push(MP(v[t][j],v[t][j]));
                }
                else q.push(MP(v[t][j],w));
                a[i][v[t][j]]=a[i][t]+1;
            }
        }
    }
   // for(i=1;i<=n;i++){for(j=1;j<=n;j++)cout<<pro[i][j]<<" ";cout<<endl;}
    if(k>=d){cout<<0<<endl;return 0;}
    for(i=1;i<=n;i++){
        t=0;
        for(j=0;j<=n;j++)fex[j]=0;
        for(j=1;j<=n;j++){
            if(a[i][j]<=k/2)t++;
            if(a[i][j]==k/2+1)fex[pro[i][j]]++;
        }
        if(k%2==1){
            m=0;
            for(j=1;j<=n;j++){
                if(fex[j]>m){
                    m=fex[j];
                }
            }
            t+=m;
        }
        ans=max(ans,t);
    }
    cout<<n-ans<<endl;
    return 0;
}

Measured memory_bytes: 31744
#include<iostream>
#include<string>
#include<cmath>
#include<queue>
#include<map>
#include<set>
#include<list>
#include<iomanip>
#include<vector>
#include<random>
#include<functional>
#include<algorithm>
#include<cstdio>
#include<bitset>
#include<unordered_map>
using namespace std;
//---------------------------------------------------
//ライブラリゾーン！！！！
typedef long long ll;
typedef long double ld;
#define str string
#define rep(i,j) for(ll i=0;i<(long long)(j);i++)
#define all(a) (a).begin(),(a).end()
const ll Mod = 1000000007;
const ll gosenchou = 5000000000000000;
short gh[2][4] = { { 0,0,-1,1 },{ -1,1,0,0 } };
struct P {
	ll pos, cost;
};
bool operator<(P a, P b) { return a.cost < b.cost; }
bool operator>(P a, P b) { return a.cost > b.cost; }
struct B {//隣接リスト表現
	ll to, cost;
};
struct E {//辺の情報を入れる変数
	ll from, to, cost;
};
bool operator<(E a, E b) {
	return a.cost < b.cost;
}
struct H {
	ll x, y;
};
bool operator<(H a, H b) {
	if (a.x != b.x) return a.x < b.x;
	return a.y < b.y;
}
bool operator>(H a, H b) {
	if (a.x != b.x) return a.x > b.x;
	return a.y > b.y;
}
bool operator==(H a, H b) {
	return a.x == b.x&&a.y == b.y;
}
bool operator!=(H a, H b) {
	return a.x != b.x || a.y != b.y;
}
ll gcm(ll i, ll j) {//最大公約数
	if (i > j) swap(i, j);
	if (i == 0) return j;
	return gcm(j%i, i);
}
ld rad(H a, H b) {
	return sqrt(pow(a.x - b.x, 2.0) + pow(a.y - b.y, 2.0));
}//rad＝座標上の2点間の距離
ll ari(ll a, ll b, ll c) {
	return (a + b)*c / 2;
}//等差数列の和
ll fact(ll x, ll k, ll p) {//最大値、個数、あまり
	ll sum = 1;
	for (int i = 0; i < k; i++) {
		sum *= (x--);
		sum %= p;
	}
	return sum;
}//階乗(正）
ll mod_pow(ll x, ll n, ll p) {
	ll res = 1;
	while (n > 0) {
		if (n & 1) res = res*x%p;
		x = x*x%p;
		n >>= 1;
	}
	return res;
}//x^n%p
short ctos(char a) {
	return (int)(a - '0');
}
#define int long long
const long long Inf = 4523372036854775807;
const int inf = 15000000000;
//----------------------------------------------------
//++++++++++++++++++++++++++++++++++++++++++++++++++++
bool solve(int x) {
	string s = to_string(x);
	for (int i = 0; i < ceil(s.size() / 2.0); i++) {
		if (s[i] != s[s.size() - i - 1])
			return 0;
	}
	return 1;
}
signed main() {
	int a, b;
	cin >> a >> b;
	int sum = 0;
	for (int i = a; i <= b; i++) {
		if (solve(i)) sum++;
	}
	cout << sum << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<ll, pair<ll, ll> > P3;
const ll MOD = 1000000007;
const int IINF = INT_MAX;
const ll LLINF = LLONG_MAX;
const int MAX_N = int(1e5 + 5);
const double EPS = 1e-10;
const int di[] = {0, 1, 0, -1}, dj[] = {1, 0, -1, 0};
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define SORT(v) sort((v).begin(), (v).end())
#define ALL(v) (v).begin(), (v).end()

int main() {
    string s, t="keyence";
    int l=0, r=0;
    cin >> s;
    while(l<t.size()){
        if(s[l]==t[l])l++;
        else break;
    }
    while(r<t.size()){
        if(s[s.size()-1-r]==t[t.size()-1-r])r++;
        else break;
    }
    if(l+r>=t.size()){
        cout << "YES" << endl;
    }
    else {
        cout << "NO" << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <cfloat>
#include <ctime>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <numeric>
#include <list>

using namespace std;

#ifdef _MSC_VER
#define __typeof__ decltype
template <class T> int __builtin_popcount(T n) { return n ? 1 + __builtin_popcount(n & (n - 1)) : 0; }
#endif

#define foreach(it, c) for (__typeof__((c).begin()) it=(c).begin(); it != (c).end(); ++it)
#define all(c) (c).begin(), (c).end()
#define rall(c) (c).rbegin(), (c).rend()
#define CLEAR(arr, val) memset(arr, val, sizeof(arr))

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

template <class T> void max_swap(T& a, const T& b) { a = max(a, b); }
template <class T> void min_swap(T& a, const T& b) { a = min(a, b); }

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

const double PI = acos(-1.0);
const int dx[] = { 0, 1, 0, -1 };
const int dy[] = { 1, 0, -1, 0 };


int main()
{
	int T;
	cin >> T;
	while (T--)
	{
		int n, h[128];
		cin >> n;
		rep (i, n)
			cin >> h[i];
		int up, down;
		up = down = 0;
		for (int i = 1; i < n; ++i)
		{
			max_swap(up, h[i] - h[i - 1]);
			min_swap(down, h[i] - h[i - 1]);
		}
		cout << up << " " << -down << endl;
	}
}

Measured memory_bytes: 0
n,k = map(int, input().split())

member = list(range(1, n+1))

for i in range(0,k):
    a = int(input())
    if a == 1:
        b = int(input())
        if b in member:
            member.remove(b)
        else:
            pass
    else:
        b = list(map(int, input().split()))
        for j in range(0,a):
            if b[j] in member:
                member.remove(b[j])
            else:
                pass

print(len(member))

Measured memory_bytes: 9208
// SeeAlso: 

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

#define MAX 100000
#define NIL -1

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

#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define DEBUG_VEC(v) cout<<#v<<":";REP(i,v.size())cout<<" "<<v[i];cout<<endl
#define ALL(a) (a).begin(),(a).end()

#define CHMIN(a,b) a=min((a),(b))
#define CHMAX(a,b) a=max((a),(b))

// 最大公約数
inline constexpr ll gcd(ll a,ll b){if(!a||!b)return 0;while(b){ll c=b;b=a%b;a=c;}return a;}
// 最小公倍数
inline constexpr ll lcm(ll a,ll b){if(!a||!b)return 0;return a*b/gcd(a,b);}

#define print2D(h, w, arr) REP(i, h) { REP(j, w) cout << arr[i][j] << " "; cout << endl; }
template<class T> void print(const T& x){cout << setprecision(12) << x << endl;}
template<class T, class... A> void print(const T& first, const A&... rest) { cout << first << " "; print(rest...); }

string S;

int main() {
    cin >> S;
    
    bool flag = true;

    int scounter = S.size();
    REP(i, scounter) {
        
        if(i%2==1) {
            if(!(S[i]=='L'||S[i]=='U'||S[i]=='D')) {
                flag = false;
                break;
            }
        } else {
            if(!(S[i]=='R'||S[i]=='U'||S[i]=='D')) {
                flag = false;
                break;
            }
        }
    }

    if (flag) {
        print("Yes");
    } else {
        print("No");
    }
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  string s,s1;
  cin>>s>>s1;
  int count=0;
  for(int i=0;i<3;i++){
    if(s[i]==s1[i])
      	count++;
  }
  cout<<count;
  return 0;
}

Measured memory_bytes: 3564
#include<iostream>
#include<cmath>
#include<cstdio>

#define PI 3.14159265358979

using namespace std;

struct P {
  double x;
  double y;
};

void Plot(int n, P a, P b) {
  if (n == 0) {
    return;
  }

  double th = 60.0 * (PI / 180.0); // degree to rad

  P s, t, u;
  s.x = (2.0 * a.x + 1.0 * b.x) / 3.0;
  s.y = (2.0 * a.y + 1.0 * b.y) / 3.0;
  t.x = (1.0 * a.x + 2.0 * b.x) / 3.0;
  t.y = (1.0 * a.y + 2.0 * b.y) / 3.0;  
  u.x = (t.x - s.x) * cos(th) - (t.y - s.y ) * sin(th) + s.x;
  u.y = (t.x - s.x) * sin(th) + (t.y - s.y ) * cos(th) + s.y;  

  Plot(n - 1, a, s);
  printf("%.8lf %.8lf\n", s.x, s.y);
  Plot(n - 1, s, u);
  printf("%.8lf %.8lf\n", u.x, u.y);
  Plot(n - 1, u, t);
  printf("%.8lf %.8lf\n", t.x, t.y);
  Plot(n - 1, t, b);
}
 
int main() {
  const P A = {0.0, 0.0}, B = {100.0, 0.0};
  int N;

  cin >> N;

  printf("%.8lf %.8lf\n", A.x, A.y);
  Plot(N, A, B);
  printf("%.8lf %.8lf\n", B.x, B.y);

  return 0;
}


Measured memory_bytes: 3208
#include <iostream>
#include <string>

int main(int argc, char** argv)
{
	std::string N;
	std::cin >> N;
	if (N.back() == '3')
	{
		std::cout << "bon" << std::endl;
	}
	else if (N.back() == '0' || N.back() == '1' || N.back() == '6' || N.back() == '8')
	{
		std::cout << "pon" << std::endl;
	}
	else
	{
		std::cout << "hon" << std::endl;
	}

	return 0;
}

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

#define  ll         long long
#define  llu        unsigned long long
#define  mod        1000000007
#define  pi         ((2.0)*acos(0.0))
#define  pb         push_back
#define  pf         push_front
#define  eb         emplace_back
#define  mp         make_pair
#define  all(x)     (x).begin(),(x).end()
#define  X          first
#define  Y          second

/*loop*/
#define  fr(i,m,n)   for(ll i=m;i<n;++i)

/*output shortcuts*/
#define  nl         "\n"
#define  Yes        cout<<"Yes\n"
#define  yes        cout<<"yes\n"
#define  YES        cout<<"YES\n"
#define  No         cout<<"No\n"
#define  no         cout<<"no\n"
#define  NO         cout<<"NO\n"

ll a[10000000];


using namespace std;
int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);

    ll n,k;
    cin>>n>>k;

    ll a[n];
    fr(i,0,n)
    cin>>a[i];

    ll dp[n];
    dp[n-1]=0;

    for(ll i=n-2; i>=0; i--)
    {
        ll p=LONG_MAX;

        fr(j,1,k+1)
        {
            if(i+j >= n)
                break;
            p = min( (dp[i+j] + abs(a[i]-a[i+j]) ) ,p );
            dp[i]=p;
        }
    }

    cout<<dp[0]<<nl;

return 0;
}




Measured memory_bytes: 5196
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <stdlib.h>
#include <math.h>


int main() {
	int X,a;
	double x = 0;
	int Ans = 0,max = 0;

	scanf("%d", &X);

	for (int i = 1; i < 100; i++){
		for (int j = 2; j < 10; j++){
			x = pow(i, j);
			if ((x <= X)&&(x > max)){
				max = x;
				
			}

		}
	}
	if (max == 0){
		max = 1;
	}



	printf("%d\n", max);

	return 0;
}



Measured memory_bytes: 128
#include<bits/stdc++.h>
#define watch(x) cout << (#x) << " is " << (x) << endl
typedef long long ll;
using namespace std;
int static fast = [](){
  ios::sync_with_stdio(false);
  cin.tie(0); cout.tie(0); return 0;
}();
// freopen("input.txt", "r", stdin);

int main() {
    string s, t;
    cin >> s >> t;
    int n = s.size(), m = t.size();
    vector<vector<int>> lcs(n+1, vector<int>(m+1, 0));
    vector<vector<int>> trace(n+1, vector<int>(m+1, -1));
    for(int i = 0; i < n; i++) {
        for(int j = 0; j < m; j++) {
            if (s[i] == t[j]) {
                lcs[i+1][j+1] = lcs[i][j] + 1;
                trace[i+1][j+1] = 3; // diag
            } else {
                if (lcs[i+1][j] > lcs[i][j+1])
                    trace[i+1][j+1] = 2; // left
                else
                    trace[i+1][j+1] = 1; // up
                lcs[i+1][j+1] = max(lcs[i+1][j], lcs[i][j+1]);
            }
        }
    }
    // cout << lcs[n][m] << endl;

    string ans = "";
    int row = n, col = m;
    while (row > 0 && col > 0) {
        int pre = trace[row][col];
        if (pre == 3)
            ans += s[row-1];
        row -= (pre & 1);
        col -= ((pre>>1) & 1);
        // printf("row = %d, col = %d, pre = %d\n", row, col, trace[row][col]);
    }
    reverse(ans.begin(), ans.end());
    cout << ans << endl;
    return 0;
}



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

// g++ -std=c++17 -O2 -Wall template.cpp -o template
int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    unsigned long long n, a, b;
    cin >> n >> a >> b;
    unsigned long long perfect_blues = n / (a + b) * a;
    unsigned long long leftover_blues = n % (a + b) > a ? a : n % (a + b);
    cout << perfect_blues + leftover_blues << endl;
    // freopen("input.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);
    // Solution
}


Measured memory_bytes: 256
T = 1000
N = 4000
dp = [[0] * (N + 1) for _ in range(5)] 
#Java: int[][] dp = new int[5][N];
dp[0][0] = 1
for i in range(1,5):
    for j in range(i*T+1):
        dp[i][j] = sum([dp[i-1][k] for k in range(max(0,j-T),j+1)])

while True:
    try:
        n = input() 
    except EOFError:
        break
    print dp[4][n]

#O(T^2), 0.954

Measured memory_bytes: 4720
import java.util.Scanner;

class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();
        int c;
        if(a < b){
            c = a;
            a = b;
            b = c;
        }
        c = a%b;
        while(c != 0){
            a = b;
            b = c;
            c = a%b;
        }      
        System.out.println(b);         
    }
}



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

using namespace std;
#define PI 3.141592653589
void solve(){
	int n,m;
	cin>>n>>m;
	int graph[m][2];
	for(int i=0;i<m;i++){
		cin>>graph[i][0]>>graph[i][1];
	}
	vector<int> dp(n,0);
	vector<vector<int>> g(n,vector<int>());
	for(int i=0;i<m;i++){
		g[graph[i][0]-1].push_back(graph[i][1]-1);
		g[graph[i][1]-1].push_back(graph[i][0]-1);
	}

	queue<int> q;
	q.push(0);
	int curr;
	while(!q.empty()){
		curr = q.front();
		q.pop();
		for(int &i:g[curr]){
			if(dp[i] == 0){
				dp[i] = curr+1;
				q.push(i);
			}
		}
	}
	for(int i=0;i<n;i++){
		if(dp[i] == 0){
			cout<<"No\n";
			return;
		}
	}
	cout<<"Yes\n";
	for(int i=1;i<n;i++){
		cout<<dp[i]<<"\n";
	}
}
int main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);

	
	solve();

	return 0;
}

Measured memory_bytes: 11816
/*input

*/


// assic value of ('0'-'9') is(48 - 57) and (a-z) is (97-122) and (A-Z) is(65-90) and 32 for space
// #pragma GCC target ("avx2")
// #pragma GCC optimization ("O3")
// #pragma GCC optimization ("unroll-loops")
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;

// order_of_key (k) : Number of items strictly smaller than k .
// find_by_order(k) : K-th element in a set (counting from zero).
using namespace __gnu_pbds;
template<class T> using oset=tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

#define ll          long long int
#define pb          push_back
#define pii         pair<ll ,ll >
#define vpii        vector< pii >
#define vi          vector<ll >
#define vs			vector< string >
#define vvi         vector< vector< ll > >
#define inf			(ll)1e18
#define all(it,a)   for(auto it=(a).begin();it!=(a).end();it++) 
#define F           first
#define S           second
#define sz(x)       (ll )x.size()
#define rep(i,a,b)	for(ll  i=a;i<b;i++)
#define repr(i,a,b) for(ll  i=a;i>b;i--)
#define lbnd        lower_bound
#define ubnd        upper_bound
#define mp          make_pair
#define whatis(x)   cout << #x << " is " << x << "\n";
#define graph(n)    adj(n,vector< ll > () )
//mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

#define debug(x)     cout << #x << " " << x << endl;
#define debug_p(x)   cout << #x << " " << x.F << " " << x.S << endl;
#define debug_v(x)   {cout << #x << " "; for (auto ioi : x) cout << ioi << " "; cout << endl;}
#define debug_vp(x)  {cout << #x << " "; for (auto ioi : x) cout << '[' << ioi.F << " " << ioi.S << ']'; cout << endl;}
#define debug_v_v(x) {cout << #x << "/*\n"; for (auto ioi : x) { for (auto ioi2 : ioi) cout << ioi2 << " "; cout << '\n';} cout << "*/" << #x << endl;}

int solve()
{
	string s;cin>>s;
	rep(i,0,sz(s))
	{
		if(s[i]!='?') cout<<s[i];
		else cout<<"D";
	}
	return 0;
}

int main()
{
	auto start = chrono::high_resolution_clock::now();

	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);

	ll test_cases=1;
	//cin>>test_cases;
	while(test_cases--)
		solve();

	auto stop = chrono::high_resolution_clock::now();
	auto duration = chrono::duration_cast<chrono::milliseconds>(stop-start);
	//cout<<"\nduration: "<<(double)duration.count()<<" milliseconds";
}

Measured memory_bytes: 3772
#include <iomanip>
#include <random>
#include <time.h>
#include <vector>
#include <algorithm>
#include <queue>
#include <functional>
#include <map>
#include <string>
#include <cstdlib>
#include <typeinfo>
#include <math.h>
#include <iostream>
using namespace std;
int main()
{
	long long int n, x, a[100010], ans = 0;
	cin >> n >> x;
	for(int i = 1; i <= n; i++) {
		cin >> a[i];
		if (a[1] - x > 0) {
			ans += a[1] - x;
			a[1] = x;
		}
		if (i > 1) {
			if (a[i] + a[i - 1] > x) {
				ans += a[i] + a[i - 1] - x;
				a[i] = x - a[i - 1];
			}
		}
	}
	cout << ans << endl;
	return 0;
}


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

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

    int d;
    cin >> d;

    vector<int> c(26);
    rep(i, 26) cin >> c[i];
    vector<vector<int>> s(d, vector<int>(26));
    rep(i, d) rep(j, 26) cin >> s[i][j];

    vector<int> t(d);
    rep(i, d){
        cin >> t[i];
        --t[i];
    }

    int m;
    cin >> m;

    vector<int> x(m), q(m);
    rep(i, m){
        cin >> x[i] >> q[i];
        --x[i];
        --q[i];
    }

    vector<int> tt = t;
    rep(idx, m){
        
        tt[x[idx]] = q[idx];

        vector<int> last(26, 0);
        int res = 0;
        rep(i, d){
            res += s[i][tt[i]];
            
            int minus = 0;

            rep(j, 26) ++last[j];
            last[tt[i]] = 0;
            rep(j, 26) minus += c[j] * last[j];

            res -= minus;
            
        }
        cout << res << endl;
    }

    return 0;
}

Measured memory_bytes: 3904
#!python3

iim = lambda: map(int, input().rstrip().split())

def resolve():
    N = int(input())
    S = input()

    ar = []
    ab = []
    ag = []
    for i, si in enumerate(S):
        if si == "R":
            ar.append(i)
        elif si == "G":
            ag.append(i)
        else:
            ab.append(i)

    aa = [(ar, "R"), (ab, "B"), (ag, "G")]
    aa.sort(key=lambda x: len(x[0]))
    ans = 0
    ck = aa[2][1]
    ans = len(ar)*len(ab)*len(ag)
    for si in aa[0][0]:
        for sj in aa[1][0]:
            for k in [2*si-sj, 2*sj-si]:
                if 0 <= k < N and S[k] == ck:
                    ans -= 1
            k = si + sj
            if k & 1:
                continue
            k //=2
            if k < N and S[k] == ck:
                ans -= 1
    print(ans)





if __name__ == "__main__":
    resolve()


Measured memory_bytes: 9304
n = int(input())
s = input().split()
for i, x in enumerate(s):
    s[i] = int(x)
q = int(input())
t = input().split()
for i, x in enumerate(t):
    t[i] = int(x)

c = 0
len_s = len(s)
for x in t:
    l = 0
    r = len_s
    while l < r:
        if s[(l + r) // 2] == x:
            c += 1
            break
        elif s[(l + r) // 2] < x:
            l = (l + r) // 2 + 1
        else:
            r = (l + r) // 2

print(c)


Measured memory_bytes: 13500
#include <algorithm>
#include <iostream>
#include <numeric>

using namespace std;

int main() {
  int N, K, a;
  cin >> N >> K;
  int A[200000]{};
  while (cin >> a) ++A[a-1];
  sort(rbegin(A),rend(A));
  cout << N - accumulate(begin(A),begin(A)+K,0) << endl;
}


Measured memory_bytes: 4356
require 'set'

class UnionFind
  def initialize(size)
    @rank = Array.new(size, 0)
    @parent = Array.new(size, &:itself)
  end

  def unite(id_x, id_y)
    x_parent = get_parent(id_x)
    y_parent = get_parent(id_y)
    return if x_parent == y_parent

    if @rank[x_parent] > @rank[y_parent]
      @parent[y_parent] = x_parent
    else
      @parent[x_parent] = y_parent
      @rank[y_parent] += 1 if @rank[x_parent] == @rank[y_parent]
    end
  end

  def get_parent(id_x)
    @parent[id_x] == id_x ? id_x : (@parent[id_x] = get_parent(@parent[id_x]))
  end

  def same_parent?(id_x, id_y)
    get_parent(id_x) == get_parent(id_y)
  end
end

n, k, l  = gets.strip.split.map(&:to_i)
pq = k.times.map { gets.strip.split.map(&:to_i) }
rl = l.times.map { gets.strip.split.map(&:to_i) }

roads = UnionFind.new(n+1)
rails = UnionFind.new(n+1)


pq.each do |p, q|
  roads.unite(p, q)
end

rl.each do |r, l|
  rails.unite(r, l)
end

counter = {}
(1..n).each do |i|
  k = [roads.get_parent(i), rails.get_parent(i)].to_s
  counter[k] ||= Set.new
  counter[k].add(i)
end

result = (1..n).map do |i|
  counter[ [roads.get_parent(i), rails.get_parent(i)].to_s ].length
end

puts result.join(' ')

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

int main(){
  int a, b;
  cin >> a >> b;
  int c = stoi(to_string(a) + to_string(b));
  bool result = false;
  for (int i = 1; i <= 1000; i++){
    if (c == (i * i)){
      result = true;
      break;
    }
  }
  if (result) cout << "Yes" << endl;
  else cout << "No" << endl;
  return 0;
}

Measured memory_bytes: 256
s = input()
K = int(input())
length = len(s)

substringList = []
for i in range(1,K+1) :
    for j in range(length-i+1) :
        substringList.append(s[j:j+i])


substringList = sorted(list(set(substringList)))
print(substringList[K-1])


Measured memory_bytes: 5068
#include <bits/stdc++.h>
using namespace std;
int main(){
  double x1,x2,y1,y2,d;

  cin >> x1 >> y1 >> x2 >> y2;

  double x = pow((x1-x2),2);
  double y = pow((y1-y2),2);

  d = pow((x+y),0.5);

  cout << fixed << setprecision(8) << d << endl;


  return 0;
}


Measured memory_bytes: 3400
#include <iostream>
#include <complex>
#include <cstring>
#include <vector>

using namespace std;

#define loop(i,a,b) for(int i=(a); i<int(b); i++)
#define rep(i,n) loop(i,0,n)
#define all(c) (c).begin(), (c).end()
typedef complex<int> P;

const int MAX_M = 1.5e6+10;
const int SIZE = 1500;
int ps[MAX_M/2];
bool isp[MAX_M];
int grid[SIZE][SIZE]={};
P itop[MAX_M];
pair<int,int> dp[SIZE][SIZE];

int cnt_p = 0;

void make_es(){
    fill(isp,isp+MAX_M,true);
    isp[0]=isp[1]=false;
    rep(i,MAX_M){
        if(!isp[i]) continue;
        ps[cnt_p++] = i;
        for(int j=i<<1; j<MAX_M; j+=i){
            isp[j] = false;
        }
    }
}

int n,m;

pair<int,int> rec(int y, int x){
    if(dp[y][x].first!=-1) return dp[y][x];

    pair<int,int> best(0,0);
    loop(i,-1,2){
        if(grid[y+1][x+i]<=m){
            auto t = rec(y+1,x+i);
            best = max(t,best);
        }
    }

    pair<int,int> res(0,0);
    if(isp[grid[y][x]]){
        res.first = 1;
        res.second = grid[y][x];
    }
    if(best.first != 0){
        res.first += best.first;
        res.second = best.second;
    }

    return dp[y][x] = res;
}

int main(){
    make_es();
    P p(SIZE/2,SIZE/2);
    P dir(0,1);
    for(int i=1; i<MAX_M; i++){
        grid[p.real()][p.imag()] = i;
        itop[i]=p;
        p+=dir;
        P q = p+dir*P(0,1);
        if(grid[q.real()][q.imag()] == 0){
            dir*=P(0,1);
        }
    }

    while(cin>>m>>n, n+m){
        auto t = make_pair(-1,-1);
        rep(i,SIZE)rep(j,SIZE) dp[i][j] = t;
        auto u = itop[n];
        auto ans = rec(u.real(), u.imag());
        cout << ans.first << " " << ans.second << endl;
    }
}

Measured memory_bytes: 42220
#include <stdio.h>

int main(void)
{
  int x,y,z;

  scanf("%d %d %d\n",&x,&y,&z);

  int n=0;
  for(int i=0;i<=10000;i++)
    {
      if(i>=x && i<=y && z%i==0)
	{
	  n++;
	}
    }

  printf("%d\n",n);

  return 0;

}

Measured memory_bytes: 1028
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <queue>
#include <stack>
#include <deque>
#include <set>
#include <unordered_set>
#include <map>
#define ll long long
#define endl '\n'
using namespace std;

int main(void)
{
  cin.tie(NULL); ios_base::sync_with_stdio(false);
  int N; cin >> N; vector<ll> vec; vec.push_back(0);
  for(int i = 0; i < N; i++)
    {
      int temp; cin >> temp; vec.push_back(temp);
    } vec.push_back(0);

  ll acc = 0;

  for(int i = 0; i < vec.size() - 1; i++)
    {
      acc += abs(vec[i+1] - vec[i]);
    }
 // cout << "acc is " << acc << endl;

  for(int i = 1; i <= N; i++)
    {
      ll offset = abs(vec[i] - vec[i+1]) + abs(vec[i] - vec[i-1]);
      cout << acc - offset + abs(vec[i-1] - vec[i+1]) << endl;
    }
  
  return 0;
}

Measured memory_bytes: 2164
#include"stdio.h"
int func(int a,int b) {
	if (a > b) {
		if (a%b == 0) {
			return b;
		}
		else {
			return func(b, a%b);
		}
	}
	else {
		if (b%a == 0) {
			return b;
		}
		else {
			return func(b, b%a);
		}
	}
}
int main()
{
	int a;
	int b;
	scanf("%d%d", &a, &b);
	printf("%d\n", func(a, b));
    return 0;
}	



Measured memory_bytes: 2724
#include <bits/stdc++.h>
#define int long long
#define P pair<int,int>
#define inf (int)(3e18)
#define mod (int)(1e9+7)
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;

int n;
vector<int>G[114514];
int fe[114514],snu[114514];
void dfs(int x,bool b){
	for(int i:G[x]){
		if(b&&fe[i])continue;
		if(!b&&snu[i])continue;
		if(b){
			fe[i]=fe[x]+1;
		}else {
			snu[i]=snu[x]+1;
		}
		dfs(i,b);
	}
}
signed main(){
	cin>>n;
	rep(i,n-1){
		int a,b;cin>>a>>b;a--;b--;
		G[a].push_back(b);G[b].push_back(a);
	}
	fe[0]=1;snu[n-1]=1;
	dfs(0,1);dfs(n-1,0);
	int f=0,s=0;
	rep(i,n){
		if(fe[i]<=snu[i])f++;
		else s++;
	}
	if(f>s){
		cout<<"Fennec"<<endl;	
	}else {
		cout<<"Snuke"<<endl;
	}
}


Measured memory_bytes: 12288