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

#define fs first
#define sc second
#define pb emplace_back
#define mp make_pair
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)

using pii = pair<int, int>;
using vi = vector<int>;
using lint = long long;

const int inf = 1001001001;
const lint linf = 1001001001001001001ll;
const double eps = 1e-9;
const int mod = 1e9 + 7;
const int dx[]{0, 1, 0, -1, -1, -1, 1, 1}, dy[]{1, 0, -1, 0, -1, 1, -1, 1};

template<typename T> inline bool chmin(T &a, T b) { if (a > b) { a = b; } return a > b; }
template<typename T> inline bool chmax(T &a, T b) { if (a < b) { a = b; } return a < b; }
template<typename T> inline void print(const T &x, string s = "\n") { cout << x << s; }
template<typename T> inline void print(const vector<T> &v, string s = " ")
{ if (!v.size()) puts(""); rep(i, v.size()) cout << v[i] << (i + 1 == v.size() ? "\n" : s); }
inline bool inside(int y, int x, int H, int W) { return 0 <= y && y < H && 0 <= x && x < W; }
inline lint in() { lint x; std::cin>>x; return x; }

int n;
vector<lint> a;

signed main() {
  cin >> n;
  lint m = 3 * n;
  rep(i, m) a.pb(in());

  vector<lint> l(m), r(m);
  priority_queue<lint, vector<lint>, greater<lint>> L;
  priority_queue<lint, vector<lint>> R;

  lint sum = 0;
  rep(i, m) {
    sum += a[i];
    L.push(a[i]);
    if (L.size() > n) {
      sum -= L.top();
      L.pop();
    }
    l[i] = sum;
  }
  sum = 0;
  for (int i = m - 1; i >= 0; --i) {
    sum += a[i];
    R.push(a[i]);
    if (R.size() > n) {
      sum -= R.top();
      R.pop();
    }
    r[i] = sum;
  }

  lint ans = -linf;
  for (int i = n - 1; i <= 2 * n - 1; ++i) {
    chmax(ans, l[i] - r[i + 1]);
  }

  cout << ans << endl;
}


