akhauriyash/Code-Regression huggingface dataset:
import Control.Applicative
import Control.Monad
import Data.List
import Data.Array
import Data.Char

main = do
  [a, b, c, x, y] <- map (read::String -> Int) . words <$> getLine
  let (d, e, z, w) = if x < y then (b, a, y, x) else (a, b, x, y)
    in print $ if d + e <= 2 * c
      then d * z + e * w
      else if d <= 2 * c
        then 2 * c * w + d * (z - w)
        else 2 * c * z

Measured memory_bytes: 508
import sys
input = lambda: sys.stdin.readline().rstrip()

def main():
    n, m, k = map(int, input().split())
    a = list(map(int, input().split()))
    b = list(map(int, input().split()))
    ans = 0
    a_time = [0]
    b_time = [0]
    for i in range(1, len(a) + 1):
        a_time.append(a_time[i - 1] + a[i - 1])
    for i in range(1, len(b) + 1):
        b_time.append(b_time[i - 1] + b[i - 1])

    a_max = len(a_time) - 1
    b_max = len(b_time) - 1
    for i in range(1, len(a_time)):
        if a_time[i] > k:
            a_max = i - 1
            break
    for i in range(1, len(b_time)):
        if b_time[i] > k:
            b_max = i - 1
            break

    for i in range(len(b_time)):
        if a_time[a_max] + b_time[i] <= k:
            ans = max(ans, a_max + i)
        else:
            if a_max > 0:
                a_max -= 1
    for i in range(len(a_time)):
        if b_time[b_max] + a_time[i] <= k:
            ans = max(ans, b_max + i)
        else:
            if b_max > 0:
                b_max -= 1

    print(ans)

if __name__ == '__main__':
    main()


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

int main() {
    int t;
    cin >> t;
    while (t--) {
        int n, pre, maxUp = 0, maxDown = 0;
        cin >> n >> pre;
        for (int i = 0; i < n - 1; i++) {
            int h;
            cin >> h;
            if (h > pre) {
                if (h - pre > maxUp) {
                    maxUp = h - pre;
                }
            } else if (h < pre) {
                if (pre - h > maxDown) {
                    maxDown = pre - h;
                }
            }
            pre = h;
        }
        cout << maxUp << " " << maxDown << endl;
    }
}

Measured memory_bytes: 0
#include <iostream>
#include <vector>
#define REP(i, n) for(int i = 0; i < (n); i++)
#define INF 1100000000

using namespace std;
typedef long long ll;

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

  vector<ll> minA(N); // maxA[i] := [0,i)まで見たときの最小値
  minA[0] = INF;
  REP(i, N - 1) minA[i + 1] = min(minA[i], A[i]);

  ll ma = -INF;
  for (int i = 1; i < N; i++) {
    if (A[i] >= minA[i])
      ma = max(ma, T * (A[i] - minA[i]) / 2);
  }

  ll ans = 0;
  for (int i = 1; i < N; i++) {
    ll tmp = T * (A[i] - minA[i]) / 2;
    if (A[i] >= minA[i] && tmp == ma) ans++;
  }
  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 1792
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <queue>
using namespace std;

//conversion
//------------------------------------------
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

//math
//-------------------------------------------
template<class T> inline T sqr(T x) {return x*x;}

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);

//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))

//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

LL N,A,B,C,D;
int main(){

    cin>>N>>A>>B>>C>>D;

    LL m=0;

    REP(m,N-1){
        if((C*(N-1-m)-D*m)<=B-A&&B-A<=(-C*m+(N-1-m)*D)){
            cout<<"YES"<<endl;
            exit(0);
        }
    }

    cout<<"NO"<<endl;
    exit(0);

}


Measured memory_bytes: 256
/* ＵＴＦ－８ */
#include <iostream>
#include <string>
#include <vector>
#include <deque>
#include <list>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <array>
#include <queue>
#include <stack>
#include <algorithm>
#include <tuple>
#include <numeric>
#include <type_traits>
#include <limits>

#include <stdio.h>
#include <unistd.h>
#include <fcntl.h>
#include <string.h>

#define USE_COLORED 1

#ifdef USE_COLORED
static const char stdout_pre[]  = "\033[1m"; // bold black
static const char stderr_pre[]  = "\033[31;1m"; // bold red
static const char stdxxx_post[] = "\033[m";

// 当然ながら GCC(g++)/libstdc++ 依存
#include <ext/stdio_filebuf.h>
using stdio_filebuf = __gnu_cxx::stdio_filebuf<char>;
class colored_stdio_filebuf : public stdio_filebuf {
private:
	const char* const pre_;
	const char* const post_;

public:
	colored_stdio_filebuf(FILE* fp, const char* pre, const char* post) : stdio_filebuf(fp, std::ios_base::out), pre_(pre), post_(post)
	{
	}

protected:
	std::streamsize xsputn(const char* s, std::streamsize count) override
	{
		stdio_filebuf::xsputn(pre_, strlen(pre_));
		auto ret = stdio_filebuf::xsputn(s, count);
		stdio_filebuf::xsputn(post_, strlen(post_));
		return ret;
	}
};
#endif

int main()
{
#ifdef USE_COLORED
	if (getenv("DEBUG")) {
		std::cout.rdbuf(new colored_stdio_filebuf(stdout, stdout_pre, stdxxx_post));
		std::cerr.rdbuf(new colored_stdio_filebuf(stderr, stderr_pre, stdxxx_post));
	} else
#endif
	{
		int fd = open("/dev/null", O_WRONLY);
		dup2(fd, 2);
		close(fd);
	}
	
	std::string s;
	std::cin >> s;
	
	std::cout << s.front() << (s.size() - 2) << s.back() << "\n";
}


Measured memory_bytes: 256
def main():
    spots_number = int(input())
    spots = [0] + list(map(int, input().split(" "))) + [0]
    visit_time = [0] * (spots_number + 2)
    for i in range(1, spots_number + 1):
        visit_time[i] = visit_time[i - 1] + abs(spots[i] - spots[i - 1])
    visit_time[-1] = visit_time[-2] + abs(spots[-2])
    for i in range(1, spots_number + 1):
        print(visit_time[i - 1] + visit_time[-1] - visit_time[i + 1] + abs(spots[i + 1] - spots[i - 1]))


if __name__ == '__main__':
    main()

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

#define FOR(i, j, k, in) for (int i=j ; i<k ; i+=in)
#define RFOR(i, j, k, in) for (int i=j ; i>=k ; i-=in)
#define REP(i, j) FOR(i, 0, j, 1)
#define RREP(i, j) RFOR(i, j, 0, 1)

#define INF (int)1e9
#define PI 3.1415926535897932384626433832795
#define MOD 1000000007

