akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i=0; i<n; i++)
#define rep1(i, n) for(int i=1; i<=n; i++)
#define repr(i, n) for(int i=n-1; i>=0; i--)
#define repr1(i, n) for(int i=n; i>=1; i--)
#define all(v) v.begin(),v.end()
using ll = long long;
using pii = pair<int, int>;
using pil = pair<int, ll>;
using pli = pair<ll, int>;
using pll = pair<ll, ll>;
const int INF = 1e9;
const ll LLINF = 1e18;
const ll MOD = 1e9+7;
const double EPS = 1e-10;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

template<typename T>
T gcd(T x, T y) {
    if (y==0) return x;
    return gcd(y, x % y);
}

template<typename T>
T lcm(T x, T y) {
    T g = gcd(x, y);
    return x / g * y;
}

int main() {
    ll k; cin >> k;
    ll sum = 0;
    for (ll a = 1; a <= k; a++) {
        for (ll b = 1; b <= k; b++) {
            for (ll c = 1; c <= k; c++) {
                sum += gcd(a, gcd(b, c));
            }
        }
    }
    cout << sum << endl;
}


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

using namespace std;

int main(void) {
    int a, b, k;
    cin >> a >> b >> k;
    
    for (int i = 0; i < k; i++) {
        if (i % 2 == 0) {
            if (a % 2 == 1)
                a--;
            b += a / 2;
            a /= 2;
        }
        else {
            if (b % 2 == 1)
                b--;
            a += b / 2;
            b /= 2;
        }
    }

    cout << a << " " << b << endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define mp make_pair
#define pb push_back
#define vll vector<ll>
#define endl "\n"
#define pll pair<ll,ll>
#define all(x) (x).begin() , (x).end()
#define f first
#define s second
#define pr(x) cout<<x<<endl;
#define pr2(x,y) cout<<x<<" "<<y<<endl;
#define pr3(x,y,z) cout<<x<<" "<<y<<endl;
#define prv(v) for(auto x:v) cout<<x<<" ";
#define ffs fflush(stdout);
#define int ll
using namespace std;
 
const ll N =(1e5+5);
const ll MOD = 1e9+7;
const ll INF = LLONG_MAX;
const ll LOG = 29;
#define PI 3.141592653589793238 


long long binpow(long long a, long long b) {
    a%=MOD;    
    long long res = 1;
    while (b > 0) {
        if (b & 1)
            res = (res * a)%MOD;
        a = (a * a)%MOD;
 
        
        b >>= 1;
    }
    res%=MOD;
    return res;
}

void solve(){
    ll x;
    cin>>x;
    ll cur =100;
    ll ans = 0;
    while(true){
        ans++;
        ll gg = cur/100;
        cur += gg;
        if(cur >= x){
            cout<<ans<<endl;
            return;
        }
    }
    
}   
 
 
signed main(){
    ios_base::sync_with_stdio(0);
    cin.tie(NULL);
     
    ll t=1;
    while(t--){
        solve();
    }    
}

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


int main()
{
  string X, Y;
  cin >> X >> Y;
  ll x = X.size(), y = Y.size();
  vector<vector<ll>> dp(x + 1, vector<ll>(y + 1, INF));
  for (ll i = 0; i < x; ++i)
  {
    dp.at(i).at(0) = i;
  }
  for (ll j = 0; j < y; ++j)
  {
    dp.at(0).at(j) = j;
  }
  // dp.at(1).at(0) = 1;
  // dp.at(0).at(1) = 1;
  for (ll i = 0; i < x; ++i)
  {
    for (ll j = 0; j < y; ++j)
    {
      // 削除
      dp.at(i + 1).at(j + 1) = min(dp.at(i + 1).at(j + 1), dp.at(i + 1).at(j) + 1);
      dp.at(i + 1).at(j + 1) = min(dp.at(i + 1).at(j + 1), dp.at(i).at(j + 1) + 1);
      //変更
      dp.at(i + 1).at(j + 1) = min(dp.at(i).at(j) + 1, dp.at(i + 1).at(j + 1));
      //一致
      if (X.at(i) == Y.at(j))
      {
        dp.at(i + 1).at(j + 1) = min(dp.at(i).at(j), dp.at(i + 1).at(j + 1));
      }
    }
  }
  cout << dp.at(x).at(y) << endl;
  // for (ll i = 0; i < min(x, y) + 1; ++i)
  // {
  //   cout << dp.at(i).at(i) << endl;
  // }
  // cout << dp.at(10).at(y) << endl;
  // for (ll i = 0; i < x + 1; ++i)
  // {
  //   for (ll j = 0; j < y + 1; ++j)
  //   {
  //     cout << dp.at(i).at(j) << ' ';
  //   }
  //   cout << endl;
  // }
}



Measured memory_bytes: 10816
//B Picture Flame
#include<bits/stdc++.h>
using namespace std;

int main()
{
  int h,w;
  cin>>h>>w;
  string s;
  for(int i=0;i<w+2;i++)
  {
    cout<<"#";
  }
  cout<<endl;
  for(int i=0;i<h;i++)
  {
    cin>>s;
    cout<<"#"<<s<<"#"<<endl;
  }
  for(int i=0;i<w+2;i++)
  {
    cout<<"#";
  }
  cout<<endl;
}


Measured memory_bytes: 256
#include<cstdio>
#include<iostream>
#include<list>
#include<cstring>
#include<stack>
#include<string>
#include<vector>
#include<set>
#include<algorithm>
using namespace std;
const int maxn = 100100;
int depth[maxn], n, vis[maxn], para[maxn], tid[maxn];
vector<int> son[maxn], nodes;
void dfs(int s, int dis)
{
	vis[s] = 1;
	depth[s] = dis;
	int sz = son[s].size();
	for(int i=0; i<sz; i++)
	{
		int val = son[s][i];
		//cout << val << endl;
		if (vis[val] == 1)
			continue;
		dfs(val, dis + 1);
	}
}

int main()
{
	
	int id, cn, tmp;
	for (int i = 0; i < maxn; i++)
		son[i].clear(), para[i]=-1;
	memset(vis, 0, sizeof vis);
	memset(tid, -1, sizeof id);
	scanf("%d", &n);
	for(int _=1; _<=n; _++)
	{
		scanf("%d%d", &id, &cn);
		nodes.push_back(id);
		if (cn > 0)
		{
			for (int i = 1; i <= cn; i++)
			{
				scanf("%d", &tmp);
				son[id].push_back(tmp);
				para[tmp]=id;
			}
		}
	}

	int root = -1;
	sort(nodes.begin(), nodes.end());
	for (auto it=nodes.begin(); it!=nodes.end(); it++)
	{
		//cout << "para" << para[i] << endl;
		if(para[*it]==-1)
		{
			root = *it;
			break;
		}
	}
	//cout << root << endl;
	dfs(root,0);
	string str = "";
	for (auto it=nodes.begin(); it!=nodes.end(); it++)
	{
		int i = *it;
		printf("node %d: parent = %d, depth = %d,",i,para[i],depth[i]);
		
		if (son[i].size() > 0)
		{
			if (para[i] == -1)
			{
				printf(" root, [");
			}
			else
				printf(" internal node, [");
			
			int sz = son[i].size();
			for (int pp = 0; pp < sz; pp++)
				printf("%d%s",son[i][pp],pp==sz-1?"]\n":", " );
		}
		else
		{
			if (para[i] != -1)
				printf(" leaf, []\n");
			else
				printf(" root, []\n");
		}
	}

	return 0;


}


Measured memory_bytes: 7732
#include <iostream>

using namespace std;

int main()
{
    int w, h, x, y, r;
    cin >> w >> h >> x >> y >> r;

    if (0 <= x - r && x + r <= w && 0 <= y - r && y + r <= h)
        cout << "Yes" << endl;
    else
        cout << "No" << endl;
}


Measured memory_bytes: 3104
#include<bits/stdc++.h>
//ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
//clock_t start=clock();clock_t end=clock();cout<<(double)(end-start)/CLOCKS_PER_SEC<<endl;
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef unsigned int ui;
typedef pair<int,int> pii;
typedef pair<pii,int> ppii;
typedef pair<int,pii> pipi;
typedef pair<ll,ll> pll;
typedef pair<pll,ll> ppll;
typedef pair<ll,pll> plpl;
typedef tuple<ll,ll,ll> tl;
typedef pair<double,double> pdd;
typedef vector<vector<ll>> mat;
ll mod=1000000007;
ll mod2=998244353;
ll mod3=1000003;
ll mod4=998244853;
ll mod5=1000000009;
ll inf=1LL<<60;
double pi=3.141592653589793238462643383279L;
double eps=1e-8;
#define rep(i,m,n) for(int i=m;i<n;i++)
#define rrep(i,n,m) for(int i=n;i>=m;i--)
#define srep(itr,st) for(auto itr=st.begin();itr!=st.end();itr++)
#define mrep(itr,mp) for(auto itr=mp.begin();itr!=mp.end();itr++)
#define Max(a,b) a=max(a,b)
#define Min(a,b) a=min(a,b)
int dh[4]={1,-1,0,0};
int dw[4]={0,0,1,-1};
int ddh[8]={-1,-1,-1,0,0,1,1,1};
int ddw[8]={-1,0,1,-1,1,-1,0,1};
ll gcd(ll a,ll b){
    if(a<b)swap(a,b);
    if(b==0)return a;
    if(a%b==0)return b;
    return gcd(b,a%b);
}
ll Pow(ll n,ll k){
    ll ret=1;
    ll now=n;
    while(k>0){
        if(k&1)ret*=now;
        now*=now;
        k/=2;
    }
    return ret;
}
ll beki(ll n,ll k,ll md){
  ll ret=1;
  ll now=n;
  while(k>0){
    if(k%2==1){
      ret*=now;
      ret%=md;
    }
    now*=now;
    now%=md;
    k/=2;
  }
  return ret;
}
ll gyaku(ll n,ll md){
  return beki(n,md-2,md);
}
ll popcount(ll n){
    ll ret=0;
    ll u=n;
    while(u>0){
        ret+=u%2;
        u/=2;
        
    }
    return ret;
}
int main(){
    ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    int n;cin>>n;
    if(n==0)cout<<1<<endl;
    else if(n==1)cout<<2<<endl;
    else if(n==2)cout<<1<<endl;
    else cout<<0<<endl;
}






Measured memory_bytes: 3168
from sys import stdin
data = stdin.readline().rstrip()

def shorten_phrase(x):
    l = len(x)
    if x.startswith("eraser"):
        x = x[6:]
    elif x.startswith("erase"):
        x = x[5:]
    elif x.startswith("dreamera"):
        x = x[5:]
    elif x.startswith("dreamer"):
        x = x[7:]
    elif x.startswith("dream"):
        x = x[5:]
    m = len(x)
    return l != m

while shorten_phrase(data):
    if data.startswith("eraser"):
        data = data[6:]
    elif data.startswith("erase"):
        data = data[5:]
    elif data.startswith("dreamera"):
        data = data[5:]
    elif data.startswith("dreamer"):
        data = data[7:]
    elif data.startswith("dream"):
        data = data[5:]
if len(data) == 0:
    print("YES")
else:
    print("NO")

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

using namespace std;

#ifdef NeverBeRed
#include "debug.h"
#else
#define debug(...) 9715
#endif
typedef long long ll;
typedef long double ld;
typedef complex<ld> point;
#define F first
#define S second

const int mod = 998244353;
int dp[305][305][305];

inline void add(int &x, int y)
{
	x += y;
	if (x >= mod)
		x -= mod;
}

int main()
{
	#ifdef TurnRed
		//freopen("a.in", "r", stdin);
		//freopen("a.out", "w", stdout);
	#endif

	ios_base::sync_with_stdio(0), cin.tie(0);

	string s;
	cin >> s;

	int n = s.length();
	dp[0][0][0] = true;
	for (int p = 0; p < n; ++p)
		for (int z = 0; z <= n; ++z)
			for (int o = 0; o <= n; ++o)
				if (dp[p][z][o])
				{
					if (z >= 2) dp[p][z-2][o] = true;
					if (o >= 2) dp[p][z][o-2] = true;
					if (z && o) dp[p][z-1][o-1] = true;
					if (z || o) dp[p+1][z][o] = true;
					if (z && s[p] == '1') dp[p+1][z-1][o+1] = true;
					if (o && s[p] == '0') dp[p+1][z+1][o-1] = true;
					if (p+1 < n)
					{
						if (s[p] == '0' || s[p+1] == '0') dp[p+2][z+1][o] = true;
						if (s[p] == '1' || s[p+1] == '1') dp[p+2][z][o+1] = true;
					}
				}

	vector<vector<int>> f(2, vector<int>(n+1));
	for (int i = n-1; i >= 0; --i)
	{
		++f[s[i]-'0'][i];
		f[0][i] += f[0][i+1];
		f[1][i] += f[1][i+1];
	}

	vector<vector<int>> cnt(n+1, vector<int>(n+1, -1));
	for (int p = 0; p <= n; ++p)
		for (int z = 0; z <= n; ++z)
			for (int o = 0; o <= n; ++o)
				if (dp[p][z][o])
				{
//					debug(p, z, o);
					int nz = z + f[0][p];
					int no = o + f[1][p];
					cnt[nz][no] = max(cnt[nz][no], p);
				}

//	for (auto i : cnt)
//		debug(i);

	memset(dp, 0, sizeof dp);
	for (int z = 0; z <= n; ++z)
		for (int o = 0; o <= n; ++o)
			if (cnt[z][o] != -1)
			{
				int p = cnt[z][o];
				dp[p][z - f[0][p]][o - f[1][p]] = 1;
			}

	for (int p = 0; p <= n; ++p)
		for (int z = n; z >= 0; --z)
			for (int o = n; o >= 0; --o)
			{
				if (p < n && s[p] == '0')
					add(dp[p+1][z][o], dp[p][z][o]);
				else if (z)
					add(dp[p][z-1][o], dp[p][z][o]);

				if (p < n && s[p] == '1')
					add(dp[p+1][z][o], dp[p][z][o]);
				else if (o)
					add(dp[p][z][o-1], dp[p][z][o]);
			}

	cout << dp[n][0][0] << "\n";

	return 0;
}


Measured memory_bytes: 114600
#include <bits/stdc++.h>
#define FOR(i, a, n) for(ll i = (ll)a; i < (ll)n; i++)
#define FORR(i, n) for(ll i = (ll)n - 1LL; i >= 0LL; i--)
#define rep(i, n) FOR(i, 0, n)
#define ALL(x) (x).begin(), (x).end()
using namespace std;
using ll = long long;
template <typename T> using V = vector<T>;

constexpr int Mod = 998244353;
constexpr int mod = 1e9 + 7;
constexpr ll inf = 1LL << 60;

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

/*-------------------------------------------*/

const int INF = 1 << 30;

int N;
V<V<int>> G;
V<int> l, u;

V<int> ans;

void dfs1(int v, int p, int guuki) {
    if(l[v] == u[v] && l[v] % 2 != guuki) {
        cout << "No" << endl;
        exit(0);
    }
    for(int x : G[v]) {
        if(x != p) {
            dfs1(x, v, 1 - guuki);
            chmax(l[v], l[x] - 1);
            chmin(u[v], u[x] + 1);
        }
    }
    if(l[v] > u[v]) {
        cout << "No" << endl;
        exit(0);
    }
}

void dfs2(int v, int p) {
    if(l[v] == u[v])
        ans[v] = l[v];
    else if(l[v] <= ans[p] + 1 && ans[p] + 1 <= u[v])
        ans[v] = ans[p] + 1;
    else
        ans[v] = ans[p] - 1;
    for(int i : G[v])
        if(i != p) dfs2(i, v);
}

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

    cin >> N;
    G.resize(N);
    l.assign(N, -INF);
    u.assign(N, +INF);
    ans.resize(N);
    rep(i, N - 1) {
        int a, b;
        cin >> a >> b;
        a--;
        b--;
        G[a].push_back(b);
        G[b].push_back(a);
    }
    int K;
    cin >> K;
    int r = 0;
    rep(i, K) {
        int p;
        cin >> r >> p;
        r--;
        l[r] = u[r] = p;
    }

    dfs1(r, -1, l[r] % 2);

    dfs2(r, -1);

    cout << "Yes" << endl;
    rep(i, N) cout << ans[i] << endl;

    return 0;
}