Measured memory_bytes: 11372
#include<bits/stdc++.h>
using namespace std;
int main()
{
	 long long int ar,arr,arrr,j=0;
	 scanf("%lld %lld %lld",&ar,&arr,&arrr);
	if(ar>0)
	{
		j=(arr/arrr)-(ar-1)/arrr;
		cout<<j<<endl;
		return 0;
	}
    j=(arr)/arrr;
	printf("%lld\n",j+1);
	return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
int main(void) {
    char s[5];
    scanf("%s",s);
    int t = 0;
    if(s[0] == s[1]) {
        if(s[0] != s[2] && s[2] == s[3]) {
            t = 1;
        }
    }
    if(s[0] == s[2]) {
        if(s[0] != s[1] && s[1] == s[3]) {
            t = 1;
        }
    }
    if(s[0] == s[3]) {
        if(s[0] != s[1] && s[1] == s[2]) {
            t = 1;
        }
    }

    if(t == 0) {
        printf("No\n");
    } else {
        printf("Yes\n");
    }
    return 0;
}

Measured memory_bytes: 128
input_lines = raw_input()
n1_n2_n3 = input_lines.rstrip().split(" ")
n1 = int(n1_n2_n3[0])
n2 = int(n1_n2_n3[1])
n3 = int(n1_n2_n3[2])
num_list = []
num_list.append(n1)
num_list.append(n2)
num_list.append(n3)
num_list.sort()
print str(num_list[0]) + " " + str(num_list[1]) + " " + str(num_list[2])

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

typedef long long int ll; 
#define fori(i, n) for (ll(i) = 0; (i) < (n); (i)++) 
#define foria(i, a, b) for (ll(i) = (a); (i) <= (b); (i)++) 
#define foriar(i, a, b) for (ll(i) = (a); (i) >= (b); (i)--)  
#define ff first 
#define ss second 
#define pb push_back 
#define pob pop_back
const ll mod = 1e9 + 7;

void solve()
{
    ll n;
    cin >> n;
    map<string, ll> m;
    string s[n];
    fori(i, n)
    {
    	cin >> s[i];
    	m[s[i]]++;
    }
    cout << "AC x " << m["AC"] << endl;
    cout << "WA x " << m["WA"] << endl;
    cout << "TLE x " << m["TLE"] << endl;
    cout << "RE x " << m["RE"] << endl;
}
int main()
{
    ios_base::sync_with_stdio(false); 
    cin.tie(NULL); 
    cout.tie(NULL);

    // ifstream cin("input.txt");    
    // ofstream cout("output.txt");

    ll t = 1;
    // cin >> t;
    for(ll _ = 0; _ < t; _++)
    {
        // cout << "Case #" << _ + 1 << ": ";
        solve();
    }
    return 0;
}

Measured memory_bytes: 6748
W, H, N = map(int, input().split())
xya = [list(map(int, input().split())) for _ in range(N)]

x1 = 0 #左端
x2 = W #右端
y3 = 0 #下端
y4 = H #上端

# 白い4角形が最小になる上下左右を見つける
for x,y,a in xya:
    if a == 1:
        x1 = max(x1, x)
    elif a == 2:
        x2 = min(x2, x)
    elif a == 3:
        y3 = max(y3, y)
    elif a == 4:
        y4 = min(y4, y)
else:
    # 右端が左端より左, 上端が下端より下,だと全部黒
    if x2 <= x1 or y4 <= y3:
        print(0)
    else:
        print((x2-x1) * (y4-y3))

Measured memory_bytes: 3064
//#include <ext/pb_ds/assoc_container.hpp> 
 //#include <ext/pb_ds/tree_policy.hpp>
//#include <bits/stdc++.h>
#include <iostream>
#include <iomanip>
#include <sstream>
#include <cstring>
#include <vector>
#include <deque>
#include <queue>
#include <set>
#include <map>
#include <valarray>
#include <iterator>
#include <functional>
#include <limits>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <cassert>
#include <unordered_map>
#include <unordered_set>
#include <stack>
using namespace std;
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define trace(x) cerr << #x << ": " << x << " " << endl;

typedef int64_t ll;
 
#define endl '\n'
#define int ll
ll mod=1e9+7;
ll mod1=1e9+5;
ll power(ll a,ll b)
{
    if(b==0) return 1;
    else if(b%2==0)
        return power(((((a)%mod)*((a)%mod))%mod),b/2)%mod;
    else return (((a)%mod)*(power(((((a)%mod)*((a)%mod))%mod),b/2)%mod))%mod;
}
inline ll inverse(ll a,ll md) {
  a %= md;
  if (a < 0) a += md;
  ll b = md, u = 0, v = 1;
  while (a) {
    ll t = b / a;
    b -= t * a; swap(a, b);
    u -= t * v; swap(u, v);
  }
  assert(b == 1);
  if (u < 0) u += md;
  return u;
}
  
  
 //using namespace __gnu_pbds;
 //#define ordered_set tree<pair<int,int>, null_type,less<pair<int,int>>, rb_tree_tag,tree_order_statistics_node_update>
//find_by_order(k)  returns iterator to kth element starting from 0;
//order_of_key(k) returns count of elements strictly smaller than k;
//erase,insert same as normal set
// mt19937 mrand(chrono::high_resolution_clock::now().time_since_epoch().count()); for randomized solution
const int ce=1e9+7;
ll fast_mod(ll input)
{
    return input < ce ? input : input%ce;
}
int fre[100001];
int co[11];
int n,k;
int f[100001];
int maxi;
int dp[501][5001];
int solve(int i,int rem)
{
	if(rem==0)
		return 0;
	if(i==maxi)
		return 0;
	int &res=dp[i][rem];
	if(res!=-1)
		return res;
	res=0;
	for(int j=1;j<=min(rem,k);j++)
	{
		res=max(res,co[j]+solve(i+1,rem-j));
	}
	return res;
}
int32_t main()
{
    IOS
   
    
    int n;
    cin>>n;
    int a[n+1];
    map<int,int> m;
    int sum=0;
    for(int i=1;i<=n;i++)
    {
    	cin>>a[i];
    	m[a[i]]++;
    	sum+=a[i];
    }
    int q;
    cin>>q;
    while(q--)
    {
    	int x,y;
    	cin>>x>>y;
    	sum-=m[x]*x;
    	sum+=m[x]*y;
    	m[y]+=m[x];
    	m[x]=0;
    	cout<<sum<<endl;;
    }

}       

Measured memory_bytes: 10376
#include "iostream"
#include <stdio.h>
#include <algorithm>
#include <stdlib.h>
#include <cstring>
#include <math.h>
#include <cctype>
#include <stack>
#include <vector>
#include <list>
#include <queue>
#include <set>
#include <map>
#include <bitset>
#include <iomanip>
using namespace std;
using ll=long long;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
#define MOD  1000000007
int dx[4]={0,0,-1,1},dy[4]={1,-1,0,0};


int main(int argc, char const *argv[]) {
  int n;
  ll a[1010],b[1010];
  std::cin >> n;
  for(int i=0; i<n; i++){
    std::cin >> a[i] >> b[i];
  }
  ll k=1,x=1,y=1;

  for(int i=0; i<n; i++){
    if(i==0) k=1;
    else{
      k=max((a[i-1]*k+a[i]-1)/a[i],(b[i-1]*k+b[i]-1)/b[i]);
    }
    x=a[i]*k;
    y=b[i]*k;
  }
  std::cout << x + y << '\n';

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define inf (long long)(1e18)
using namespace std;

long long n, a, b;
vector<int> p;
vector<vector<long long>> dp;

long long solve();

int main() {
  cin >> n >> a >> b;
  p.resize(n);
  for (auto &x : p) cin >> x;
  cout << solve() << endl;
  return 0;
}

long long solve() {
  long long res = inf;
  dp.assign(n + 1, vector<long long>(n + 1, inf));
  dp[0][0] = 0;
  for (int i = 0; i < n; ++i)
    for (int j = 0; j <= n; ++j)
      if (p[i] < j)
        dp[i + 1][j] = dp[i][j] + b;
      else if (p[i] > j)
        dp[i + 1][j] = dp[i][j] + a;
      else
        for (int k = 0; k < j; ++k) dp[i + 1][j] = min(dp[i + 1][j], dp[i][k]);
  for (int i = 0; i <= n; ++i) res = min(res, dp[n][i]);
  return res;
}

Measured memory_bytes: 198828
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rrep(i,n) for(int i=(int)(n-1);i>=0;i--)
#define FOR(i,n,m) for(int i=n;i<=(int)(m);i++)
#define RFOR(i,n,m) for(int i=(int)(n);i>=m;i--)
#define all(x) (x).begin(),(x).end()
#define sz(x) int(x.size())
typedef long long ll;
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;
using namespace std;
vector<int> dy={1,0,-1,0};
vector<int> dx={0,1,0,-1};
template<class T>
vector<T> make_vec(size_t a){
    return vector<T>(a);
}
template<class T, class... Ts>
auto make_vec(size_t a, Ts... ts){
    return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}

struct UnionFind {
    vector<int> data;
    UnionFind(int size): data(size,-1) {
    }
    
    int root(int x){
        return (data[x] < 0)? x : data[x]=root( data[x] );
    }
    
    bool unite(int x, int y){
        x=root(x);
        y=root(y);
        if( x != y ){
            if( data[y] < data[x] ) swap(x, y);
            data[x] += data[y];
            data[y] = x;
        }
        return x!=y;
    }
    
    bool find(int x, int y){
        return root(x) == root(y);
    }
    
    int size(int x){
        return -data[ root(x) ];
    }
};

int main(){
    int n;
    cin>>n;
    double m=(n%2==0 ? n/2 : n/2+1);
    cout<<fixed<<setprecision(10)<<(double) m/n<<endl;
}


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


int main()
{
    int N = 0, K = 0;
    string R = "", S = "", s = "";

    cin >> N >> K >> S;

    for ( int i = 0; i < N; i++ )
    {
        s = S[i];
        if ( i == K - 1 )
        {
            transform(s.begin(), s.end(), s.begin(), ::tolower);
            R += s;
            continue;
        }
        R += s;
    }

    cout << R << endl;
}


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

int main(){
    int n;
    cin >> n;
    string s;
    cin >> s;
    vector<int>R,B,G;
    for(int i=0;i<n;i++){
        if(s[i] == 'R'){
            R.push_back(i+1);
        }else if(s[i] == 'B'){
            B.push_back(i+1);
        }else{
            G.push_back(i+1);
        }
    }   
    long long cnt = R.size() * B.size() * G.size();;
    for(int i=0;i<n;i++){
        for(int k=1;k<n;k++){
            int I,J,K;
            long long a=i;
            long long b=i+k;
            long long c=b+k;
            if(c < n){
                if(s[a] != s[b] && s[a] != s[c] && s[b] != s[c]){
                    cnt--;
                }       
            }   
        }
    }
    cout << cnt << endl;
    return 0;
}

Measured memory_bytes: 3632
import Control.Applicative ((<$>), (<*>))
import Control.Monad
import Data.List

main :: IO ()
main = do
  solve <$> replicateM 7 (getl $ wrds toInt) >>= mapM_ print

solve :: [[Int]] -> [Int]
solve = map f
  where
    f [a, b] = a - b

toInt :: String -> Int
toInt = read

wrds :: (String -> a) -> String -> [a]
wrds f = map f . words

getl :: (String -> a) -> IO a
getl f = f <$> getLine

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

int main() {
    ll N = 0; cin >> N;
    vector<ll> A(N+1, -1);
    vector<ll> B(N+1, -1);

    rep(i, N) cin >> A.at(i+1) >> B.at(i+1);


    ll sum = 0;
    for(ll i=N; i>=1; i--){
        ll tmp = 0;
        A.at(i) += sum;
        if(A.at(i)%B.at(i) == 0) continue;
        else{
            tmp = B.at(i) - A.at(i)%B.at(i);
            sum += tmp;
        }
    }
    cout << sum << endl;

}

Measured memory_bytes: 1792
#include <algorithm>
#include <cstdlib>
#include <iostream>
using namespace std;

struct fraction {
	typedef long long frac_t;
	frac_t nume, deno;

	void reduce() {
		frac_t g = __gcd(nume, deno);
		nume /= g; deno /= g;
	}

	fraction(frac_t n = 1, frac_t d = 1):nume(n), deno(d) { reduce(); }
	fraction(const fraction& f):nume(f.nume), deno(f.deno) {}

	fraction operator+(const fraction& o) const {
		frac_t rdeno = deno / __gcd(deno, o.deno) * o.deno;
		frac_t rnume = rdeno / deno * nume + rdeno / o.deno * o.nume;
		return fraction(rnume, rdeno);
	}

	fraction operator-(const fraction& o) const {
		frac_t rdeno = deno / __gcd(deno, o.deno) * o.deno;
		frac_t rnume = rdeno / deno * nume - rdeno / o.deno * o.nume;
		return fraction(rnume, rdeno);
	}

	fraction operator/(const fraction& o) const {
		frac_t g1 = __gcd(nume, o.nume);
		frac_t g2 = __gcd(o.deno, deno);
		frac_t rnume = (nume / g1) * (o.deno / g2);
		frac_t rdeno = (deno / g2) * (o.nume / g1);
		return fraction(rnume, rdeno);
	}

	fraction &operator+=(const fraction& o) {
		frac_t rdeno = deno / __gcd(deno, o.deno) * o.deno;
		nume = rdeno / deno * nume + rdeno / o.deno * o.nume;
		deno = rdeno;
		reduce();
		return *this;

	}

	fraction operator+(int d) {
		return *this + fraction(d, 1);
	}

	fraction operator/(int d) {
		return fraction(nume, deno * d);
	}

	bool operator==(const fraction& o) const {
		return nume == o.nume && deno == o.deno;
	}

	bool operator<(const fraction& o) const {
		frac_t lcm_deno = deno / __gcd(deno, o.deno) * o.deno;
		return lcm_deno / deno * nume < lcm_deno / o.deno * o.nume;
	}

	double toDouble() const {
		return (double)nume / deno;
	}
};

int H;

constexpr double EPS = 1e-10;
const fraction one(1, 1);

void normalize(int &h, int &m, fraction &fs) {
	if(fs.toDouble() >= 60) {
		fs += fraction(-60, 1);
		if(++m >= 60) {
			m = 0;
			if(++h >= H) {
				h = 0;
			}
		}
	}
}

template<class T>
T get_angle(T a, T b) {
	if(b < a) swap(a, b);
	return min(b - a, a - b + 1);
}

bool equal(double a, double b) {
	return abs(a - b) < EPS;
}

bool strict_ok(int h, int m, const fraction &fs) {
	fraction theta_s = fs / 60;
	fraction theta_m = fraction(m, 60) + theta_s / 60;
	fraction theta_h = fraction(h, H) + theta_m / H;
	return !(theta_m == theta_h)
		&& get_angle(theta_s, move(theta_m)) == get_angle(move(theta_s), move(theta_h));
}

bool ok(int h, int m, const fraction &fs) {
	const double theta_s = fs.toDouble() / 60.0;
	const double theta_m = (m + theta_s) / 60.0;
	const double theta_h = (h + theta_m) / H;
	return equal(get_angle(theta_s, theta_m), get_angle(theta_s, theta_h))
		&& !equal(theta_m, theta_h) && strict_ok(h, m, fs);
}

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

	for(int h, m, s; cin >> H >> h >> m >> s && H;) {
		const fraction d(1, 119 * H - 1);
		for(fraction fs(s, 1);; normalize(h, m, (fs += d))) {
			if(ok(h, m, fs)) {
				cout << h << " " << m << " " << fs.nume << " " << fs.deno << endl;
				break;
			}
		}
	}

	return EXIT_SUCCESS;
}

Measured memory_bytes: 1192
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
using namespace std;

int main(){
    string s;
    cin >> s;
    if(s[s.length()-1] == 's'){
        cout << s << "es" << endl;
    }else{
        cout << s << "s" << endl;
    }
    return 0;
}

Measured memory_bytes: 3624
def read_int():
    return int(input().strip())


def read_ints():
    return list(map(int, input().strip().split(' ')))


def solve():
    A, B, C = read_ints()
    if sorted([A, B, C]) == [5, 5, 7]:
        return 'YES'
    return 'NO'


if __name__ == '__main__':
    print(solve())

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

const int D = 80*160+10;
const int D2 = D*2;
typedef bitset<D2> bs;

int a[100][100];
bs dp[90][90];

int main() {
  int h, w;
  cin >> h >> w;
  rep(i,h)rep(j,w) {
    int x;
    cin >> x;
    a[i][j] = x;
  }
  rep(i,h)rep(j,w) {
    int x;
    cin >> x;
    a[i][j] = abs(x-a[i][j]);
  }

  dp[0][0][D-a[0][0]] = 1;
  dp[0][0][D+a[0][0]] = 1;
  rep(i,h)rep(j,w) {
    if (i) {
      dp[i][j] |= dp[i-1][j]<<a[i][j];
      dp[i][j] |= dp[i-1][j]>>a[i][j];
    }
    if (j) {
      dp[i][j] |= dp[i][j-1]<<a[i][j];
      dp[i][j] |= dp[i][j-1]>>a[i][j];
    }
  }
  int ans = D2;
  rep(i,D2) if (dp[h-1][w-1][i]) {
    ans = min(ans, abs(i-D));
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 24704
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll read(){
	ll a=0,b=getchar(),c=1;
	while(!isdigit(b))c=b=='-'?-1:1,b=getchar();
	while(isdigit(b))a=a*10+b-'0',b=getchar();
	return a*c;
}
ll k,an1=2,an2=2,a[100005];
int main(){
	k=read();
	for(int i=0;i<k;i++)
		a[i]=read();
	if(a[k-1]!=2)return puts("-1"),0;
	for(int i=k-1;i;i--){
		an2=((an2+a[i]-1)/a[i-1])*a[i-1];
		an1=((an1+a[i-1]-1)/a[i-1])*a[i-1];
		if(an1>an2)return puts("-1"),0;
	}
	an2+=a[0]-1;
	cout << an1 << " " << an2;
	return 0;
}

Measured memory_bytes: 1024
//Name: Dragon's Cruller
//Level: 3
//Category: 最短経路,探索
//Note:

/**
 * 状態は高々9!通りしかないので、数の並び方を適当にエンコードして状態として使い、ダイクストラで最短経路を求めればよい。
 *
 * オーダーは O(V log V)。
 * ただしVは状態数の総数で、V=9!。
 */
#include <iostream>
#include <vector>
#include <algorithm>
#include <unordered_map>
#include <queue>
#include <cassert>
#include <array>

using namespace std;

typedef long long LL;

array<int,9> field, goal;

LL encode() {
    LL res = 0;
    for(int i = 0; i < 9; ++i) {
        res *= 9;
        res += field[i];
    }
    return res;
}

void decode(LL v) {
    for(int i = 0; i < 9; ++i) {
        field[8-i] = v % 9;
        v /= 9;
    }
}

const int TO[4][9] = {
    {1, 2, 3, 4, 5, 6, 7, 8, 0},
    {8, 0, 1, 2, 3, 4, 5, 6, 7},
    {6, 7, 8, 0, 1, 2, 3, 4, 5},
    {3, 4, 5, 6, 7, 8, 0, 1, 2},
};
bool solve() {
    int CH, CV;
    if(!(cin >> CH >> CV)) return false;
    if(!CH && !CV) return false;

    for(int i = 0; i < 9; ++i) {
        cin >> field[i];
    }
    for(int i = 0; i < 9; ++i) {
        cin >> goal[i];
    }
    LL G = 0;
    {
        array<int,9> tmp = field;
        field = goal;
        G = encode();
        field = tmp;
    }

    unordered_map<LL,int> memo;
    memo[0] = encode();
    priority_queue<pair<int,int>> q;
    q.push(make_pair(0, encode()));
    while(!q.empty()) {
        const int cost = -q.top().first;
        const LL state = q.top().second;
        q.pop();
        if(memo.count(state) && memo[state] < cost) continue;
        if(state == G) {
            cout << cost << endl;
            return true;
        }
        decode(state);

        int zero = 0;
        while(field[zero] != 0) ++zero;

        for(int d = 0; d < 4; ++d) {
            swap(field[zero], field[TO[d][zero]]);
            const int nc = cost + (d < 2 ? CH : CV);
            const int ns = encode();
            swap(field[zero], field[TO[d][zero]]);
            if(memo.count(ns) && memo[ns] <= nc) continue;
            memo[ns] = nc;
            q.push(make_pair(-nc, ns));
        }
    }
    assert(false);
    return true;
}

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

    while(solve()) ;
    return 0;
}

Measured memory_bytes: 19872
/*Enter your code here. Read input from STDIN. Print your output to STDOUT*/
#include <bits/stdc++.h>
using namespace std;
#define endl "\n";
#define int long long
#define fastio ios_base::sync_with_stdio(0); cin.tie(0)
#define maxN 1000000

int32_t main()
{
    fastio;
    
    int n, k; cin >> n >> k;
    vector<int> a(n);
    for(int i=0; i<n; i++) cin >> a[i];

    vector<bool> dp(k+1,false);

    for(int stones=0; stones<=k; stones++){
        for(int x: a){
            if(stones-x>=0 && !dp[stones-x]){
                dp[stones] = true;
            }
        }
    }

    puts(dp[k]?"First":"Second");
    return 0;   
}
    


Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
#ifdef _DEBUG
#include "dump.hpp"
#else
#define dump(...)
#endif

//#define int long long
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define all(c) begin(c),end(c)
const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)(1e9) + 7;
template<class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if (b < a) { a = b; return true; } return false; }