typedef long long ll;
typedef unsigned long long ull;

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<string, string> pss;
typedef map<int, int> mii;

void solve(ll test_case)
{
    int n;
    cin>>n;
    n = n%10;
    if(n == 3){
        cout<<"bon";
        return;
    }
    else if(n == 0 || n==1 || n==6 || n==8)
        cout<<"pon";
    else
        cout<<"hon";
    // Do your thing here :)
    //cout << test_case << "\n";
}

int main()
{
//#ifndef ONLINE_JUDGE
  //  freopen("input.txt", "r", stdin);
   // freopen("output.txt", "w", stdout);
//#endif
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    ll t=1, t1 = 0;
   // cin >> t;
    while (t1 < t)
    {
        solve(t1 + 1);
        t1++;
    }
}


Measured memory_bytes: 3524
#include <bits/stdc++.h>
#define ll long long
using namespace std;
int main() 
{
    ll a,b;
    cin>>a>>b;
    ll diff=abs(b+a);
    if(diff%2==0)
    {
        cout<<diff/2;
    }
    else
    {
        cout<<"IMPOSSIBLE";
    }
    return 0;
}











Measured memory_bytes: 256
#include<iostream>
#include <algorithm>
#include <string>
#include<math.h>
#define rep(i,n)for(int i=0;i<n;i++)
using namespace std;
int main() {
    int a, b;
    cin >> a >> b ;
    cout << (a%b==0?0:1) << endl;
    return 0;
}


Measured memory_bytes: 256
#include <cstdio>

bool check(int x)
{
  int tmp=0;
  while(x!=0)
  {
    x/=10;
    ++tmp;
  }
  return tmp%2==1;
}

int main()
{
  int n,ans=0;
  scanf("%d",&n);
  for(int i=1;i<=n;++i)
  {
    if(check(i)) ++ans;
  }
  printf("%d\n",ans);
}

Measured memory_bytes: 128
import sys

input = sys.stdin.readline


def main():
    K, S = map(int, input().split())

    ans = 0
    for X in range(K + 1):
        for Y in range(K + 1):
            Z = S - (X + Y)
            if 0 <= Z <= K:
                ans += 1
            else:
                continue
    print(ans)


if __name__ == "__main__":
    main()


Measured memory_bytes: 2940
#include <bits/stdc++.h>
using namespace std;
long long n,x;
long long gcd(long long a,long long b)
{
     return b==0?a:gcd(b,a%b);
}
int main()
{
    scanf("%lld%lld",&n,&x);
    printf("%lld\n",3LL*n-3LL*gcd(n,x));
    return 0;
}


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

int main()
{
	lli n;cin>>n;
	string s;
	cin>>s;
	lli r=0,g=0,b=0;
	for(lli i=0;i<n;i++){
		if(s[i]=='R')r++;
		else if(s[i]=='G')g++;
		else b++;
	}
	lli temp=r*g*b;

	for(lli i=0;i<n;i++){
		for(lli j=i+1;j<n;j++){
			if(s[i]==s[j])continue;
			lli k=j+(j-i);
			if(k>=n)continue;
			if(s[k]==s[i] || s[k]==s[j])continue;
			temp--;
		}
	}
	cout<<temp;

    return 0;
}


Measured memory_bytes: 3628
#include<iostream>
#include<vector>
#include<bits/stdc++.h>
#define lli long long int
#define mod 1000000007
#define pb push_back
#define mk make_pair
#define fastio ios_base::sync_with_stdio(false); cout.tie(NULL);
using namespace std;

int main()
{
	fastio;
	string s;
	cin>>s;
	if(s=="SUN")
		cout<<7;
	if(s=="MON")
		cout<<6;
	if(s=="TUE")
		cout<<5;
	if(s=="WED")
		cout<<4;
	if(s=="THU")
		cout<<3;
	if(s=="FRI")
		cout<<2;
	if(s=="SAT")
		cout<<1;
	return 0;
}


Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
using i64 = long long;
#define rep(i,s,e) for(int (i) = (s);(i) <= (e);(i)++)
#define all(x) x.begin(),x.end()

int main(){
  int N,i;
  cin >> N >> i;
  cout << N - i + 1 << endl;
}

Measured memory_bytes: 256
using System;
using System.Linq;

namespace AtCoder.ABC115
{
    public class B
    {
        public static void Solve()
        {
            int N = int.Parse(Console.ReadLine());
            var a = new int[N];
            for (int i = 0; i < N; i++)
            {
                a[i] = int.Parse(Console.ReadLine());
            }

            Console.WriteLine(a.Max() / 2 + (a.Sum() - a.Max()));
        }    
    }
}

namespace AtCoder {
    class Program
    {
        static void Main(string[] args)
        {
            ABC115.B.Solve();
        }
    }
}


Measured memory_bytes: 13268
/*    特徴    */

/*    教訓    */

#include <bits/stdc++.h>
using namespace std;

using ll = long long;
using ld  = long double;
using pint = pair<int, int>;
using pll = pair<ll, ll>;
using pld = pair<ld, ld>;
const int INF=1e9+7;
const ll LINF=9223372036854775807;
const ll MOD=1e9+7;
const ld PI=acos(-1);
const ld EPS = 1e-10; //微調整用（EPSより小さいと0と判定など）

int ii() { int x; if (scanf("%d", &x)==1) return x; else return 0; }
long long il() { long long x; if (scanf("%lld", &x)==1) return x; else return 0; }
string is() { string x; cin >> x; return x; }
char ic() { char x; cin >> x; return x; }
void oi(int x) { printf("%d ", x); }
void ol(long long x) { printf("%lld ", x); }
void od_nosp(double x) { printf("%.15f", x); } // 古い問題用
void od(double x) { printf("%.15f ", x); }
// long doubleで受け取り、fをLfなどに変えて出力すると、変な数値が出る
// それをなんとかするには独自の出力を作らなければならなそう
void os(const string &s) { printf("%s ", s.c_str()); }
void oc(const char &c) { printf("%c ", c); }
#define o_map(v){cerr << #v << endl; for(const auto& xxx: v){cout << xxx.first << " " << xxx.second << "\n";}} //動作未確認
void br() { putchar('\n'); }

// #define gcd __gcd //llは受け取らない C++17~のgcdと違うので注意
int lcm(int a, int b){return a / gcd(a, b) * b;}
#define begin_end(a) a.begin(),a.end() //sort(begin_end(vec));
#define REP(i,m,n) for(ll i=(ll)(m) ; i < (ll) (n) ; i++ )
#define rep(i,n) REP(i,0,n)
#define m_p(a,b) make_pair(a,b)
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
#define p_b push_back
#define SZ(x) ((int)(x).size) //size()がunsignedなのでエラー避けに