Measured memory_bytes: 15360
#include <bits/stdc++.h>
#define br cout << "\n";
#define pb push_back
#define ll long long 
#define ff first 
#define ss second
#define all(x) x.begin(),x.end()
#define in(a , idx , n ) for (int i = idx ; i < n ; ++i)cin >>a[i];
using namespace std;
const int MOD = 1000*1000*1000 + 7 ; 
const int MAXN = 1000*100 +10 ;
const ll INF = 1e18 ; 
vector<int>e[MAXN];
int dp[MAXN]; 
int  dfs(int u ){
		
	if (dp[u] > 0  )
		return dp[u];
		
	for(int x : e[u])
		dp[u] = max ( dp [u] , 1 + dfs(x) ) ; 
	return dp[u]; 
	
}
void solve(){
	int n , m ;
	cin >> n >> m ;
	
	for(int i = 0,u,v ; i < m ; ++i )
	{
		cin >> u >> v ;
		e[u].pb(v);
	}
	int res = 0 ; 
	for(int i = 0 ; i <= n ; ++i )
	{
		if(dp[i] == 0 )
		{
			dfs(i);
			res = max ( res , dp[i] ) ; 
			
		}
	}

	// for (int i = 1 ; i <= n ; ++ i )
		// cout << i << " " << dp[i] , br 
	cout << res ,  br 

}
int main (){ 
	int t = 1  ;
	// cin >> t ;
	while (t--){
		solve() ; 
	}
    
return 0 ; 
}