template<typename Value>
struct BinaryHeap {
	static const int MAX_N = 2000010;
	vector<Value> heap;
	int sz;
	BinaryHeap() :heap(MAX_N), sz(0) {};
	void push(Value x) {
		int v = sz++;
		while (v > 0) {
			int p = (v - 1) / 2;
			if (heap[p] >= x)break;
			heap[v] = heap[p];
			v = p;
		}
		heap[v] = x;
	}
	const Value pop() {
		Value ret = heap[0];
		Value back = heap[--sz];
		int v = 0;
		while (v * 2 + 1 < sz) {
			// l ??¨ r ??????????°???????????????¨???????????????
			int l = v * 2 + 1, r = v * 2 + 2;
			int u = (r >= sz || heap[l] > heap[r]) ? l : r;
			// ???????????¢???????????????
			if (heap[u] <= back)break;
			heap[v] = heap[u];
			v = u;
		}
		heap[v] = back;
		return ret;
	}
	const Value top() {
		return heap[0];
	}
};

signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n, q; scanf("%d%d", &n, &q);
	vector<int> a(q), v(q); rep(i, 0, q) {
		scanf("%d%d", &a[i], &v[i]);
		a[i]--;
	}
	using T = tuple<int, int>;
	//priority_queue<T> pq;
	BinaryHeap<T> pq;
	rep(i, 0, n)pq.push(T(0, -i));
	vector<int> point(n);
	rep(i, 0, q) {
		point[a[i]] += v[i];
		pq.push(T(point[a[i]], -a[i]));
		while (true) {
			int p, u; tie(p, u) = pq.top(); pq.pop();
			if (point[-u] != p)continue;
			printf("%d %d\n", -u + 1, p);
			pq.push(T(p, u));
			break;
		}
	}
	return 0;
}