// coutによるpairの出力（空白区切り）
template<typename T1, typename T2> ostream& operator<<(ostream& s, const pair<T1, T2>& p) {return s << "(" << p.first << " " << p.second << ")";}
// coutによる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 << " "; //"\t"に変えるとTabで見やすく区切る
  }
  return s;
}
// coutによる多次元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;
}

//最大値、最小値の更新。更新したor等しければtrueを返す
template<typename T>
bool chmax(T& a, T b){return (a = max(a, b)) == b;}
template<typename T>
bool chmin(T& a, T b){return (a = min(a, b)) == b;}

//4近傍（上下左右） rep(i, 2) にすると右・下だけに進む
vector<int> dx_4 = {1, 0, -1, 0};
vector<int> dy_4 = {0, 1, 0, -1};

// -------- template end - //


// - library ------------- //



// --------- library end - //


int main(){

  ll N = il();
  vector<ll> as;
  rep(i, N){
    as.push_back(il());
  }

  ll sum = as[0];
  rep(i, N-1) sum ^= as[i+1];

  vector<ll> ans;
  rep(i, N){
    ans.push_back(as[i] ^ sum);
  }

  cout << ans << endl;

  
}

Measured memory_bytes: 7968
#include<iostream>
#include<vector>
#include<queue>
using namespace std;
vector<int> path[100005];
int t[100005];
int s[100005];
queue<int> q1;
int main(){
	int n,m;
	int i,j,k;
	int a,b;
	cin>>n>>m;
	for(i=0;i<n-1+m;i++){
		cin>>a>>b;
		a--,b--;
		t[b]++;
		path[a].push_back(b);
	}
	for(i=0;i<n;i++){
		if(t[i]==0){a=i;break;}
	}
	q1.push(a);
	while(!q1.empty()){
		a=q1.front(),q1.pop();
		if(path[a].size()==0)continue;
		for(i=0;i<path[a].size();i++){
			b=path[a][i];
			t[b]--;
			if(t[b]==0){
				s[b]=a+1;
				q1.push(b);
			}
		}
	}
	for(i=0;i<n;i++){
		cout<<s[i]<<endl;
	}
	return 0;
}
		


Measured memory_bytes: 7040
//
// Created by Abhishek Bansal on 9/02/2020.
//
#include <iostream>
#include <bits/stdc++.h>
#define ll long long
using namespace std;
int main() {
    ios_base::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr);

    ll n; cin >> n;ll a[n];for(ll i=0;i<n;i++) cin >> a[i];
    ll h = 0, ma = a[0];
    for(ll i=1;i<n;i++) {
        if (a[i] < ma) {
            h += ma-a[i];
            a[i] = ma;
        }else if (a[i] > ma) ma = a[i];
    }
    cout << h;
    return 0;
}

Measured memory_bytes: 5148
#include<bits/stdc++.h>
using namespace std;
string a,b;
int main()
{
cin>>a>>b;
for(int i=0;i<min(a.size(),b.size());i++)
cout<<a[i]<<b[i];
if(a.size()>b.size())
{
for(int i=b.size();i<a.size();i++)
cout<<a[i];
}
else
{
for(int i=a.size();i<b.size();i++)
cout<<b[i];
}
cout<<endl;
return 0;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
int main() {
	deque<char>S;
	string s; cin >> s;
	for (int i = 0; i < s.size(); i++) {
		S.push_back(s.at(i));
	}
	int Q;
	cin >> Q;
	int times = 0;
	for (int i = 0; i < Q; i++) {
		int T; cin >> T;
		if (T == 1) {
			times++;
		}
		else {
			int F;
			char ch;
			cin >> F >> ch;
			if (F == 1) {
				if (times % 2 == 0) {
					S.push_front(ch);
				}
				else {
					S.push_back(ch);
				}
			}
			else {
				if (times % 2 == 0) {
					S.push_back(ch);
				}
				else {
					S.push_front(ch);
				}
			}
		}
	}
	if (times % 2 == 0) {
		while (!S.empty()) {
			cout << S.front();
			S.pop_front();
		}
	}
	else {
		while (!S.empty()) {
			cout << S.back();
			S.pop_back();
		}
	}
	cout << endl;
}

Measured memory_bytes: 896
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <sstream>
#include <functional>
#include <numeric>
#include <cmath>
#include <cstring>
#include <cstdio>
#include <queue>
#include <stack>
#include <set>

using namespace std;

#define ALL(co) co.begin(), co.end()
#define tpl(...) make_tuple(__VA_ARGS__)

typedef long long LL;
typedef pair<int, int> P; typedef pair<int, P> IP; typedef pair<P, P> PP;
typedef vector<int> Array; typedef vector<vector<int> > Array2;
typedef vector<LL> LArray; typedef vector<P> PArray; typedef vector<string> SArray;

const int INF = 1 << 29;
const LL LINF = 1LL << 60;

inline int getInt() { int itiv; return (cin >> itiv, itiv); }
template <typename T> void readAll(vector<T>& vec) { for (int i = 0, size = vec.size(); i < size; i++) cin >> vec[i]; }
template <typename T, typename U> void readAll(vector<pair<T, U> >& vec) { for (int i = 0, size = vec.size(); i < size; i++) cin >> vec[i].first >> vec[i].second; }
template < typename T > inline string toString( const T &a ){ ostringstream oss; oss << a; return oss.str(); };
inline bool between(int min, int max, int n) { return min <= n && n <= max; }
inline bool inRange(int begin, int end, int n) { return begin <= n && n < end; }
inline bool inRange(int size, int n) { return 0 <= n && n < size; }

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

int m, n;

int main(void)
{
	string str;
	for (int i = 0; i < 3; i++)
	{
		int h1, m1, s1, h2, m2, s2; cin >> h1 >> m1 >> s1 >> h2 >> m2 >> s2;
		int hs = h2 - h1, ms = m2 - m1, ss = s2 - s1;
		if(ss < 0) (ms -= 1, ss = 60 + ss);
		if(ms < 0) (hs -= 1, ms = 60 + ms);
		cout << hs << ' ' << ms << ' ' << ss << endl;
	}
	return 0;
}

Measured memory_bytes: 1160
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

func main() {
	K := getStdinInt()
	S := getStdin()

	if len(S) <= K {
		fmt.Printf("%s\n", S)
	} else {
		fmt.Printf("%s%s\n", S[:K], "...")
	}
}

var sc = bufio.NewScanner(os.Stdin)

func getStdin() string {
	sc.Scan()
	return sc.Text()
}
func getStdinInt() int {
	str := getStdin()
	rtn, _ := strconv.Atoi(str)
	return rtn
}


Measured memory_bytes: 1772
#include <iostream>
#include <cstring>
#include <map>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <set>
#include <vector>
#include <queue>
#include <list>
#include <numeric>
#include <stdio.h>
#include <string>
#include <cstdlib>
#include <math.h>
#include <stack>
#include <climits>
#include <bitset>
#include <utility>


using namespace std;
typedef long long ll;
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; }
const ll INF = 1LL <<60;