Measured memory_bytes: 11348
# encoding: "utf-8"

class Stdin:
    @staticmethod
    def read_line(converter=str):
        return [converter(x) for x in input().split()]
    
    @staticmethod
    def read_lines(n, converter=str):
        result = list()
        for _ in range(n):
            result.append(Stdin.read_line(converter))
        return result
    
    @staticmethod
    def convert(data, converter):
        assert(len(data) == len(converter))
        return tuple(map(lambda x, f: f(x), data, converter))

    @staticmethod
    def convert_lines(datas, n, converter):
        return [converter(data, n, converter) for data in datas]


def count_and_drop(xs):
    cnt = 0
    fst = xs[-1]
    for x in reversed(xs):
        if x != fst:
            break
        cnt += 1
    del xs[-cnt:]
    return cnt


def main():
    _ = input()
    xs = Stdin.read_line(converter=int)
    xs.sort()
    ys = dict()
    while xs:
        key = xs[-1]
        cnt = count_and_drop(xs)
        ys[key] = cnt
    m = 0
    for x in ys.keys():
        temp = ys.get(x-1, 0) + ys.get(x, 0) + ys.get(x+1, 0)
        if m < temp:
            m = temp
    print(m)

if __name__ == "__main__":
    main()


Measured memory_bytes: 13864
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
#include <cmath>
#include <cstring>
#include <iomanip>
#include <random>
#include <chrono>
#include <queue>
using namespace std;
typedef long long ll;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;
#define INF 1000000000
#define MOD 1000000007
#define EPS 0.00000001


int main(){
    int N; cin >> N;
    int ret = INF;
    for(int i=1; i<N; i++){
        int a = i;
        int b = N-i;
        int dsum = 0;
        while(a!=0 || b!=0){
            dsum += a%10;
            dsum += b%10;
            a/=10;
            b/=10;
        }
        ret = min(ret, dsum);
    }
    cout << ret << endl;
    return 0;
}