Measured memory_bytes: 23096
import numpy as np
N = int(input())
X = np.array([list(map(int, input().split())) for _ in range(N)])

def d(X1, X2):
    return ((X1[0] - X2[0]) ** 2 + (X1[1] - X2[1]) ** 2) ** 0.5

sum = 0
for i in range(N):
    for j in range(i):
        sum += d(X[i], X[j])

ans = sum * 2 / N
print(ans)


Measured memory_bytes: 22420
import sys
sys.setrecursionlimit(10**6)


N = int(input())
A = list(map(int, input().split()))
INF = float('inf')
cnt = 0


def merge(left, mid, right):
    global cnt
    L = A[left:mid]+[INF]
    R = A[mid:right]+[INF]
    l = 0
    r = 0

    for i in range(right-left):
        cnt += 1
        if L[l] < R[r]:
            A[left+i] = L[l]
            l += 1
        else:
            A[left+i] = R[r]
            r += 1


def merge_sort(left, right):
    if left+1 < right:
        mid = (left+right)//2
        merge_sort(left, mid)
        merge_sort(mid, right)
        merge(left, mid, right)


merge_sort(0, N)
print(*A)
print(cnt)



Measured memory_bytes: 61648
def num2alpha(num):
    if num<=26:
        return chr(64+num)
    elif num%26==0:
        return num2alpha(num//26-1)+chr(90)
    else:
        return num2alpha(num//26)+chr(64+num%26)

n=int(input())
print(str.lower(num2alpha(n)))


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

int main() {
  int N, M, R;
  cin >> N >> M >> R;
  vector<int> r(R);
  for (int i = 0; i < R; i++) {
    cin >> r.at(i);
    r.at(i)--;
  }

  vector<vector<int>> G(N, vector<int>(N, 1e9));
  for (int i = 0; i < N; i++) G.at(i).at(i) = 0;
  for (int a, b, t; cin >> a >> b >> t;) G.at(--a).at(--b) = t, G.at(b).at(a) = t;
  for (int i = 0; i < N; i++)
    for (int j = 0; j < N; j++)
      for (int k = 0; k < N; k++) G.at(j).at(k) = min(G.at(j).at(k), G.at(j).at(i) + G.at(i).at(k));

  int ans = 1e9;
  sort(r.begin(), r.end());
  do {
    int tmp = 0;
    for (int i = 0; i + 1 < R; i++) {
      tmp += G.at(r.at(i)).at(r.at(i + 1));
    }
    ans = min(ans, tmp);
  } while (next_permutation(r.begin(), r.end()));
  cout << ans << "\n";
}

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

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


Measured memory_bytes: 256
import sys
A=str(input())
B=str(input())
C=str(input())
 
alt="a"
while True:
  if alt == "a":
    if A=="":
      print("A")
      sys.exit()
    alt = A[0]
    A=A[1:]
  if alt == "b":
    if B=="":
      print("B")
      sys.exit()
    alt = B[0]
    B=B[1:]
  if alt == "c":
    if C=="":
      print("C")
      sys.exit()
    alt = C[0]
    C=C[1:]

Measured memory_bytes: 3064
#include <cstdlib>
#include <cstdio>
#include <algorithm>
#include <cassert>
#define maxn 
#define maxm 
#define rep(i, l, r) for (register int i = l; i <= r; i++)
#define per(i, r, l) for (register int i = r; i >= l; i--)
//#define DEBUG
using namespace std;

int main(){
	int n;
	scanf("%d", &n);
	int max = 0, sum = 0, x;
	rep(i, 1, n) {
		scanf("%d", &x);
		if (x >= max) sum++, max = x;
	}
	printf("%d", sum);
	return 0;
}

Measured memory_bytes: 128
import sys
input = sys.stdin.readline
from collections import deque
def main():
    N = int( input())
    A = [deque()] + [deque( map( int, input().split())) for _ in range(N)]
    Days = [0]*(N+1)
    NOW = [0]*(N+1)
    # for i in range(1, N+1):
    #     a = A[i].popleft()
    #     if NOW[a] == i:
    #         Days[a] = Days[i] = max(Days[a], Days[i])
    q = deque( [ i+1 for i in range(N)])
    while q:
        i = q.popleft()
        if not A[i]:
            continue
        a = A[i].popleft()
        if NOW[a] == i:
            Days[a] = Days[i] = max(Days[a], Days[i])+1
            q.append(i)
            q.append(a)
            NOW[a] = NOW[i] = 0
        else:
            NOW[i] = a
    for i in range(1,N+1):
        if A[i]:
            print(-1)
            return
    print( max(Days))
if __name__ == '__main__':
    main()


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

using namespace std;

typedef long long ll;
typedef pair<int, int> P;
typedef vector<int> Vec;

#define REP(i, a, b) for(ll i=(a); i<(b); i++)
#define rep(i, n) REP(i, 0, n)
const int INF=1e9;
#define Yes(n) cout << ((n) ? "Yes" : "No") << endl;
#define ALL(v) v.begin(), v.end()
#define dbg(x_) cerr << #x_ << ":" << x_ << endl;
#define pb(x) push_back(x)
#define sum(v) accumulate(ALL(v),0)

template<typename T1, typename T2>
ostream &operator<<(ostream &s, const pair<T1, T2> &p) { return s<<"("<<p.first<<", "<<p.second<<")"; }

// vector
template<typename T>
ostream &operator<<(ostream &s, const vector<T> &v) {
    int len=v.size();
    for(int i=0; i<len; ++i) {
        s<<v[i];
        if(i<len-1) s<<"	";
    }
    return s;
}

// 2 dimentional vector
template<typename T>
ostream &operator<<(ostream &s, const vector<vector<T> > &vv) {
    int len=vv.size();
    for(int i=0; i<len; ++i) {
        s<<vv[i]<<endl;
    }
    return s;
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n;
    cin>>n;
    cout<<n*n*3<<endl;
    return  0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
ll w[100+5];
ll v[100+5];
ll dp[100+5][100000+5];
int n, W, V;
ll ans(int rval, int idx){
    if(rval==0) return 0;
    if(idx==n) return INT_MAX;
if(dp[idx][rval]!=-1) return dp[idx][rval];
if(v[idx]>rval) return dp[idx][rval] = ans(rval, idx+1);
else{
    return dp[idx][rval] = min(ans(rval-v[idx], idx+1) +w[idx],  ans(rval, idx+1));
}
}
int main(){
    cin >> n >> W;
    for(int i=0; i<n; i++) { cin >> w[i] >> v[i]; V += v[i];}
    for(int i=0; i<105; i++){
        for(int j=0; j<100005; j++){
            dp[i][j] = -1;
        }
    }
    for(int i=V; i>=0; i--){
        if(ans(i,0)<=W)
        {
            cout << i;
            return 0;
        }
    }
return 0;
}


Measured memory_bytes: 85676
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
const ll MOD = 998244353;
const double EPS = 1e-10;

int main() {
	string S;
	cin >> S;
	ll sum = 0;
	ll ans = 0;
	for (int i = S.size() - 1; i >= 0; i--) {
		if (S[i] == 'B') ans += sum;
		else sum++;
	}
	cout << ans << endl;
}

Measured memory_bytes: 640
#include <iostream>
#include <vector>
using namespace std;
 
int main() {
	int n,k;
	cin >> n >> k;
	vector <char> s(n);
	for (int i=0; i<n; i++) cin >> s[i];
	if (s[k-1]=='A') s[k-1]='a';
	if (s[k-1]=='B') s[k-1]='b';
	if (s[k-1]=='C') s[k-1]='c';
	for (int i=0; i<n; i++) cout << s[i];
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#pragma GCC optimize("Ofast")
using namespace std;
#define bye return 0
#define Yes cout << "Yes" << "\n"
#define No  cout << "No" << "\n"
#define YES cout << "YES" << "\n"
#define NO cout << "NO" << "\n"
#define endl cout << "\n"

void func(vector<int> &v){
	reverse(v.begin(), v.end());
}

int main(){
	/*ios::sync_with_stdio(false);
    cin.tie(NULL);*/
   vector<int> v;
   int a, b, c;
   cin >> a;
   v.push_back(a);
   cin >> b;
   v.push_back(b);
   cin >> c;
   v.push_back(c);

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

   int d = v[0]+v[1];
   int e = v[2];
   if(d==e){
   	Yes;
   }else{
   	No;
   }
   bye;
    
}

Measured memory_bytes: 256
// Hail god Yato
 
#include <bits/stdc++.h> 
using namespace std;
 
#define hs ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
typedef long long ll;
const ll mod = 1000000007;
const ll INF = 1e18;
const ll MAX = 100001;
//
//
ll n, m, x;
void solve(){
    cin>>n>>m>>x;
    vector<vector<int>> vec(n, vector<int>(m+1));
    for(int i = 0; i < n; i++){
        for(int j = 0; j <= m; j++){
            cin>>vec[i][j];
        }
    }

    ll ans = INF;
    for(int i = 0; i < (1<<n); i++){
        vector<int> temp(m, 0);
        ll price = 0;
        for(int j = 0; j < n; j++){
            if((i>>j)&1){
                price += vec[j][0];
                for(int k = 1; k < m+1; k++)
                    temp[k-1] += vec[j][k];
            }
        }

        int f = 0;
        for(int j = 1; j < m+1; j++){
            if(temp[j-1] < x){
                f = 1;
                break;
            }
        }
        if(!f){
            ans = min(ans, price);
        }
    }
    if(ans == INF)
        cout<<"-1";
    else
        cout<<ans;
}
int main(){ 
        hs;
        ll t;
        t=1;
        // cin>>t;
        for (int i=1; i<=t; i++){
                //cout<<"Case #"<<i<<": ";
                solve();
         }
        return 0; 
}

Measured memory_bytes: 3692
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
  ll A,B,C;
  cin>>A>>B>>C;
  if(A-B==C||B-A==C) printf("Yes\n");
  else if(C-A==B||A-C==B) printf("Yes\n");
  else if(C-B==A||B-C==A) printf("Yes\n");
  else cout<<"No"<<endl;
  return 0;
}
	


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

int main(){
  int x, y;
  cin >> x >> y;
  
  bool ok = true;
  if(y % 2) ok = false;
  if(y < x*2) ok = false;
  if(y > x*4) ok = false;
  
  if(ok) cout << "Yes" << endl;
  else cout << "No" << endl;
}

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

struct item {
  int zero, sum;
};

int main () {
  int n, k;
  string s;

  cin >> n >> k >> s;

  vector<item> a;
  // 1(01)(01)...(01)
  if(s[0] == '0') a.push_back(item{0,0});
  for(int i = 0, l = s.size(); i < l; ) {
    item it = item{0,0};
    while(i < l && s[i] == '0') {
      it.zero++;
      i++;
    }
    it.sum += it.zero;
    while(i < l && s[i] == '1') {
      it.sum++;
      i++;
    }
    a.push_back(it);
  }

  int sum = a[0].sum;
  int ans = sum;
  for(int i = 1; i < a.size(); i++) {
    sum += a[i].sum;
    if(i > k) sum -= a[i-k].zero + (a[i-k-1].sum - a[i-k-1].zero);
    ans = max(ans, sum);
  }

  cout << ans << endl;

  return 0;
}


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

int main() {
  int a, b;
  cin >> a >> b;
  if(!(a % 3) || !(b % 3) || !((a + b) % 3)) {
    cout << "Possible" << endl;
  } else {
    cout << "Impossible" << endl;
  }
}

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

int main(){
    ll n;
    cin >> n;
    map<ll, ll> a;
    rep(i, n){
        ll an;
        cin >> an;
        a[an]++;
    }
    ll ans = 0;
    for(auto i : a){
        if(i.second < i.first) ans += i.second;
        else if(i.second > i.first) ans += i.second - i.first;
    }
    cout << ans << endl;
    return 0;
}

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


int main()
{
    // koi number kisi ka multiple hai toh answer main nhi hoga
    int n;
    cin>>n;
    int arr[n];
    int ma =0;
    unordered_map<int,int>freq;
    for(int i=0;i<n;i++)
    {
        cin>>arr[i];
        ma = max(ma,arr[i]);
        freq[arr[i]]++;
    }
    int check[ma + 1];
    for(int i=0;i<=ma;i++)
        check[i] =0;
    int ans =0;
    for(int i=0;i<n;i++)
    {
        for(int j=arr[i]*2;j<=ma;j=j+arr[i])
            check[j] =1;
        if(freq[arr[i]]>1)
            check[arr[i]] = 1;
    }
    for(int i=0;i<n;i++)
    {
        if(check[arr[i]]==0)
            ans++;
    }
    cout<<ans;
}


Measured memory_bytes: 16068
n = int(input())
mem = [[0]*10 for _ in range(10)]
for i in range(1,n+1):
    a = int(str(i)[0])
    b = int(str(i)[-1])
    mem[a][b] +=1

ans = 0
    
for i in range(1,n+1):
    a = int(str(i)[0])
    b = int(str(i)[-1])
    ans += mem[b][a]
print(ans)

Measured memory_bytes: 3064
#include <stdio.h>
#include <stdlib.h>
typedef struct dinnerr{
    long a;
    long b;
} dinner;
int c(const void *a,const void *b){
    dinner *da=(dinner *)a;
    dinner *db=(dinner *)b;
    long das=(da->a)+(da->b),dbs=(db->a)+(db->b);
    if(das<dbs) return 1;
    if(das>dbs) return -1;
    return 0;
}
long suma(dinner *d,int n){
    long s=0;
    int i;
    for(i=0;i<n;i+=2)s+=d[i].a;
    return s;
}
long sumb(dinner *d,int n){
    long s=0;
    int i;
    for(i=1;i<n;i+=2)s+=d[i].b;
    return s;
}
int main(void){
    int n,i;
    scanf("%d",&n);
    dinner d[n];
    for(i=0;i<n;i++)scanf("%ld%ld",&d[i].a,&d[i].b);
    qsort(d,n,sizeof(dinner),c);
    printf("%ld",suma(d,n)-sumb(d,n));
}

Measured memory_bytes: 3324
#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>

using namespace std;

static bool judge_rightTri(vector<int> &dataset) {

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

	if ((pow(dataset.at(0), 2) + pow(dataset.at(1), 2)) == pow(dataset.at(2), 2)) {
		return true;
	}

	return false;
}

int main(void) {
	int input_num;
	cin >> input_num;

	vector<vector<int>> input(input_num, vector<int>(3, 0));

	for (vector<int> &dataset : input) {
		for (int &data : dataset) {
			cin >> data;
		}
	}

	for (vector<int> &dataset : input) {
		if (true == judge_rightTri(dataset)) {
			cout << "YES" << endl;
		}
		else {
			cout << "NO" << endl;
		}
	}

	return 0;
}



Measured memory_bytes: 3056
#include<bits/stdc++.h>
using namespace std;
int l1,l2,r1,r2;
int main(){
    cin>>l1>>l2>>r1>>r2;
    if(l1+l2 > r1+r2) cout<<"Left"<<endl;
    else if(l1+l2 < r1+r2) cout<<"Right"<<endl;
    else cout<<"Balanced"<<endl;
}

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

#define INFINITE 1000000

vector<int> v;
vector<int> dp;
int n;

int rec(int i)
{
    if(i>=n)
        return INFINITE;
    if(i==n-1)
        return 0;
    if(dp[i]!=-1)
        return dp[i];
    int a,b;
    a=abs(v[i+1]-v[i])+rec(i+1);
    b=abs(v[i+2]-v[i])+rec(i+2);
    return dp[i]=min(a,b);
}

int main()
{
    cin>>n;
    int i;
    for(i=0;i<n;i++)
    {
        int x;
        cin>>x;
        v.push_back(x);
        dp.push_back(-1);
    }
    v.push_back(0);
    v.push_back(0);
    int no=rec(0);
    cout<<no;
    return 0;
}


Measured memory_bytes: 5876
#include <iostream>
#include <stdio.h>
#include <string>
#include <vector>
#include <cmath>
#include <algorithm>

using namespace std;

int main()
{
  string a,b,c;
  cin >> a >> b >> c;
  if(a[a.size()-1]==b[0] && b[b.size()-1]==c[0])
    cout << "YES" << endl;
  else
    cout << "NO" << endl;

  return 0;
}


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

int main() {
    int n, m;
    cin >> n >> m;
    vector<vector<pair<int, int>>> x(n);
    for (int i = 0; i < m; i++) {
        int l, r, d;
        cin >> l >> r >> d;
        x[l-1].emplace_back(r-1, d);
        x[r-1].emplace_back(l-1, -d);
    }

    string ans = "Yes";
    vector<int> d(n, 1e9);
    for (int i = 0; i < n; i++) {
        if (d[i] != 1e9) continue;
        queue<int> q;
        q.emplace(i);
        d[i] = 0;
        while (!q.empty()) {
            int b = q.front(); q.pop();
            for (auto& e : x[b]) {
                if (d[e.first] == 1e9) {
                    q.emplace(e.first);
                    d[e.first] = d[b] + e.second;
                } else if (d[e.first] != d[b] + e.second) {
                    ans = "No";
                }
            }
        }
    }

    cout << ans << endl;
}


Measured memory_bytes: 9344
#include <numeric>
#include <bits/stdc++.h>
#include <utility>
#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>
#include <math.h>
#include <string>
#define ll long long
#define ull unsigned long long
#define make(type,x) type x; cin>>x
#define make2(type,x,y) type x,y; cin>>x>>y
#define fr(x,y) for(long long x=0;x<y;x++)
#define makevec(x,y,n) vector <x> y(n); for(ll i=0;i<n;i++) cin>>y[i]
#define M (ll)1000000007
#define MM (ll) 1e8
#define INF (ll) 1e18

# define IOS ios_base::sync_with_stdio(false); cin.tie(NULL)


using namespace std;


template <typename T>
T modpow(T base, T exp, T modulus) {
  base %= modulus;
  T result = 1;
  while (exp > 0) {
    if (exp & 1) result = (result * base) % modulus;
    base = (base * base) % modulus;
    exp >>= 1;
  }
  return result;
}
bool sortbysec(const ll &a, const ll &b){
    return abs(a)>abs(b);
}

struct cmp {
	bool operator() (const pair<int, int> &a, const pair<int, int> &b) const {
		int lena = a.second - a.first + 1;
		int lenb = b.second - b.first + 1;
		if (lena == lenb) return a.first < b.first;
		return lena > lenb;
	}
};


struct c_h {
    size_t operator()(uint64_t x) const {
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        x ^= FIXED_RANDOM;
        return x ^ (x >> 16);
    }
};

ll calcpow(ll x, ll y)
{
    ll temp;
    if(y == 0)
        return 1;
    temp = calcpow(x, y / 2);
    if (y % 2 == 0)
        return temp * temp;
    else
    {
        if(y > 0)
            return x * temp * temp;
        else
            return (temp * temp) / x;
    }
}
ll gcd(ll a, ll b){
    if(b==0) return a;
    return gcd(b,a%b);

}
ll egcd(ll a, ll b, ll &x,ll &y){
    if(b==0){
        x=1;
        y=0;
        return a;
    }
    ll x1;
    ll y1;
    ll g=egcd(b,a%b,x1,y1);
    x=y1;
    y=x1-y1*(a/b);
    return g;
}


bool isprime(ll a){
bool flag=1;
for(ll i=2;i*i<=a;i++){
    if(a%i==0) {flag=0; break;}
}
return flag;
}

ll dx8[8]={1,0,-1,0,1,-1,1,-1};
ll dy8[8]={0,1,0,-1,1,-1,-1,1};
ll dx4[4]={0,0,1,-1};
ll dy4[4]={1,-1,0,0};
ll N=1e6;

int main(){
    IOS;
    make(string,s);
    ll n=s.length();
    ll ans=INF;
    for(char i ='a';i<='z';i++){
        ll prev=-1;
        ll mx=0;
        for(ll j=0;j<n;j++){
            if(s[j]==i){
                mx=max(mx,j-prev);
                prev=j;
            }
        }
        mx=max(mx,n-prev);
        ans=min(ans,mx);
    }
    cout<<ans-1<<endl;





    return 0;
}



Measured memory_bytes: 3612
import java.io.BufferedInputStream;
import java.io.IOException;
import java.io.InputStream;

public class Main {

	private static final int MOD = 1000000007;

	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int x = sc.nextInt();
		int[] a = new int[N];
		sc.fill(a);

		long count = 0;
		for (int i = 1; i < N; i++) {
			if (a[i] + a[i - 1] > x) {
				int eat = (a[i] + a[i - 1]) - x;
				a[i - 1] -= Math.max(eat - a[i], 0);
				a[i] -= Math.min(a[i], eat);
				count += eat;
			}
		}

		System.out.println(count);
	}

	public static class Scanner {
		private BufferedInputStream inputStream;

		public Scanner(InputStream in) {
			inputStream = new BufferedInputStream(in);
		}

		public int nextInt() throws IOException {
			int num = 0;
			int sign = 1;

			int read = skip();
			if (read == '-') {
				sign = -1;
				read = inputStream.read();
			}

			do {
				num = num * 10 + sign * (read - 0x30);
			} while ((read = inputStream.read()) > 0x20);

			return num;
		}

		public void fill(int[] a) throws IOException {
			for (int i = 0; i < a.length; i++) {
				a[i] = nextInt();
			}
		}

		public void fill(int[] a, int[] b) throws IOException {
			if (a.length != b.length) {
				throw new IllegalArgumentException();
			}

			for (int i = 0; i < a.length; i++) {
				a[i] = nextInt();
				b[i] = nextInt();
			}
		}

		public long nextLong() throws IOException {
			long num = 0;
			int sign = 1;

			int read = skip();
			if (read == '-') {
				sign = -1;
				read = inputStream.read();
			}

			do {
				num = num * 10 + sign * (read - 0x30);
			} while ((read = inputStream.read()) > 0x20);

			return num;
		}

		public void fill(long[] a) throws IOException {
			for (int i = 0; i < a.length; i++) {
				a[i] = nextLong();
			}
		}

		public void fill(long[] a, long[] b) throws IOException {
			if (a.length != b.length) {
				throw new IllegalArgumentException();
			}

			for (int i = 0; i < a.length; i++) {
				a[i] = nextLong();
				b[i] = nextLong();
			}
		}

		public long[] nextLong(int n) throws IOException {
			long[] array = new long[n];
			for (int i = 0; i < n; i++) {
				array[i] = nextLong();
			}

			return array;
		}

		public String next() throws IOException {
			StringBuilder builder = new StringBuilder();

			int read = skip();
			do {
				builder.append((char) read);
			} while ((read = inputStream.read()) > 0x20);

			return builder.toString();
		}

		private int skip() throws IOException {
			int read;
			while ((read = inputStream.read()) <= 0x20)
				;

			return read;
		}
	}
}


Measured memory_bytes: 9428
#include<bits/stdc++.h>
#define rep(i,n,m) for(int i = (n); i <(m); i++)
#define rrep(i,n,m) for(int i = (n) - 1; i >=(m); i--)
#define pvec(vec) {for (auto v: vec) cout << v << ' '; cout << endl;}
#define pivec(vec) {rep(i, 0, vec.size()) cout << i << ':' << vec[i] << ' '; cout << endl;}

using namespace std;
using ll = long long;

int main()
{
    int x, y;
    cin >> x >> y;

    int b = (y-2*x)/2;
    int a = x - b;

    bool is_ok = true;
    is_ok &= a>=0 and b>=0;
    is_ok &= a + b == x;
    is_ok &= 2*a + 4* b == y;

    if (is_ok)
        cout << "Yes" << endl;
    else
        cout << "No" << endl;
    return 0;
}


Measured memory_bytes: 3632
import java.util.*;
public class Main { 
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		long n = sc.nextLong();
		long a = 0;
		for(long i = 1; i <= Math.sqrt(n); i++) {
			if(n % i == 0) {
				a = (i-1) + (n / i - 1);
			}
		}
		System.out.println(a);
     }
}

Measured memory_bytes: 21844
n = int(input())
s = str(input())
count = 0
for i in range(n):
    if s[i] == 'a' or s[i] == 'A':
        if i + 1 < n:
            if s[i + 1] == 'b' or s[i + 1] == 'B':
                if i + 2 < n:
                    if s[i + 2] == 'c' or s[i + 2] ==  'C':
                        count += 1
print(count)

Measured memory_bytes: 3060
get_number(Number) :-
    get_string(String),
    number_string(Number, String).

get_string(String) :-
    current_input(Input),
    read_string(Input, ' \n', '', _, String).

/* memo
    code(int)
    string_code(1, S, C), (C: code)
    char_code(X, Y) (X: char, Y: code)
    string_chars(S, S2) (S: string, S2: [char])
    to_lower(C, C2) (C: char? C2: code?)

    f(0, [], []).
    f(Z, [X|Xs], [Y|Ys]) :- X = Y, f(Z1, Xs, Ys), Z is Z1 + 1.
    f(Z, [_|Xs], [_|Ys]) :- f(Z, Xs, Ys).

    match: =, \=

    numeric: <,=<, >, >= (eval)
    lexicographically: @<. @=<, @>, @>=
    value?: =:=, =\= (eval)
    identical: ==, \==
*/

f(A, B, X) :- A =< X , X =< A + B.

main :-
    get_number(A),
    get_number(B),
    get_number(X),
    f(A, B, X) -> writeln("YES") ; writeln("NO").


Measured memory_bytes: 8080
W,H,N=map(int, input().split())
ls1=[0]
ls2=[W]
ls3=[0]
ls4=[H]
for i in range(N):
    tmp=list(map(int, input().split()))
    if tmp[2]==1:
        ls1.append(tmp[0])
    if tmp[2]==2:
        ls2.append(tmp[0])
    if tmp[2]==3:
        ls3.append(tmp[1])
    if tmp[2]==4:
        ls4.append(tmp[1])
print((min(ls2)-max(ls1))*(min(ls4)-max(ls3)) if min(ls2)>=max(ls1) and min(ls4)>=max(ls3) else 0)


Measured memory_bytes: 3192
#include <stdio.h>
char map[101][101];
int dy[4]={0,1,0,-1};
int dx[4]={1,0,-1,0};
int H,W;
void dfs(int y,int x){
  int ny,nx;
  int i,j;
  char c;
  c=map[y][x];
  map[y][x]='.';
  for(i=0;i<4;i++){
    nx=x+dx[i];
    ny=y+dy[i];
    if(0<=nx && nx<W && 0<=ny && ny<H && map[ny][nx]==c)dfs(ny,nx);
  }
}
int main(){
  int i,j;
  int count;
  while(1){
    count=0;
    for(j=0;j<100;j++){
      for(i=0;i<100;i++){
	map[j][i]='.';
      }
    }
    scanf("%d %d",&H,&W);
    if(H==0 && W==0)break;
    for(i=0;i<H;i++){
      scanf("%s",map[i]);
    }
    for(j=0;j<H;j++){
      for(i=0;i<W;i++){
	if(map[j][i]!='.'){
	  dfs(j,i);
	  count++;
	}
      }
    }
    printf("%d\n",count);
  }
  return 0;
}

Measured memory_bytes: 1080
#include "bits/stdc++.h"
using namespace std;
int a[555][555];
string s[555], p[555], q[555];

void calc(int lx, int rx, int ly, int ry) {
	int sz = min(ry - ly + 1, rx - lx + 1);
	for(int i = lx; i <= rx; i++) {
		a[i][ly] = a[i][ry] = 1;
	}
	for(int j = ly; j <= ry; j++) {
		a[lx][j] = a[rx][j] = 1;
	}
	if(sz > 1) a[lx + 1][ly] = 0;
	if(sz > 4) {
		a[lx + 2][ly + 1] = 1;
		calc(lx + 2, rx - 2, ly + 2, ry - 2);
	}
}

int main(int argc, char const *argv[])
{
	int h, w;
	cin >> h >> w;
	calc(0, h-1, 0, w-1);

	for(int i = 0; i < h; i++) {
		cin >> s[i];
		p[i] = q[i] = s[i];
	}
	for(int i = 0; i < h; i++) {
		for(int j = 0; j < w; j++) {
			if(a[i][j]) p[i][j] = '#';
			else q[i][j] = '#';
		}
	}
	for(int i = 0; i < h; i++) {
		cout << p[i] << endl;
	}
	cout << endl;
	for(int i = 0; i < h; i++) {
		cout << q[i] << endl;
	}
	return 0;
}


Measured memory_bytes: 2688
#include <iostream>
#include <cstring>
#include <vector>

#define ll long long
using namespace std;
#define pb push_back
const int N = 1e5 + 5;

inline int read() {
    int x = 0; char ch = getchar();
    for (; !isdigit(ch); ch = getchar());
    for (; isdigit(ch); ch = getchar()) x = x * 10 + ch - '0';
    return x;
}

void W(int x) { if (x >= 10) W(x / 10); putchar(x % 10 + '0'); }

vector<int> g[N];
int mx[N], n, col[N], Q, d[N], c[N], m, p[N];

void dfs(int x) {
    if (!col[x]) col[x] = c[Q];
    for (int i : g[x]) if (mx[x] - 1 > mx[i]) mx[i] = mx[x] - 1, dfs(i);
}

int main() {
    memset(mx, -1, sizeof(mx));

    n = read(), m = read();
    for (int i = 1, uu, vv; i <= m; i++)
        uu = read(), vv = read(), g[uu].pb(vv), g[vv].pb(uu);
    Q = read();
    for (int i = 1; i <= Q; i++) p[i] = read(), d[i] = read(), c[i] = read();

    for (; Q; Q--) if (d[Q] > mx[p[Q]]) mx[p[Q]] = d[Q], dfs(p[Q]);

    for (int i = 1; i <= n; i++) W(col[i]), puts("");
    return 0;
}

Measured memory_bytes: 11048
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<vector>
#include<map>
#include<set>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
int main(){
    int a,b,c;
cin>>a>>b>>c;
set<int>st{a,b,c};
if(st.size()==2)cout<<"Yes"<<endl;
else cout<<"No"<<endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include <iostream>
using namespace std;
 
int main() 
{
	int n;
	cin>>n;
	vector<double> a(n);
	for(int i=0;i<n;i++)
	{
		cin>>a[i];
	}
	int m=n/2+1;
	vector <vector <double> > dp(n+1,vector <double>(n+1,0.0));
	dp[0][0]=1;
	for(int i=1;i<=n;i++)
	{
		for(int j=0;j<=i;j++)
		{
			if(j==0)
			{
				dp[i][j]=dp[i-1][j]*(1-a[i-1]);
			}
			else
			{
				dp[i][j]=(a[i-1]*dp[i-1][j-1])+((1-a[i-1])*dp[i-1][j]);
			}
		}
	}
	double s=0.0;
	for(int i=m;i<=n;i++)
	{
		s+=dp[n][i];
	}
	cout<<setprecision(9)<<s;
	return 0;
}

Measured memory_bytes: 70656