//最小公倍数
ll gcd(ll x, ll y) {
  ll tmp = 0;
  if (x < y){
    tmp=x;
    x=y;
    y=tmp;
  }
  while (y > 0) {
    ll r = x % y;
    x = y;
    y = r;
  }
  return x;
}

//最大公倍数
ll lcm(ll x,ll y){
  return x/gcd(x,y)*y;
}

//階乗
ll kaijo(ll k){
    ll sum = 1;
    for (ll i = 1; i <= k; ++i)
    {
        sum *= i;
        sum%=1000000000+7;
    }
    return sum;
}

//for(int i = ; i < ; i++){}

ll lmax(ll s,ll t){
  if(s>t){
    return s;
  }
  else{
    return t;
  }
}

ll lmin(ll s,ll t){
  if(s<t){
    return s;
  }
  else{
    return t;
  }
}
// ここから開始
int a [502][502];
vector<pair<int,int> > v;

int main(){
  string s;
  cin>>s;
  bool ans = true;
  for(int i = 0; i < s.length(); ){
   if(s.substr(i,5)=="dream"){
     if(s.substr(i,10)=="dreamerase"){
       i+=5;
       continue;
     }
     else if(s.substr(i,7)=="dreamer"){
       i+=7;
     }
     else{
       i+=5;
     }
   }
   else if(s.substr(i,6)=="eraser"){
     i+=6;
     continue;
   }
   else if(s.substr(i,5)=="erase"){
     i+=5;
     continue;
   }
   else{
     ans = false;
     
     break;
   }
  }
  if(ans) cout<<"YES"<<endl;
  else cout<<"NO"<<endl;  
  return 0;
}


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

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; }

using ll = long long;

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

int main() {
  int N;
  cin>>N;
  vector<ll> S(N);
  for(int i = 0; i < N; i++){
    ll x;
    cin>>x;
    if(i==0)S[i]=x;
    else S[i]=S[i-1]+x;
  }
  ll m=0LL,n=0LL;
  ll d=0LL,e=0LL;
  for(int i = 0; i < N; i++){
    if(i%2==0){
      if(S[i]+m>=0LL) {
        d+=abs(S[i]+1LL+m);
        m-=S[i]+1LL+m;
      }
      if(S[i]+n<=0LL) {
        e+=abs(S[i]+n)+1LL;
        n+=abs(S[i]+n)+1LL;
      }
    }
    if(i%2==1){
      if(S[i]+m<=0LL){
        d+=abs(S[i]+m)+1LL;
        m+=abs(S[i]+m)+1LL;
      }
      if(S[i]+n>=0LL){
        e+=abs(S[i]+1LL+n);
        n-=S[i]+1LL+n;
      }
    }
    
  }
  cout<<min(d,e)<<endl;
}
      

Measured memory_bytes: 1152
#include<iostream>
#include <numeric>
// #include<string>
#include<vector>
#include <algorithm>
#include <cmath>
// #include <functional>

using namespace std;

int main()
{
    // Input
    string a;
    cin >> a;

    if (a[0] == '7' || a[1] == '7' || a[2] == '7') {
        cout << "Yes";
    } else {
        cout << "No";
    }

    return 0;
}


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

#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
#include <iterator>
#include <map>
#include <queue>
#define mp make_pair
#define pb push_back
#define p push
#define FOR(a,c) for(int a = 0;a<c;a++)
#define FORR(el,vecc) for(auto& el:vecc)
#define ll long long
#define abs(x) (x<0 ? (-x) : x)
#define getI(a) scanf("%d",&a)
#define getII(a,b) scanf("%d %d",&a,&b)
#define getIII(a,b,c) scanf("%d%d%d",&a,&b,&c)
#define getL(a) scanf("%lld",&a)
#define getLL(a,b) scanf("%lld %lld",&a,&b)
#define getLLL(a,b,c) scanf("%lld%lld%lld",&a,&b,&c)
#define BEND(c) (c).begin(),(c).end()
#define BEND2(c) (c).begin(),(c).end(),greater<int>()
#define fi first
#define se second
#define PI 3.1415926535897932384626
#define getS(a) scanf("%s",a)
#define pfi(a) printf("%d",a);
#define pfii(a,b) printf("%d%d",a,b);
#define pfl(a) printf("%lld",a);
#define pfll(a,b) printf("%lld%lld",a,b);
#define SIZE 1000000007

using namespace std;

typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<vector<ll>> vvl;
typedef vector<long long> vl;
typedef vector<pair<int,int>> vpi;
typedef vector<pair<long long,long long>> vpl;
typedef vector<vector<pair<long long,long long>>> vvpl;
typedef vector<bool> vb;
typedef pair<int,int> pii;
typedef pair <ll,ll> pll;
const  double eps = 1e-10;
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;
const int MX = 200005;
/*ios_base::sync_with_stdio(false);cin.tie(0);*/

ll gcd(ll n,ll m){
    if (n==0)return m;
    return gcd(m%n,n) ;
}

long long fast_exp(long long n,long long k){
    if(k == 0)
        return 1;
    if(k==1)
        return n;

    long long temp = fast_exp(n,k>>1);

    if((k&1)==1)
        return (n*temp*temp)%SIZE;
    return (temp*temp)%SIZE;

}