Measured memory_bytes: 256
#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 reps(i, n) for (int i = 1; i <= int(n); i++)
#define rreps(i, n) for (int i = int(n); i >= 1; i--)
#define repc(i, n) for (int i = 0; i <= int(n); i++)
#define rrepc(i, n) for (int i = int(n); i >= 0; i--)
#define repi(i, a, b) for (int i = int(a); i < int(b); i++)
#define repic(i, a, b) for (int i = int(a); i <= int(b); i++)
#define each(x, y) for (auto &x : y)
#define all(a) (a).begin(), (a).end()
#define bit32(x) (1 << (x))
#define bit64(x) (1ll << (x))

using namespace std;

using i64 = long long;
using f80 = long double;
using vi32 = vector<int>;
using vi64 = vector<i64>;
using vf80 = vector<f80>;
using vstr = vector<string>;

inline void yes() { cout << "Yes" << endl; exit(0); }
inline void no() { cout << "No" << endl; exit(0); }
inline i64 gcd(i64 a, i64 b) { if (min(a, b) == 0) return max(a, b); if (a % b == 0) return b; return gcd(b, a % b); }
inline i64 lcm(i64 a, i64 b) { if (min(a, b) == 0) return max(a, b); return a / gcd(a, b) * b; }
template <typename T> class pqasc : public priority_queue<T, vector<T>, greater<T>> {};
template <typename T> class pqdesc : public priority_queue<T, vector<T>, less<T>> {};
template <typename T> inline void amax(T &x, T y) { x = max(x, y); }
template <typename T> inline void amin(T &x, T y) { x = min(x, y); }
template <typename T> inline T exp(T x, i64 n, T e = 1) { T r = e; while (n > 0) { if (n & 1) r *= x; x *= x; n >>= 1; } return r; }
template <typename T> istream& operator>>(istream &is, vector<T> &v) { each(x, v) is >> x; return is; }
template <typename T> ostream& operator<<(ostream &os, vector<T> &v) { rep(i, v.size()) { if (i) os << ' '; os << v[i]; } return os; }
void solve(); int main() { ios::sync_with_stdio(0); cin.tie(0); cout << fixed << setprecision(16); solve(); return 0; }

void solve() {
  int N;
  cin >> N;
  reps(h, 3500) reps(n, 3500) {
    i64 c = (i64) N * h * n;
    i64 p = (i64) 4 * h * n - (i64) N * n - (i64) N * h;
    if (p == 0) continue;
    if (c % p != 0) continue;
    i64 w = c / p;
    if (w < 1 || w > 3500) continue;
    cout << h << " " << n << " " << w << endl;
    return;
  }
}


Measured memory_bytes: 256
n,k=gets.split.map(&:to_i)
h=gets.split.map(&:to_i)
d=Array.new(n+1,0)
h.unshift(0)

1.upto(n){|i|
  min=1000000000
  [1,i-k].max.upto(i){|j| 
    x=(h[i]-h[j]).abs+d[j]
    min=(min>x)?x:min
    d[i]=min
  }}
puts d[n]

Measured memory_bytes: 11908
#include <iostream>
#include <stdio.h>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <algorithm>
#include <cmath>
#include <math.h>
#include <memory.h>
#include <deque>
#include <stdlib.h>
#include <time.h>
using namespace std;
typedef long long ll;
#define mp make_pair
const int M=100005;
const int N=1000001;
const int K=1000000007;
const ll MAX=1000000000000000000ll;
int n,k,a[100];
bool dp[M];
int main(){
    cin>>n>>k;
    for(int i=0;i<n;i++)
    	cin>>a[i];
    sort(a,a+n);
    for(int i=k;i>=0;i--)
	{
		if(a[0]+i>k)
		{
			dp[i]=0;
			continue;
		}
		for(int j=0;j<n;j++)
	    {
			if(a[j]+i>k)
				break;
			if(!dp[i+a[j]])
				dp[i]=1;
	    }
	 }
    if(dp[0])
    	cout<<"First";
    else
    	cout<<"Second";
}

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

int main () {
    int N, s, t;
    cin >> N;
    int sum = 0;
    for (int i = 0; i < N; i++) {
        cin >> s >> t;
        sum += t - s + 1;
    }
    cout << sum << endl;

}

Measured memory_bytes: 256
N, Y = list(map(int, input().split()))

ans = False

for a in range(N+1):
    for b in range(N+1):
        c = N - a - b
        if 10000*a + 5000*b + 1000*c == Y and c >= 0:
            print(a, b, c)
            ans = True
            break
    if ans:
        break
if not ans:
    print(-1, -1, -1)

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

int main(){
  int N;cin >> N;
  int mean=0;
  vector<int> X(N,0);
  for(int i=0;i<N;i++){
    cin >> X[i];
    mean += X[i];
  }
  mean /= N;
  int ans=1000000;
  for(int x=mean;x<=mean+1;x++){
    int cost=0;
    for(int i=0;i<N;i++){
      cost += (X[i]-x)*(X[i]-x);
    }
    ans = min(ans,cost);
  }
  cout << ans << endl;
}

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

int main() {
  int n;
  cin >> n;
  string s;
  cin >> s;
  
  if(n%2==1){
    cout << "No" << endl;
    return 0;
  }
  
  for(int i=0; i<n/2; i++){
    if(s.at(i) != s.at(i+n/2)){
      cout << "No" << endl;
      return 0;
    }
  }
  cout << "Yes" << endl;
  return 0;
}

Measured memory_bytes: 256
import java.util.*;
public class Main
{
	public static void main(String[] args) 
	{
		Scanner in=new Scanner(System.in);
		for(;;)
		{
			int n=in.nextInt();
			int k=in.nextInt();
			if((n|k)==0)
				return;
			int a[]=new int[n];
			int max=0;
			int cmax=0;
			for(int i=0;i<n;i++)
				a[i]=in.nextInt();
			for(int i=0;i<n-k+1;i++)
			{
				int mul=1;
				for(int j=i;j<i+k;j++)
					mul*=a[j];
				max=Math.max(max,mul);
			}
			int ans=-1;
			for(int i=0;i<n;i++)
				for(int j=i+1;j<n;j++)
				{
					int b[]=a.clone();
					int tmp=b[i];
					b[i]=b[j];
					b[j]=tmp;
					for(int s=0;s<n-k+1;s++)
					{
						int mul=1;
						for(int t=s;t<s+k;t++)
							mul*=b[t];
						cmax=Math.max(cmax,mul);
					}
					ans=Math.max(ans,cmax-max);
				}
			System.out.println(ans>=0 ? ans : "NO GAME");
		}
	}

	static public void debug(Object... o)
	{
		System.err.println(Arrays.deepToString(o));
	}
}

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

w, h, n = map(int, input().split())
A = [list(map(int, input().split())) for _ in range(n)]
field = [['.' for j in range(w)] for i in range(h)]
for a in A:
    if a[2] == 1:
        for i in range(h):
            for j in range(a[0]):
                field[i][j] = '#'
    elif a[2] == 2:
        for i in range(h):
            for j in range(a[0], w):
                field[i][j] = '#'
    elif a[2] == 3:
        for i in range(a[1]):
            for j in range(w):
                field[i][j] = '#'
    elif a[2] == 4:
        for i in range(a[1], h):
            for j in range(w):
                field[i][j] = '#'
ans = 0
for line in field:
    ans += line.count('.')
print(ans)


Measured memory_bytes: 3188
import java.util.*;

public class Main implements Runnable {

    private static int MOD = 1_000_000_007;

    public static void main(String[] args) {
        // Run with 32MB stack
        Thread thread = new Thread(null, new Main(), "", 32 * 1024 * 1024);
        thread.start();
    }

    @Override
    public void run() {
        final Scanner scanner = new Scanner(System.in);
        solve(scanner);
    }

    static void solve(Scanner scanner) {
        int N = scanner.nextInt();
        scanner.nextLine();
        int[][] edges = new int[N - 1][2];
        Map<Integer, Map<Integer, Integer>> color = new HashMap<>();
        int[] deg = new int[N + 1];
        for (int i = 0; i < N - 1; i++) {
            edges[i] = Arrays.stream(scanner.nextLine().split(" ")).mapToInt(Integer::parseInt).toArray();
            deg[edges[i][0]]++;
            deg[edges[i][1]]++;
            if (!color.containsKey(edges[i][0])) {
                color.put(edges[i][0], new HashMap<>());
            }
            color.get(edges[i][0]).put(edges[i][1], 0);

            if (!color.containsKey(edges[i][1])) {
                color.put(edges[i][1], new HashMap<>());
            }
            color.get(edges[i][1]).put(edges[i][0], 0);
        }

        int max = Arrays.stream(deg).max().orElse(-1);

        System.out.println(max);
        Map<Integer, Set<Integer>> used = new HashMap<>();
        for (int i = 1; i <= N; i++) {
            used.put(i, new HashSet<>());
        }
        for (int i = 1; i <= N; i++) {
            int curr = 1;
            for (int to : color.getOrDefault(i, Collections.emptyMap()).keySet()) {
                int c = color.get(i).get(to);
                if (c != 0) {
                    continue;
                }
                while (used.get(i).contains(curr) || used.get(to).contains(curr)) {
                    curr++;
                }
                used.get(i).add(curr);
                used.get(to).add(curr);
                color.get(i).put(to, curr);
                color.get(to).put(i, curr);
                curr++;
            }
        }

        for (int[] e : edges) {
            System.out.println(color.get(e[0]).get(e[1]));
        }
    }

}



Measured memory_bytes: 198416
#include<stdio.h>

int main(){
  int i, n, m, x, y;

  while(1){
    scanf("%d", &n);
    if(n == 0) break;

    scanf("%d", &m);
    for(i=0; i<m; i++){
      scanf("%d %d", &x, &y);
      n -= (y - x);
    }

    if(n <= 0) printf("OK\n");
    else printf("%d\n", n);
  }

  return 0;
}

Measured memory_bytes: 0
#include<iostream>

int main(){
	int a, b, c, d, e,f,g;
	f = 0;
	g = 0;
	std::cin >> a >> b >> c >> d >> e;
	if (b%d == 0){
		f = b / d;
	}
	else {
		f = b / d + 1;
	}
	if (c%e == 0){
		g = c / e;
	}
	else {
		g = c / e + 1;
	}
	if (f >= g){
		std::cout << a - f << std::endl;
	}
	if (f < g){
		std::cout << a - g << std::endl;
	}
	return 0;
}

Measured memory_bytes: 3080
N, M = map(int, input().split(' '))
a = []
b = []

for i in range(M):
    ai, bi = input().split(' ')
    if ai == '1':
        a.append(bi)
    if bi == str(N):
        b.append(ai)
if len(set(a) & set(b)) > 0:
    print("POSSIBLE")
else:
    print('IMPOSSIBLE')


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

const int maxn(105);

int n, tim, c[maxn], t[maxn], ans = 100000;

int main() {
	cin >> n >> tim;
	for (int i = 1; i <= n; ++i) {
		cin >> c[i] >> t[i];
		if (t[i] <= tim) ans = min(ans, c[i]);
	}
	if (ans != 100000) printf("%d\n", ans);
	else puts("TLE");
	return 0;
}

Measured memory_bytes: 256
#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")

#include <algorithm>
#include <climits>
#include <cmath>
#include <cstring>
#include <deque>
#include <forward_list>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

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

const ll MOD = 1E+09 + 7;
const ll INF = 1E18;
const int MAX_N = 1E+05;

int N;

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

    cin >> N;

    unordered_map<ll, int> mp;

    int ans = 0;

    for (int i = 0; i < N; i++) {
        ll a;
        cin >> a;
        if (mp.count(a)) {
            mp[a]++;
            if (mp[a] & 1) {
                ans++;
            } else {
                ans--;
            }
        } else {
            mp.insert(P(a, 1));
            ans++;
        }
    }

    cout << ans << "\n";

    return 0;
}

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

using namespace std;
using ll = long long;
const ll INF = 1e18;

vector<ll> dijkstra(int N,int start,int dest,const vector<vector<pair<ll,ll>>>& Hen){
    vector<ll> dist(N, INF), prever(N, -1), seen(N);
    dist[start] = 0;
    priority_queue<pair<ll,ll>, vector<pair<ll,ll>>, greater<pair<ll,ll>>> que;
    que.emplace(0, start);

    while(que.size()) {
        ll ver = que.top().second, cost = que.top().first; que.pop();
        if(seen[ver])continue;
        seen[ver] = true;
        for(auto i : Hen[ver]) {
            if(dist[i.first] > cost + i.second) {
                dist[i.first] = cost + i.second;
                prever[i.first] = ver;
                que.emplace(dist[i.first], i.first);
            }
        }
    }
    return dist;
}


int main()
{
    int n, m, s, t; cin >> n >> m >> s >> t; s--, t--;
    vector<vector<pair<ll,ll>>> en(n), sn(n);
    for(int i = 0; i < m; i++) {
        int u, v, a, b;
        cin >> u >> v >> a >> b; u--, v--;
        en[u].emplace_back(v, a); en[v].emplace_back(u, a);
        sn[u].emplace_back(v, b); sn[v].emplace_back(u, b);
    }
    vector<ll> sta = dijkstra(n, s, t, en);
    vector<ll> end = dijkstra(n, t, s, sn);

    ll nax = 0, def = 1e15;
    vector<ll> cost(n);
    for(int i = n - 1; i >= 0; i--) {
        nax = max(nax, def - (sta[i] + end[i]));
        cost[i] = nax;
    }
    for(int i = 0; i < n; i++)cout << cost[i] << endl;
}