int main() {
   ll n;
   cin >> n;
   vl vec(n);
   vl vec2(n);

    for (ll cur, i = 0; i <n ; ++i) {
             cin >> cur;
             vec[i]=cur;
             vec2[i]=cur;
    }
    sort(BEND(vec2));
    ll tmp = vec2[0];
    for (int i = 1; i <n ; ++i) {
        if(tmp==vec2[i]){
            cout << "NO";
            return 0;
        }
    }
    ll count =0;
    for (int i = 0; i <n ; ++i) {
        if(vec[i] != vec2[i])count++;
    }
    if(count == 0 || count == 2){
        cout << "YES";
    }else{
        cout <<"NO";

    }
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <iostream>
#include <string>
#include <vector>
#define REP(i, n) for (int i = 0; (i) < (int)(n); ++ (i))
#define REP3(i, m, n) for (int i = (m); (i) < (int)(n); ++ (i))
#define REP_R(i, n) for (int i = (int)(n) - 1; (i) >= 0; -- (i))
#define REP3R(i, m, n) for (int i = (int)(n) - 1; (i) >= (int)(m); -- (i))
#define ALL(x) ::std::begin(x), ::std::end(x)
using namespace std;
const long long INF = numeric_limits<long long>::max();
typedef long long ll;

constexpr int64_t MOD = 1000000007;

int64_t solve(int64_t N) {
    ll left = 1;
    ll right = 1;
    ll mid = 1;
    REP(i, N) {
        left = (left * 10) % MOD;
        right = (right * 9) % MOD;
        mid = (mid * 8) % MOD;
    }
    ll ans = ((left - right * 2 + mid) % MOD + MOD) % MOD;
    return ans;
}

// generated by online-judge-template-generator v4.6.0 (https://github.com/kmyk/online-judge-template-generator)
int main() {
    std::ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
    constexpr char endl = '\n';
    int64_t N;
    cin >> N;
    auto ans = solve(N);
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3600
#include<stdio.h>

int main(void)
{
	int  a,b=100000,c=-1,d,i,e=0;
	while(1){
	b=100000;c=-1;e=0;
	scanf("%d",&a);
	if(a==0)
		break;
	for(i=1; i<=a; i++){
		scanf("%d",&d);
		if(c<d)
			c=d;
		if(b>d)
			b=d;
		e+=d;
	}
	
	printf("%d\n",(e-b-c)/(a-2)); 
	}
	
	return 0;
}



Measured memory_bytes: 2696
#include<bits/stdc++.h>
#define ll long long
#define Tipo int
#define ii pair<Tipo, Tipo>
#define vi vector<Tipo>
#define vii vector<ii>
#define fs first
#define sc second
#define oo 1000000009
#define N 200123

using namespace std;

int main(){
    ios_base::sync_with_stdio(0);
    int n, m, cont = 0, a[123], total = 0;
    cin >> n >> m;
    for(int i =0; i < n; ++i){
        cin >> a[i];
        total += a[i];
    }
    for(int i = 0; i < n; ++i){
        if(4*m*a[i] >= total) cont++;
    }
    cout << ((cont >= m) ? "Yes\n" : "No\n");
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <map>
#include <queue>
#include <stack>
#include <algorithm>
#include <list>
#include <set>
#include <cmath>
#include <cstring>
#include <stdio.h>
#include <string.h>
#include <sstream>
#include <stdlib.h>
#include <vector>
#include <iomanip>
#include <ctime>
#include <deque>
#include <bitset>
#include <functional>
#include <numeric>
#include <utility>
#include <cstdlib>
#include <cassert>

#define el_cucuy ios_base::sync_with_stdio(0), cout.tie(0); cin.tie(0);
#define llong long long
#define pb push_back
#define bpc __builtin_popcount
#define pii pair <int, int>
#define f first
#define s second

const llong mxn = 4 * 1e5 + 3;
const llong mod = 1e9 + 7;
const llong inf = 1e18 + 9;

using namespace std;

//int dx[]= {1,0,-1,0}; int dy[]= {0,1,0,-1}; //4 Direction
//int dx[]={1,1,0,-1,-1,-1,0,1}; int dy[]={0,1,1,1,0,-1,-1,-1};//8 direction
//int dx[]={2,1,-1,-2,-2,-1,1,2}; int dy[]={1,2,2,1,-1,-2,-2,-1};//Knight Direction
//int dx[]={-1,-1,+0,+1,+1,+0}; int dy[]={-1,+1,+2,+1,-1,-2}; //Hexagonal Direction

llong n, m, a[mxn], dp[1001][1001], sum[mxn];

int main(){
    ///freopen("input.txt", "r", stdin);
    ///freopen("output.txt", "w", stdout);
    cin >> n;
    for (int i = 1; i <= n; i ++){
        cin >> a[i];
    }for (int i = 1; i <= n; i ++){
        sum[i] = sum[i - 1] + a[i];
    }
    for (int sz = 2; sz <= n; sz ++){
        for (int l = 1; l <= n - sz + 1; l ++){
            llong r = l + sz - 1;
            if(sz == 2){
                dp[l][r] = a[l] + a[r];
            }else{
                dp[l][r] = inf;
                for (int x = l; x < r; x ++){
                    dp[l][r] = min(dp[l][r], dp[l][x] + dp[x + 1][r] + sum[r] - sum[l - 1]);
                }
            }
        }
    }cout << dp[1][n];
    return 0;
}


Measured memory_bytes: 8448
#include <stdio.h>
#include <stdlib.h>

int time_num;
int time_list[100];

int qsort_comp(const void* x,const void* y) {
	int* a=(int*)x;
	int* b=(int*)y;
	if(*a>*b)return 1;
	if(*a<*b)return -1;
	return 0;
}

int main(void) {
	int i;
	int time_sum;
	int result;
	while(scanf("%d",&time_num)==1) {
		for(i=0;i<time_num;i++)scanf("%d",&time_list[i]);
		qsort(time_list,time_num,sizeof(int),qsort_comp);
		for(i=0,result=0,time_sum=0;i<time_num;i++) {
			time_sum+=time_list[i];
			result+=time_sum;
		}
		printf("%d\n",result);
	}
	return 0;
}

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

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 FOR(i,a,b) for(ll i=(a);i<(b);++i)
#define ALL(v) (v).begin(), (v).end()
#define p(s) cout<<(s)<<endl
#define p2(s, t) cout << (s) << " " << (t) << endl
#define br() p("")
#define pn(s) cout << (#s) << " " << (s) << endl

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

const int W = 3;

struct Point{
    ll x;
    ll y;
    Point(ll x, ll y): x(x), y(y) {}
    Point(){}
};

struct Puzzle{
    ll A[W][W];
    vector<ll> path;

    Point get_space(){
        Point p;
        FOR(y, 0, 3){
            FOR(x, 0, 3){
                if(A[y][x]==0){
                    p.x = x;
                    p.y = y;
                    return p;
                }
            }
        }
        return p;
    }

    bool operator<(const Puzzle &b)const
    {
        FOR(y, 0, 3){
            FOR(x, 0, 3){
                if(A[y][x] != b.A[y][x]){
                    return A[y][x] < b.A[y][x];
                }
            }
        }
        return false;
    }

    bool is_solved(){
        FOR(y, 0, W){
            FOR(x, 0, W){
                ll target = W*y + x + 1;
                if(y==W-1 && x==W-1) target = 0;
                if(A[y][x]!=target) return false;
            }
        }
        return true;
    }

    void print(){
        FOR(y, 0, W){
            FOR(x, 0, W){
                cout << A[y][x] << ' ';
            }
            cout << endl;
        }
    }
};

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

    // 初期状態
    auto p = Puzzle();
    FOR(y, 0, 3){
        FOR(x, 0, 3){
            cin >> p.A[y][x];
        }
    }

    map<Puzzle, bool> mp;
    mp[p] = true;

    queue<Puzzle> que;
    que.push(p);

    while(!que.empty()){
        auto pu = que.front();
        que.pop();

        if(pu.is_solved()){
            p(pu.path.size());
            return 0;
        }

        FOR(i, 0, 4){
            auto sp = pu.get_space();
            ll x = sp.x;
            ll y = sp.y;
            
            // target position
            ll tx = x + dx[i];
            ll ty = y + dy[i];

            auto cp = pu;

            // in range
            if(0<=tx && tx<W && 0<=ty && ty<W){
                swap(cp.A[y][x], cp.A[ty][tx]);

                // まだその状態になったことがないなら入れる
                if(mp[cp]!=true){
                    mp[cp] = true;
                    cp.path.push_back(i);
                    que.push(cp);
                }   
            }
        }
    }
    
    return 0;
}


Measured memory_bytes: 65892
#include <iostream>
#include <vector>
#include <map>
#include <string>
#include <algorithm>
#include <stack>
#include <cmath>
#include <utility>

int main()
{
    using namespace std;

    string s;

    cin >> s;

    string editor{s};

    int i {};
    for (auto c : s)
    {
        if (c == 'B')
            i = max(0, i - 1);
        else
        {
            editor[i++] = c;
        }
    }

    for (int j = 0; j < i; ++j)
    {
        cout << editor[j];
    }
    cout << endl;

    return 0;
}

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

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);  
	int n;
	cin >> n;
	long long h;
	cin >> h;
	vector<int> a(n), b(n);
	for(int i = 0; i < n; i++) {
		cin >> a[i] >> b[i];
	}
	sort(a.rbegin(), a.rend());
	sort(b.rbegin(), b.rend());
	long long sum = 0;
	int cnt = 0;
	for(int i = 0; i < n; i++) {
		if(b[i] < a.front()) {
			break;
		}
		sum += b[i];
		cnt++;
		if(sum >= h) {
			break;
		}
	}
	int rem = max(1LL * 0, h - sum);
	cnt += (rem + a.front() - 1) / a.front();
	cout << cnt << endl;
	return 0;	
}


Measured memory_bytes: 1024
#include <cstdio>
#include <cstring>
#include <string>
#include <cmath>
#include <cassert>
#include <iostream>
#include <algorithm>
#include <stack>
#include <queue>
#include <vector>
#include <set>
#include <map>
#include <bitset>
#include <functional>
#include <numeric>
using namespace std;

#define repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define rep(i,n) repl(i,0,n)
#define mp(a,b) make_pair((a),(b))
#define pb(a) push_back((a))
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<((x))<<endl
#define fi first
#define se second

#define INF 2147483600
#define long long long
#define EPS 1e-8

// 浮動小数点誤差考慮
inline double add(double a, double b){
  if(abs(a+b) < EPS*(abs(a) + abs(b))) return 0;
  return a+b;
}

struct Point{
  double x,y;
  Point() {}
  Point(double nx, double ny) : x(nx), y(ny) {}
  inline Point operator + (const Point & p){ return Point(add(x, p.x), add(y, p.y)); }
  inline Point operator - (const Point & p){ return Point(add(x,-p.x), add(y,-p.y)); }
  inline Point operator * (double d){ return Point(x*d, y*d); }
  inline double dot(const Point & p){ return add(x * p.x, y*p.y); }  //内積
  inline double det(const Point & p){ return add(x * p.y, -y*p.x); } //外積
  inline double dist(const Point & p){ return sqrt((x-p.x)*(x-p.x) + (y-p.y)*(y-p.y)); }
  inline bool operator < (const Point & p) const {
    if(x != p.x) return x < p.x;
    else return y < p.y;
  }
  inline bool operator == (const Point & p) const {
    return (add(x, -p.x)==0) && (add(y, -p.y)==0);
  }
  friend ostream& operator<<(ostream& os, const Point& p) {
    os << "[" << p.x << "," << p.y << "]";
    return os;
  }
};

double d[1002][1002];

int main(){
  Point s,t;
  cin>>s.x>>s.y>>t.x>>t.y;
  int n;
  cin>>n;
  vector<Point> v(n+2);
  vector<double> r(n+2);
  rep(i,n) cin>>v[i].x>>v[i].y>>r[i];
  v[n]=s;
  v[n+1]=t;
  n+=2;

  fill(d[0], d[1000], INF);
  rep(i,n) repl(j,i+1,n){
    d[j][i] = d[i][j] = max<double>(0, v[i].dist(v[j])-r[i]-r[j]);
  }

  rep(k,n) rep(i,n) rep(j,n) d[i][j] = min(d[i][j], d[i][k]+d[k][j]);

  printf("%.9f\n", d[n-2][n-1]);

  return 0;
}


Measured memory_bytes: 8192
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
	int a,b,c;
	cin>>a>>b;
	if((a==2 && b==1)||(a==1 && b==2)) cout<<3;
	if((a==2 && b==3)||(a==3 && b==2)) cout<<1;
	if((a==1 && b==3)||(a==3 && b==1)) cout<<2;
}

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

int main() {
  string day;
  int N;
  cin >> N >> day;
        
  rep(i, day.size()){
    if(((int)day[i]+N) <= 90) cout << (char)((int)day[i]+N);
    else{
      cout << (char)(65 + (int)day[i] + N - 91);
    }
  }
  
  

  
}

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

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

	int ans = 1 << 28;

	for (int i = 1; i < n; i++) {
		int a = i;
		int b = n - i;

		int sum = 0;

		while (a) {
			sum += a % 10;
			a /= 10;
		}

		while (b) {
			sum += b % 10;
			b /= 10;
		}

		ans = min(ans, sum);
	}

	cout << ans << endl;

	return 0;
}

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

using namespace std;

typedef long long LL;
typedef unsigned long long ULL;
typedef long double LD;

#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define X first
#define Y second
#define pb push_back
#define make_unique(x) sort(all(x)), x.resize(unique(all(x)) - x.begin())
#define int long long

const LL mod = 1e9 + 7;


template<class T>
istream& operator >> (istream& in, vector<T>& v){ for (auto &x : v) { in >> x; } return in; }

template<class T, class U>
istream& operator >> (istream& in, pair<T, U> & v){ in >> v.X >> v.Y;return in; }

template<class T, class U>
ostream& operator << (ostream& out, pair<T, U> & v){ out << v.X << " " << v.Y;return out; }