Measured memory_bytes: 19840
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define ld long double
int main()
{
	ll n,d;
	cin>>n>>d;
	ll ans=0;
	for(ll i=0;i<n;i++){
		ll a,b;
		cin>>a>>b;
		ld p=(a*a)+(b*b);
		p=sqrt(p);
		if(p<=d){
			ans++;
		}
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 3536
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std; typedef long long ll; const int M = 998244353;

int main() {
  int n,m; cin>>n>>m; int x[n];
  for(int i=0;i<n;i++) {
    cin>>x[i];
  }
  int y[100001]; fill(y,y+100001,0);
  for(int i=0;i<n;i++) {
    y[x[i]]++;
  }
  int p[m]; fill(p,p+m,0);
  int q[m]; fill(q,q+m,0);
  for(int i=1;i<=100000;i++) {
    p[i%m] += y[i];
    if (y[i] >= 2) q[i%m] += y[i]/2;
  }
  ll an=0;
  for(int i=1,j=m-1;i<m && i<j;i++,j--) {
    if (p[i] >= p[j]) {
      an += p[j];
      int left = p[i] - p[j];
      an += min(left/2, q[i]);
    } else {
      an += p[i];
      int left = p[j] - p[i];
      an += min(left/2, q[j]);
    }
  }
  {
    an += p[0] / 2;
    if (m%2 == 0) {
      an += p[m/2] / 2;
    }
  }
  cout<<an<<endl;
}

Measured memory_bytes: 1792
#!/usr/bin/env python3
import collections
import itertools as it
import math
import numpy as np

# A = input()
A = int(input())
# A = map(int, input().split())
# A = list(map(int, input().split()))
# A = [int(input()) for i in range(N)]
#
# c = collections.Counter()

li = [1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51]

print(li[A-1])

Measured memory_bytes: 21240
import collections

n,m = map(int,input().split())
h = list(map(int,input().split()))
a = [0]*m
b = [0]*m
for i in range(m):
    a[i],b[i] = map(int,input().split())

z = zip(a,b)
lis = [0]*n

for i,j in z:

    if h[i-1] > h[j-1]:
        lis[j-1] = 1
    elif h[i-1] < h[j-1]:
        lis[i-1] = 1
    else:
        lis[i-1]=1
        lis[j-1]=1

print(collections.Counter(lis)[0])

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

const int MAXN = 1010;
const int MOD = 1e9 + 7;

char entrada[MAXN][MAXN];
int dp[MAXN][MAXN],vis[MAXN][MAXN];
int N,M;

int solve(int x,int y){

	if(x >= N || y >= M) return 0;
	if(entrada[x][y] == '#') return 0;

	if(vis[x][y]) return dp[x][y];
	if(x == N - 1 && y == M - 1) return dp[x][y] = 1;

	vis[x][y] = 1;
	return dp[x][y] = (solve(x+1,y) + solve(x,y+1)) % MOD;

}

int main(){

	scanf("%d %d",&N,&M);
	for(int i = 0;i<N;i++){
		scanf("%s",entrada[i]);
	}

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

	return 0;

}

Measured memory_bytes: 12788
#include<stdio.h>

int main(){
  int c,a=0,b=0,o=0,ab=0;
  char t,br[4];	
  
  while(scanf("%d",&c)!=EOF){
    br[1]=0;br[2]=0;
    scanf("%s",br);
  
    if(br[1]=='A'&&br[2]=='B')ab++;
    else if(br[1]=='A')a++;
    else if(br[1]=='O')o++;
    else if(br[1]=='B')b++;
  }
  
  printf("%d\n",a);
  printf("%d\n",b);
  printf("%d\n",ab);
  printf("%d\n",o);
  
  return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
int n;
int arr[5000];
long long dp[3005][3005];
long long rec(int l, int r){
	if(l == r)return arr[l];
	if(dp[l][r] != -1)return dp[l][r];
	return dp[l][r] = max(arr[l] - rec(l+1, r), arr[r] - rec(l, r-1));
}
int main(){
	cin >> n;
	for(int i = 0; i <= n; i++)
		for(int j = 0; j <= n; j++)
			dp[i][j] = -1;
	for(int i = 0; i < n ; i++)cin >> arr[i];
	cout << rec(0, n-1);
}

Measured memory_bytes: 70912
<?php
$str_input = trim(fgets(STDIN));
//配列化
for ($i = 0; $i < strlen($str_input); $i++) {
    $input[] = $str_input[$i];
}

//1と０の数を数える
$blue = array_sum($input);
$red = strlen($str_input) - $blue;

if ($blue > $red) {
    $output = $red * 2;
} else {
    $output = $blue * 2;
}

echo $output;

?>


Measured memory_bytes: 21388
function Main(input) {
    var N = parseInt(input[0], 10);
    var S = input.slice(1);
    var counter = {};
    var max = 0;

    for (var i = 0; i < N; i++) {
        if (counter[S[i]]) {
            counter[S[i]]++;
            if (max < counter[S[i]]) {
                max = counter[S[i]];
            }
        } else {
            counter[S[i]] = 1;
            if (max < counter[S[i]]) {
                max = counter[S[i]];
            }
        }
    }

    var array = [];
    Object.keys(counter).forEach(c => {
        if (counter[c] === max) {
            array.push(c);
        }
    })
    var sorted = array.sort((a, b) => {
        if (a > b) {
            return 1;
        } else {
            return -1;
        }
    });

    for (var j = 0; j < sorted.length; j++) {
        console.log(sorted[j]);
    }
}

Main(require("fs").readFileSync("/dev/stdin", "utf8").trim().split(/\n/));

Measured memory_bytes: 110616
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <cmath>
#include <random>
#include <iomanip>
#include <functional>
#include <list>
using namespace std;

int main()
{
	int a, b, c;
	cin >> a >> b >> c;

	int v[] = { a, b, c };

	int max_ans = 0;
	do 
	{
		max_ans = max(max_ans, v[0] * 10 + v[1] + v[2]);
	} while (next_permutation(v, v + 3));

	cout << max_ans;
}


Measured memory_bytes: 256
rotstr :: String -> String 
rotstr str = (last str) : (init str)

isIn :: String -> String -> Bool
isIn s t = elem t $ take (length s) $ iterate rotstr s  

main = do
  s <- getLine 
  t <- getLine 
  if (isIn s t) then putStrLn "Yes" else putStrLn "No" 


Measured memory_bytes: 892
#include <string>
#include <queue>
#include <stack>
#include <vector>
#include <sstream>
#include <algorithm>
#include <deque>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <list>
#include <cstdio>
#include <iostream>
#include <cmath>
#include <climits>
#include <bitset>
#include <functional>
#include <numeric>
#include <ctime>
#include <cassert>
#include <cstring>
#include <fstream>

using namespace std;


int main() {
    int n, l;
    cin >> n >> l;
    vector<string> ss(n);
    for (int i = 0; i < n; i++) {
        cin >> ss[i];
    }
    sort(ss.begin(), ss.end());
    for (auto &t : ss)
        cout << t;
    cout << endl;

    return 0;
}

Measured memory_bytes: 256
import math
A,B,H,M = map(int,input().split())
a = (H + M / 60) * 30 #時針がなす角度
b = 6 * M #分針がなす角度
s = abs(a-b) #二つの針がなす角度
if s == 0:
    if B >= A:
        print(B-A)
    else:
        print(A-B)
elif s == 180:
    print(A+B)
else:
    C = math.sqrt(A*A+B*B-2*A*B*math.cos(math.radians(s)))
    print(C)

Measured memory_bytes: 9524
#include <bits/stdc++.h>
using namespace std;
int main()
{
	string s;
	char c='a',d;
	cin>>s;
	int a,i,j;
	a=s.size();
	for(j=0;j<26;j++)
	{
		d=c;	
		for(i=0;i<a;i++)
		{
			if(s[i]==c)
			{
				c++;
				break;
			}
		}
		if(d==c)
		{
			cout<<c<<endl;
			return 0;
		}
	}
	cout<<"None"<<endl;
}

Measured memory_bytes: 3672
#include <bits/stdc++.h>
#define inchar			getchar
#define outchar(x)		putchar(x)
#define ll long long int
#define all(v) v.begin(), v.end()
#define SP outchar(' ')
#define LN outchar('\n')
using namespace std;

template<typename T> void inpos(T &x){x=0;register T c=inchar();while(((c<48)||(c>57))&&(c!='-'))c=inchar();bool neg=0; if(c=='-')neg=1;for(;c<48||c>57;c=inchar());for(;c>47&&c<58;c=inchar())x=(x<<3)+(x<<1)+(c&15);if(neg)x=-x;}
template<typename T> void outpos(T n){if(n<0){outchar('-');n*=-1;}char snum[65];int i=0;do{snum[i++]=n%10+'0';n/=10;}while(n);i=i-1;while(i>=0)outchar(snum[i--]);}
inline void instr(char *str){register char c=0;register int i=0;while(c<33)c=inchar();while(c!='\n'&&c!=' '&&c!=EOF){str[i]=c;c=inchar();++i;}str[i]='\0';}


int main () {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	int n;
	inpos(n);
	int dp[n][3];
	inpos(dp[0][0]);
	inpos(dp[0][1]);
	inpos(dp[0][2]);

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


Measured memory_bytes: 1408
import std.algorithm, std.conv, std.range, std.stdio, std.string;

void main()
{
  auto n = readln.chomp.to!size_t;
  auto ri = n.iota.map!(_ => readln.chomp.to!int).array;

  auto maxR = ri.back;
  auto maxP = int.min;

  foreach_reverse (i; 0..n-1) {
    maxP = max(maxP, maxR - ri[i]);
    maxR = max(maxR, ri[i]);
  }

  writeln(maxP);
}

Measured memory_bytes: 3968
//hinagata.cpp
/*includes*/
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cstdlib>
#include <cmath>
#include <stdio.h>
#include <numeric>
#include <iomanip>
#include <limits>
/*namespace*/
using namespace std;
using ll= long long;
/*define macro*/
#define REP(i,n) for(int i=0;i<(n);i++)
#define REPi(i,a,b) for(int i=(a);i<(b);i++)
#define REPRi(i,a,b) for(int i=(a);i>(b);i--)
#define ALL(x) (x).begin(),(x).end()

int main(){
    int N,A,B;
    cin>>N>>A>>B;
    if(A*N>=B){
        cout<<B<<endl;
    }else{
        cout<<A*N<<endl;
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define endl '\n'

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	ll a, b, c, d;cin>>a>>b>>c>>d;
	ll g = __gcd(c, d);
	ll total = b - a + 1;
	total -= b/d - (a-1)/d;
	total -= b/c - (a-1)/c;
	ll l = c*d;
	l/=g;
	total += b/l - (a-1)/l;
	cout<<total<<endl;
	return 0;
}



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

using ll = long long;
using ld = long double;
using vi = vector<int>;
using vll = vector<ll>;
using P = pair<int, int>;

const int INF = 1e9;
const ll INFLL = 1e18;
const int MOD = 1e9 + 7;
const int NIL = -1;

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

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

#define DEBUG

int main()
{
	ios::sync_with_stdio(false); cin.tie(0);
	int n, k, x, y;
	cin >> n >> k >> x >> y;

	ll ans = 0;
	rep(i, n)
	{
		if(i < k) ans += x;
		else ans += y;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
import sys
input = sys.stdin.readline
 
N=int(input())
A=list(map(int,input().split()))
 
XOR=0
for a in A:
    XOR^=a
 
for i in range(N):
    A[i] &=~XOR
    
USED=[0]*N
 
for bi in range(60,-1,-1):
    for i in range(N):
        if USED[i]==0 and A[i] & (1<<bi)!=0:
            USED[i]=1
            useind=i
            break
    else:
        continue
 
    for i in range(N):
        if i==useind:
            continue
        if A[i] & (1<<bi)!=0:
            A[i]^=A[useind]
            
ANS=0
for a in A:
    ANS^=a
 
print(2*ANS+XOR)

Measured memory_bytes: 16052
#include <iostream>
#include <algorithm>
#include <math.h>
#include <string>
#include <vector>
#include <cstdlib>

using namespace std;

int main(){
    int n;
    cin >> n;
    int f[n];
    for(int i = 0; i < n; i++){
        cin >> f[i];
    }
    
    vector<int> div;
    int count = 0;
    int min = 0;
    
    for(int i = 0; i < n; i++){
        if(div.size() == 0){
            div.push_back(f[i]);
        }
        else if(*max_element(div.begin(), div.end()) <= f[i]){
            div.push_back(f[i]);
        }
        else{
            if(min == 0){
                min = f[i];
                count += *max_element(div.begin(), div.end());
            }
            else{
                count += *max_element(div.begin(), div.end()) - min;
                min = f[i];
            }
            div.clear();
            div.push_back(f[i]);
        }
    }
    if(min <= *min_element(div.begin(), div.end())){
        count += *max_element(div.begin(), div.end()) - min;
    }
    else{
        count += *max_element(div.begin(), div.end()) - *min_element(div.begin(), div.end());
    }
    cout << count;
}

Measured memory_bytes: 256
import sys
sys.setrecursionlimit(200100)
n, m, k = map( int, input().split() )
friend = [ [] for _ in range( n ) ]

for _ in range( m ):
    a, b = map( int, input().split() )
    friend[ a - 1 ].append( b - 1 )
    friend[ b - 1 ].append( a - 1 )

graph_id = [ -1 for _ in range( n ) ]

def dfs( ver, g_id ):
    if graph_id[ ver ] == -1:
        graph_id[ ver ] = g_id
    else:
        return
    for next_v in friend[ ver ]:
        dfs( next_v, g_id )

g_id = 0
for ver in range( n ):
    if graph_id[ ver ] != -1:
        continue
    dfs( ver, g_id )
    g_id += 1

graph_size = [ 0 for _ in range( n ) ]
for ver in range( n ):
    graph_size[ graph_id[ ver ] ] += 1

ans = [ graph_size[ graph_id[ ver ] ] for ver in range( n ) ]

for _ in range( k ):
    c, d = map( int, input().split() )
    if graph_id[ c - 1 ] == graph_id[ d - 1 ]:
        ans[ c - 1 ] -= 1
        ans[ d - 1 ] -= 1

for ver in range( n ):
    ans[ ver ] = ans[ ver ] - len( friend[ ver ] ) - 1

print( " ".join( map( str, ans ) ) )

Measured memory_bytes: 45060
#![allow(unused_imports)]
#![allow(non_snake_case)]
use std::cmp::*;
use std::collections::*;
use std::io::Write;

#[allow(unused_macros)]
macro_rules! debug {
    ($($e:expr),*) => {
        #[cfg(debug_assertions)]
        $({
            let (e, mut err) = (stringify!($e), std::io::stderr());
            writeln!(err, "{} = {:?}", e, $e).unwrap()
        })*
    };
}

const INF: i64 = 1000000;

fn main() {
    let v = read_vec::<usize>();
    let (n, m) = (v[0], v[1]);
    let mut edges = vec![vec![INF; n]; n];
    let mut edge_vec = vec![];
    for i in 0..m {
        let v = read_vec::<i64>();
        let (a, b, c) = (v[0] as usize - 1, v[1] as usize - 1, v[2]);
        edges[a][b] = c;
        edges[b][a] = c;
        edge_vec.push((a, b));
    }
    let prev = warshall_floyd_recover(edges);
    let mut used = vec![vec![false; n]; n];

    for start in 0..n {
        for goal in 0..n {
            let mut cur = goal;
            while cur != start {
                used[cur][prev[start][cur]] = true;
                used[prev[start][cur]][cur] = true;
                cur = prev[start][cur];
            }
        }
    }

    let mut ans = 0;
    for (a, b) in edge_vec {
        if !used[a][b] {
            ans += 1;
        }
    }
    println!("{}", ans);
}

fn warshall_floyd_recover(mut edges: Vec<Vec<i64>>) -> Vec<Vec<usize>> {
    assert_eq!(edges.len(), edges[0].len());
    let n = edges.len();
    let mut prev = vec![vec![0; n]; n];
    for i in 0..n {
        for j in 0..n {
            prev[i][j] = i;
        }
    }
    for k in 0..n {
        for i in 0..n {
            for j in 0..n {
                if edges[i][k] + edges[k][j] < edges[i][j] {
                    edges[i][j] = edges[i][k] + edges[k][j];
                    prev[i][j] = prev[k][j];
                }
            }
        }
    }
    prev
}

fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
#define N 200010
using namespace std;
 
inline int read()
{
	int x=0,f=1; char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')f=-1; ch=getchar();}
	while(ch>='0'&&ch<='9'){x=x*10+ch-'0'; ch=getchar();}
	return x*f;
}
struct edge{int v,next;}vs[N<<1];
int n,ee,st[N<<1],du[N],Rt,F[N];
inline void addedge(int u,int v)
{
	vs[++ee].v=v;vs[ee].next=st[u];st[u]=ee;
}

inline bool cmp(int a,int b){return F[a]<F[b];}

inline bool dfs(int rt,int pr,int x)
{
	vector <int> v; v.clear();
	for(int i=st[rt];i;i=vs[i].next)
	{
		if(vs[i].v==pr) continue;
		if(!dfs(vs[i].v,rt,x)) return false;
		v.push_back(vs[i].v);
	}
	if(v.size()==0){
		F[rt]=1;
		return true;
	}
	if(du[rt]&1) v.push_back(0);
	sort(v.begin(),v.end(),cmp);
	// printf("son of node %d len of %d\n",rt,x);
	// for(int i=0;i<v.size();i++) printf("%d ",v[i]); puts("");
	int l=0,r=v.size()-1;
	while(l<=r)
	{
		int mid=(l+r)>>1,fg=1;
		for(int i=0,j=v.size()-1;i<j;i++,j--)
		{
			if(i==mid) i++; if(j==mid) j--;
			int tmp1=F[v[i]],tmp2=F[v[j]];
			fg&=(tmp1+tmp2)<=x;
		}
		if(fg) r=mid-1;
		else l=mid+1;
	}
	if(l==v.size()) return false;
	F[rt]=F[v[l]]+1;
	return F[rt]<=x+1;
}
inline bool check(int x)
{
	return dfs(Rt,0,x);
}
int main()
{
	// freopen("read.in","r",stdin);
	n=read(); for(int i=1;i<n;i++)
	{
		int u=read(), v=read();
		addedge(u,v); du[u]++;
		addedge(v,u); du[v]++;
	}
	int cnt=0; for(int i=1;i<=n;i++) 
		cnt+=du[i]&1,Rt=du[i]==1? i:Rt;
	//Rt=1;
	int l=1,r=n,B=0;
	while(l<=r)
	{
		int mid=(l+r)>>1;
		if(check(mid)) r=mid-1,B=mid;
		else l=mid+1;
	}
	cout << cnt/2 << " " << B << endl;
	return 0;
}

Measured memory_bytes: 13312
import sys
readline = sys.stdin.buffer.readline
def even(n): return 1 if n%2==0 else 0

x,n = map(int,readline().split())
lst1 = list(map(int,readline().split()))

ans = []

for i in range(-200,200):
    if i in lst1:continue
    ans.append([abs(x-i),i])

res = 1000000
a2 = 9999999
for i in ans:
    if i[0] < res:
        a2 = i[1]
        res = i[0]
print(a2)

Measured memory_bytes: 62048
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

class Program
{
    static void Main(string[] args)
    {
        var dance = Console.ReadLine();

        var ret = Check(dance) ? "Yes" : "No";


        Console.WriteLine(ret);
    }

    public static bool Check(string dance)
    {
        for (int i = 0; i < dance.Length; i++)
        {
            if ((dance[i].ToString() == "R") && (i % 2 == 1))
            {
                return false;
            }
            if ((dance[i].ToString() == "L") && (i % 2 == 0))
            {
                return false;
            }

        }
        return true;
    }
}


Measured memory_bytes: 13140