void chkmax(int &a, int b) {
    a = max(a, b);
    return;
}

void chkmin(int &a, int b) {
    a = min(a, b);
    return;
}

LL ppow (LL x, LL s) {
    if (!s) return 1;
    if (!(s - 1)) return x % mod;
    if (s % 2) return (x * ppow (x, s - 1)) % mod;
    LL b = ppow (x, s / 2);
    return (b * b) % mod;
}

main(){
    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
    //freopen("ILUXA.in", "r", stdin);
    int a, b, k;
    cin >> a >> b >> k;
    if (k < a) {
        a -= k;
        cout << a << " " << b;
        return 0;
    }
    k -= a;
    a = 0;
    b -= k;
    b = max(b, 0ll);
    cout << a << " " << b;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstring>
#include <string>
#include <sstream>
#include <string>
#include <cstdio>
#include <algorithm>
#include <deque>
#include <set>
#include <vector>
#include <cmath>
#include <stack>
#include <set>
#include <map>
#include <queue>
#define maxn 10005
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
int m,n;
char qe[25];
int query(int x)
{
    printf("%d\n",x);
    fflush(stdout);
    scanf("%s",qe);
    if(qe[0]=='V')
        return 2;
    if(qe[0]=='M')
        return 1;
    else
        return 0;
}
int main()
{
    scanf("%d",&n);
    int ans=query(0);
    if(ans==2)
        return 0;
    int lo=0,hi=n-1;
    int mid;
    while(true)
    {
        mid=(lo+hi)/2;
        int tmp=query(mid);
        if(tmp==2)
            return 0;
        if(tmp!=ans)
        {
            if(mid%2)
                lo=mid+1;
            else
                hi=mid;

        }
        else
        {
            if(mid%2)
                hi=mid;
            else
                lo=mid+1;
        }
    }
    query(hi);
    return 0;
}


Measured memory_bytes: 852
S = int(input())
x1=0
y1=0
x2=10**9
y2=1
x3=S%x2
y3=S//x2
if x3 != 0:
    y3 +=1
    x3 = x2 - x3
print('{} {} {} {} {} {}'.format(x1,y1,x2,y2,x3,y3))



Measured memory_bytes: 2940
#include <iostream>
#include <string>
#include <math.h>
#include <vector>
#include <algorithm>
#include <map>
using namespace std;
typedef long long cc;
static const cc MAX = 1000000;
cc i, j, N, Q, M, k, n = 0, A[MAX], B[MAX], p[MAX], x[MAX];
cc Ans=0, sub = 0, flag = 0;
string S, T;
char vec[10];

//vector<pair<cc, cc>>pairs(N);

int main() {	
	cin >> N >> M;
	for (i = 0; i <= N; i++) {
		for (j = 0; j <= N - i; j++) {
			sub = M - (i * 1000 + j * 5000);
			if (sub < 0)
				break;
			if (sub == 10000 * (N - i - j)) {
				k = N - i - j;
				flag = 1;
				break;
			}
		}
		if (flag == 1)
			break;
	}
	if (flag == 1)
		cout << k << " " << j << " " << i << endl;
	else
		cout << -1 << " " << -1 << " " << -1 << endl;
	return 0;
}

Measured memory_bytes: 256
n, k = gets.split.map(&:to_i)

num = Hash.new{|h,k| h[k] = 0}

n.times do
  a, b = gets.split.map(&:to_i)
  num[a] += b
end

num = num.sort_by{|k,v| k}

sum = 0

num.each do |x|
  if sum + x[1] >= k
    puts x[0]
    exit
  end
  sum += x[1]
end


Measured memory_bytes: 10488
#pragma GCC optimize("O3")
#include<bits/stdc++.h> 
using namespace std;
using ll=long long;
using P=pair<ll,ll>;
template<class T> using V=vector<T>; 
#define fi first
#define se second
#define all(v) (v).begin(),(v).end()
const ll inf=(1e18);
//const ll mod=998244353;
const ll mod=1000000007;
ll GCD(ll a,ll b) {return b ? GCD(b,a%b):a;}
ll LCM(ll c,ll d){return c/GCD(c,d)*d;}
struct __INIT{__INIT(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(15);}} __init;
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 (a>b) { a=b; return 1; } return 0; }
V<P> g[100005];
ll t=-1;
ll mi=0,ma=inf;
bool odd=false;
void dfs(int cur,ll s,int par,int c){
  if(par!=-1){
    if(c)chmin(ma,s);
    else chmin(mi,s);
  }
  for(auto p:g[cur]){
    if(p.fi==par)continue;
    dfs(p.fi,p.se-s,cur,c^1);
  }
}
ll visited[2][100005];
void solve(int cur,ll s,int par,int c){
    if(par!=-1){
    if(c)chmin(ma,s);
    else chmin(mi,s);
      if(ma<=0){
        cout<<0<<"\n";
        exit(0);
      }
      if(visited[c^1][cur]!=inf){
          if(t==-1){
              ll d=visited[c^1][cur]-s;
              if(c)d=-d;
              if(d<=0||d%2!=0){
                cout<<0<<"\n";
                exit(0);
              }
              t=d/2;
          }else{
              ll d=visited[c^1][cur]-s;
              if(c)d=-d;
             if(d%2!=0||t!=d/2){
               cout<<0<<"\n";
               exit(0);
             }
          }
          if(visited[c][cur]==inf)visited[c][cur]=s;
          else{
            if(visited[c][cur]!=s){
               cout<<0<<"\n";
               exit(0);
            }
          }
          odd=true;
          return;
      }
        if(visited[c][cur]==inf)visited[c][cur]=s;
        else{
            if(visited[c][cur]!=s){
               cout<<0<<"\n";
               exit(0);
            }
            return;
        }
    }
    for(auto p:g[cur]){
       if(p.fi==par)continue;
       solve(p.fi,p.se-s,cur,c^1);
    }
}
int main(){
  int n,m;
  cin>>n>>m;
  for(int i=0;i<m;i++){
    ll a,b,c;
    cin>>a>>b>>c;
    g[--a].emplace_back(--b,c);
    g[b].emplace_back(a,c);
  }
  if(m==n-1){
        dfs(0,0,-1,0);
        if(ma<=0){
          cout<<0<<"\n";
        }else{
          cout<<max(0ll,ma-abs(mi)-1)<<"\n";
        }
    }
    else{
      for(int i=0;i<n;i++)for(int j=0;j<2;j++)visited[j][i]=inf;
        visited[0][0]=0;
        solve(0,0,-1,0);
        if(odd)cout<<min(1ll,max(0ll,ma-abs(mi)-1))<<"\n";
        else cout<<max(0ll,ma-abs(mi)-1)<<"\n";
    }
}

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

#define fi first
#define se second
#define vi vector<int>
#define vpi vector<pair<int,int>>
#define vll vector<ll>
#define vpll vector<pair<ll,ll>>
#define endl '\n'

#define si(v) int(v.size())
#define all(v) v.begin(), v.end()
#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define rep2(i, n, m) for (ll i = n; i <= (m); ++i)
#define rep3(i, n, m) for (ll i = n; i >= (m); --i)

template<class T, class U> void chmax(T &a, U b) { if (a < b) a = b; }
template<class T, class U> void chmin(T &a, U b) { if (b < a) a = b; }

using ll = long long;
using ld = long double;
using namespace std;

constexpr ll MOD = 1000000007;

signed main()
{
  cout << fixed << setprecision(20);
  ios::sync_with_stdio(false);
  cin.tie(0);
  
  int sx, sy, tx, ty;
  cin >> sx >> sy >> tx >> ty;

  string ans;
  rep(i, ty - sy) ans += "U";
  rep(i, tx - sx) ans += "R";

  rep(i, ty - sy) ans += "D";
  rep(i, tx - sx) ans += "L";

  ans += "L";
  rep(i, ty - sy) ans += "U";
  ans += "U";
  rep(i, tx - sx) ans += "R";
  ans += "R";
  ans += "D";
  ans += "R";
  rep(i, ty - sy) ans += "D";
  ans += "D";
  rep(i, tx - sx) ans += "L";
  ans += "L";
  ans += "U";

  cout << ans << endl;
  
  return (0);
}

Measured memory_bytes: 3616
while True:
    s1 = input()
    if s1 == ".":
        break
    s2 = input()

    w1 = s1.split('"')
    w2 = s2.split('"')

    if len(w1) != len(w2):
        result = "DIFFERENT"
    else:
        n = len(w1)
        result = "IDENTICAL"
        for i in range(n):
            if i % 2 == 0:
                if w1[i] != w2[i]:
                    result = "DIFFERENT"
                    break
            else:
                if w1[i] != w2[i]:
                    if result == "IDENTICAL":
                        result = "CLOSE"
                    else:
                        result = "DIFFERENT"
                        break

    print(result)


Measured memory_bytes: 5580
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <stack>
#include <queue>
#include <set>
#include <map>

using namespace std;

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

typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<vi> vvi;

void Main()
{
	int N; cin >> N;
	int A[100010];
	rep(i, N) cin >> A[i];
    int dp[100010];
    rep(i, N)
    {
        if (i % 2 == 0) {
            dp[0] += A[i];
        } else {
            dp[0] -= A[i];
        }
    }
    rep(i, N)
    {
        dp[i + 1] = 2 * A[i] - dp[i];
    }
    rep(i, N) cout << dp[i] << " ";
}

int main()
{
    cin.tie(nullptr);
	ios_base::sync_with_stdio(false);
	Main();
}


Measured memory_bytes: 2176
#include <iostream>
#include <algorithm>
#include <utility>
#include <string>
#include <vector>
#include <set>
#include <stack>
#include <queue>
#include <map>
#include <math.h>
#include <string.h>
#include <iomanip>
#include <numeric>
#include <cstdlib>
#include <cstdint>
#include <cmath>
#include <functional>
#include <limits>
#include <cassert>
#include <bitset>

using namespace std;

/* template */

using ll = long long;

void debug_out() { std::cout << std::endl; }
 
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cout << H << " ";
  debug_out(T...);
}

#ifdef LOCAL
#define debug(...) cout << "debug: "; debug_out(__VA_ARGS__)
#else
#define debug(...) 
#endif

#define rep(i, a, n) for (int i = (int)(a); i < (int)(n); i++)
#define rrep(i, a, n) for (int i = ((int)(n-1)); i >= (int)(a); i--)
#define Rep(i, a, n) for (long long i = (long long)(a); i< (long long)(n); i++)
#define RRep(i, a, n) for (long long i = ((long long)(n-1ll)); i>=(long long)(a); i--)
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()

template <typename T>
std::ostream& operator<<(std::ostream& os, std::vector<T> vec) {
  for (std::size_t i = 0; i < vec.size(); i++)os << vec[i] << (i + 1 == vec.size() ? "" : " ");
  return os;
}

struct Edge{
    int to;
    ll weight;
    Edge(int t, ll w) : to(t), weight(w){ }
};

struct edge{
    int from;
    int to;
    ll weight;
    edge(int f,int t,ll w) : from(f), to(t), weight(w){ }
};


using Graph = vector<vector<Edge>>;
using graph = vector<vector<int>>;
using edges = vector<edge>;

template <class T>
inline bool chmin(T &a, T b){
    if (a > b){
        a = b;
        return true;
    }
    return false;
}

template <class T>
inline bool chmax(T &a, T b){
    if (a < b){
        a = b;
        return true;
    }
    return false;
}

template <class T>
T lcm(T a, T b){
    return (a*b)/gcd(a,b);
}

constexpr ll LNF = 1LL<<50;

constexpr int INF = 1e9+7;

const double PI=3.14159265358979323846;


vector<int> dx = {-1,0,1,0,-1,1,-1,1};
vector<int> dy = {0,-1,0,1,1,-1,-1,1};

/* template */

ll ctoi(char c) {
	switch (c) {
	case '0': return 0; case '1': return 1; case '2': return 2;
	case '3': return 3; case '4': return 4; case '5': return 5;
	case '6': return 6; case '7': return 7; case '8': return 8;
	case '9': return 9;  default: return 0;
	}
}

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    ll a; cin >> a;
    string s; cin >> s;
    ll b = 0;
    rep(i,0,s.size()){
        if(s[i]=='.') continue;
        b *= 10;
        b += ctoi(s[i]);
    }
    a *= b;
    a /= 100ll;
    cout << a << endl;
}


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

int main() {
  int x, n;
  cin >> x >> n;
  unordered_set<int> p;
  rep(i, n) {
    int q;
    cin >> q;
    p.insert(q);
  }
  rep(i, 1000) {
    if (p.count(x - i) == 0) {
      cout << x - i << endl;
      break;
    } else if (p.count(x + i) == 0) {
      cout << x + i << endl;
      break;
    }
  }

  return 0;
}

Measured memory_bytes: 3600
#include "bits/stdc++.h"
using namespace std;

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

    int cnt0 = 0;
    int cnt1 = 0;
    for (int i = 0; i < S.size(); i++) {
        if (S[i] == '0') cnt0++;
        else cnt1++;
    }

    cout << min(cnt0, cnt1) * 2 << endl;
}

Measured memory_bytes: 512