akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
typedef long long ll;
const ll inf=1e15;
const int MAXN=2e3+10;
const int MAXM=4e4+20;
int edge=1,head[MAXN],tail[MAXM],nex[MAXM];
ll dist[MAXN],r[MAXM],w[MAXM];
int n,S,T,pree[MAXN],preu[MAXN];
int q[MAXM];
bool use[MAXN];
ll flow=0,cost=0;
// |x1-x2|+|y1-y2|=max(x1+y1-(x2+y2),x1-y1-(x2-y2),(y1-x1)-(y2-x2),-(x1+y1)+x2+y2
void add(int u,int v,ll R,ll W){
	edge++,nex[edge]=head[u],head[u]=edge,tail[edge]=v,r[edge]=R,w[edge]=W;
}
void ins(int u,int v,ll R,ll W){
	add(u,v,R,-W); add(v,u,0,W);
}
bool spfa(){
	for (int i=1;i<=T;i++) use[i]=0,dist[i]=inf;
	dist[S]=0; int L=0,R=0; q[++R]=S; use[S]=1;
	while (L<R){
		int u=q[++L];
		for (int e=head[u];e;e=nex[e]){
			int v=tail[e];
			if (dist[v]>dist[u]+w[e]&&r[e]>0){
				dist[v]=dist[u]+w[e];
				preu[v]=u; pree[v]=e;
				if (!use[v]) q[++R]=v,use[v]=1;
			}
		}
		use[u]=0;
	}
	return dist[T]<inf;
}
void argument(){
	ll res=inf;
	for (int now=T;now!=S;now=preu[now]){
		int e=pree[now];
		res=min(res,r[e]);
	}
	flow+=res; cost+=res*dist[T];
	for (int now=T;now!=S;now=preu[now]){
		int e=pree[now];
		r[e]-=res; r[e^1]+=res;
	}
}
int main(){
	scanf("%d",&n);
	S=2*n+5; T=S+1;
	for (int i=1;i<=n;i++){
		int x,y,c; scanf("%d%d%d",&x,&y,&c);
		ins(S,i,c,0);
		ins(i,2*n+1,inf,x+y);
		ins(i,2*n+2,inf,x-y);
		ins(i,2*n+3,inf,y-x);
		ins(i,2*n+4,inf,-x-y);
	}
	for (int i=1;i<=n;i++){
		int x,y,c; scanf("%d%d%d",&x,&y,&c);
		ins(i+n,T,c,0);
		ins(2*n+1,i+n,inf,-x-y);
		ins(2*n+2,i+n,inf,y-x);
		ins(2*n+3,i+n,inf,x-y);
		ins(2*n+4,i+n,inf,x+y);
	}
	while (spfa()) argument();
	printf("%lld\n",-cost);
	return 0;
}


Measured memory_bytes: 768
def read_data():
    N = int(input())
    Es = [[] for i in range(N)]
    for i in range(N - 1):
        a, b = map(int, input().split())
        Es[a - 1].append(b - 1)
        Es[b - 1].append(a - 1)
    return N, Es

def solve(N, Es):
    if N == 2:
        return "Snuke"
    path = find_path(N, 0, N - 1, Es)
    len_path = len(path)
    a = (len_path - 1)// 2
    b = a + 1
    p1 = path[a]
    p2 = path[b]
    e1 = count_edges(N, p1, p2, Es)
    e2 = N - e1
    if e1 > e2:
        return "Fennec"
    else:
        return "Snuke"

def find_path(N, s, g, Es):
    stack = [(s, 0)]
    path = []
    visited = [False] * N
    visited[s] = True
    while True:
        v, d = stack[-1]
        if (path and path[-1][0] == v):
            stack.pop()
            path.pop()
            continue
        if (path and path[-1][1] >= d):
            path.pop()
        path.append((v, d))
        for u in Es[v]:
            if visited[u]:
                continue
            stack.append((u, d + 1))
            visited[u] = True;
            if u == g:
                path = [p for p, depth in path] + [g]
                return path

def count_edges(N, p1, p2, Es):
    stack = [p1]
    visited = [False] * N
    visited[p1] = True
    visited[p2] = True
    count = 0
    while stack:
        v = stack.pop()
        count += 1
        for u in Es[v]:
            if visited[u]:
                continue
            stack.append(u)
            visited[u] = True
    return count


N, Es = read_data()
print(solve(N, Es))
    

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

typedef long long ll;
#define pii pair<int , int>
#define _FastIO ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define MAXX 1005

int n , a , b , k;

int main()
{
    _FastIO;
    cin >> n >> k;
    int r = 100 * (10 - n);
    if(n <= 10){
        cout << r + k << endl;
    }
    else
        cout << k << endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
using namespace std;
int main() {
	long long N, A, B, C, D, E;
	cin >> N >> A >> B >> C >> D >> E;
	cout << max({ (N - 1) / A, (N - 1) / B, (N - 1) / C, (N - 1) / D, (N - 1) / E }) + 5 << endl;
	return 0;
}
/*
#include <bits/stdc++.h>
using namespace std;

int main()
{
    vector<long long> x(6);
    for (int i = 0; i < 6; i++)
    {
        cin >> x.at(i);
    }
    long long n = x.at(0);
    long long count = 0;
    long long min = x.at(0);
    int o = 0;

    for (int i = 0; i < 5; i++)
    {
        if (min <= x.at(i + 1))
        {
            count++;
            continue;
        }
        if (min > x.at(i + 1))
        {
            o++;
            min = x.at(i + 1);
            count += n / x.at(i + 1);
            if (n % x.at(i + 1) > 0)
            {
                count++;
            }
        }
    }
    if (o > 1)
    {
        count -= o - 1;
    }
    cout << count << endl;
}
*/

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

using namespace std;

#define loop(i, n) for(int i = 0;i < int(n);i++)
#define rloop(i, n) for(int i = int(n);i >= 0;i--)
#define range(i, a, b) for(int i = int(a);i <= int(b);i++)
#define SZ(c) int(c.size())
#define ALL(c) c.begin(), c.end()
#define RALL(c) c.rbegin(), c.rend()
#define PI acos(-1)
#define pb push_back
#define mp make_pair
#define fr first
#define sc second
#define sfi1(v) scanf("%d",&v)
#define sfi2(v1, v2) scanf("%d %d",&v1,&v2)
#define sfi3(v1, v2, v3) scanf("%d %d %d",&v1,&v2,&v3)
#define sfll1(v) scanf("%I64d",&v);
#define sfll2(v1, v2) scanf("%I64d %I64d",&v1,&v2)
#define sfll3(v1, v2, v3) scanf("%I64d %I64d %I64d",&v1,&v2,&v3)
#define endl '\n'

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

const int N = 1e5 + 5;
const int LG = 18;
int up[N][LG];
int arr[N];
int n, l, q;

void run_case() {
    cin >> n;
    loop(i, n)cin >> arr[i];
    cin >> l >> q;

    rloop(i, n - 1) {
        int par = i == n - 1 ? n - 1 : (upper_bound(arr, arr + n, arr[i] + l) - arr - 1);
        up[i][0] = par;
        for (int k = 1; k < LG; ++k)
            up[i][k] = up[up[i][k - 1]][k - 1];
    }

    while (q--) {
        int a, b;
        cin >> a >> b;
        a--, b--;
        if (a > b)swap(a, b);
        int ans = 1;
        for (int i = LG - 1; i >= 0; i--) {
            if (up[a][i] < b) {
                a = up[a][i];
                ans += 1 << i;
            }
        }
        cout << ans << endl;
    }
}

int main() {

#ifndef ONLINE_JUDGE
//    freopen("in.in", "r", stdin);
//    freopen("out.in", "w", stdout);
#endif
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);


    int T = 1;
//    cin >> T;
    while (T--)run_case();

    return 0;
}


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

#define INF 1000000007
#define mem(dp,a) memset(dp,a,sizeof dp)
#define flash ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define rep(i,a,b) for(ll i=a;i<b;i++)
#define repb(i,a,b) for(ll i=a;i>=b;i--)
#define f(i,n) for (ll i=0;i<n;i++)
#define sieve(j,mp) for(ll j=2*i ; j<=mp ; j+=i)
#define pb(x) push_back(x)
#define mp(x,y) push_back(make_pair(x,y))
#define tr(c,it) for(((c).begin())it=(c).begin();it!=(c).end();it++)
#define test ll t=1;while(t--)
#define F first
#define S second
main()
{
    flash
    clock_t launch=clock();
    test
    {
        ll n; cin>>n;
        double hp[n+1],dp[n+1][n+1],ans=0.0;
        mem(dp,0); dp[0][0]=1;
        rep(i,1,n+1) cin>>hp[i];
        rep(i,1,n+1)
        f(j,i+1)
        if(j==0) dp[i][j]=dp[i-1][j]*(1-hp[i]);
        else dp[i][j]=dp[i-1][j-1]*hp[i]+dp[i-1][j]*(1-hp[i]);
        rep(i,(n+1)/2,n+1)
        ans+=dp[n][i];
        cout<<fixed<<setprecision(10)<<ans<<endl;
    }
    clog<<((long double)(clock()-launch)/CLOCKS_PER_SEC)<<"\n";
    return 0;
}


Measured memory_bytes: 70656
#include<bits/stdc++.h>
#define rep(i,N) for(ll (i)=0;(i)<(N);(i)++)
#define chmax(x,y) x=max(x,y)
#define chmin(x,y) x=min(x,y)
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
const int mod = 1000000007;

int main() {
  vector<int> a = {1, 9, 7 ,4};
  vector<bool> ok(4);
  rep(i, 4) {
    int t;
    cin >> t;
    rep(j, 4) {
      if(t == a[j]) ok[j] = true;
    }
  }

  bool ans = true;
  rep(i, 4) if(!ok[i]) ans = false;
  if(ans) cout << "YES" << endl;
  else cout << "NO" << endl;
}

Measured memory_bytes: 256
def main():
    A,B,C = map(int,input().split())
    if A == B == C and A%2 == 0 and B%2 == 0 and C%2 == 0:
        print(-1)
    else:
        for i in range(10**8):
            if A%2 != 0 or B%2 != 0 or C%2 != 0:
                break
            else:
                ta,tb,tc = A,B,C
                A = (tb+tc)/2
                B = (ta+tc)/2
                C = (ta+tb)/2
        print(i)

if __name__ == '__main__':
    main()

Measured memory_bytes: 38384
#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  vector<int>x(n);
  int sum=0;
  for(int i=0;i<n;i++) {
    cin >> x.at(i);
    sum+=x.at(i);
    }
  int p=sum/n;
  int q=0;
  int r=0;
  for(int i=0;i<n;i++) {
    q+=(x.at(i)-p)*(x.at(i)-p);
    r+=(x.at(i)-p-1)*(x.at(i)-p-1);
    }
  int hp=min(q,r);
  cout << hp << endl;
  return 0;
  }

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define SQR(x) ((x) * (x))
 
struct Bipartite_Matching
{
  vector< vector< int > > graph;
  int *match;
  bool *used;
  
  Bipartite_Matching(int n)
  {
    graph.resize(n);
  }
  void add_edge(int u, int v)
  {
    graph[u].push_back(v);
    graph[v].push_back(u);
  }
  bool dfs(int v)
  {
    used[v] = true;
    for(int i = 0; i < graph[v].size(); i++) {
      int u = graph[v][i], w = match[u];
      if(w == -1 || (!used[w] && dfs(w))) {
        match[v] = u;
        match[u] = v;
        return(true);
      }
    }
    return(false);
  }
  int bipartite_matching()
  {
    int ret = 0;
    match = new int[graph.size()];
    used = new bool[graph.size()];
    memset(match, -1, sizeof(int) * graph.size());
    for(int i = 0; i < graph.size(); i++) {
      if(match[i] == -1) {
        memset(used, 0, sizeof(bool) * graph.size());
        ret += dfs(i);
      }
    }
    return(ret);
  }
};
int main()
{
  long long N, M, X[100], Y[100], V[100];
  long long x[100], y[100];
   
  while(cin >> N >> M, N) {
    for(int i = 0; i < N; i++) {
      cin >> X[i] >> Y[i] >> V[i];
    }
    for(int i = 0; i < M; i++) {
      cin >> x[i] >> y[i];
    }
 
    double low = 0, high = 1e9;
    for(int i = 0; i < 70; i++) {
      double mid = (low + high) / 2.0;
      Bipartite_Matching graph(N + M);
      for(int j = 0; j < N; j++) {
        for(int k = 0; k < M; k++) {
          if(sqrt(SQR(X[j] - x[k]) + SQR(Y[j] - y[k])) <= mid * V[j]) {
            graph.add_edge(j, N + k);
          }
        }
      }
      if(graph.bipartite_matching() == M) high = mid;
      else low = mid;
    }
    cout << fixed << setprecision(10) << low << endl;
  }
}

Measured memory_bytes: 2104
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>
#define ll long long

int n;
ll a[100010];

int main(){
  scanf("%d",&n);
  for(int i=0;i<=n;i++){
    scanf("%lld",&a[i]);}
  
  ll fflag[100010]={};
  ll ans =0;
  ll count = 1;
  ll tmp;

  ll sum=0;
  for(int i=0;i<=n;i++){
    sum += a[i];}
  if(sum==0){
    printf("0\n");
    return 0;}

  for(int i=0;i<=n;i++){
    if(a[i]>count){
      printf("-1\n");
      return 0;}
    if(sum > count){
      tmp = count;}
    else{
      tmp = sum;}
    ans += tmp;
    sum -= a[i];
    count = (tmp-a[i])*2;}
    
  
  printf("%lld\n",ans);
  
  return 0;
}


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

const ll MOD = 1000000007;

// nのcnt乗を計算
ll pow2( ll n, ll cnt ){
  if( cnt == 1 ) return n;
  if( cnt == 0 ) return 1;
  if( cnt%2 == 0 ){
    ll tmp = pow2(n,cnt/2);
    return tmp%MOD*tmp%MOD;
  }else{
    ll tmp = pow2(n,cnt/2);
    return tmp%MOD*n%MOD*tmp%MOD;
  }
}

// n*(n-1)*...*(n-cnt+1) を計算
ll fac( ll n, ll cnt ){
  if( cnt == 1 ) return n;
  if( cnt == 0 ) return 1;
  return fac(n-1,cnt-1)%MOD*n%MOD;
}

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

  // nCa mod MOD を計算
  ll xa = fac(n,a);
  ll ya = fac(a,a);
  ll amod = xa*pow2(ya,MOD-2)%MOD;
  if( amod < 0 ) amod += MOD;
  // cout << xa << " " << ya << " " << amod << endl;

  // nCb mod MOD を計算
  ll xb = fac(n,b);
  ll yb = fac(b,b);
  ll bmod = xb*pow2(yb,MOD-2)%MOD;
  if( bmod < 0 ) bmod += MOD;
  // cout << xb << " " << yb << " " << bmod << endl;

  ll ans = pow2(2,n);
  if( ans < 0 ) ans += MOD;
  ans -= amod + bmod + 1;

  while( ans < 0 )
    ans += MOD;

  cout << ans << endl;

  return 0;
}


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

template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    fill( (T*)array, (T*)(array+N), val );
}

struct Edge{
    double cost;
    int to,used;
    bool operator>(const Edge &right)const{
        return cost > right.cost;
    }
};

int main(void){
    int n,m,p,a,b;
    while(cin>>n>>m>>p>>a>>b, m){
        a--,b--;
        int t[8];
        vector<vector<Edge>> g(m);
        rep(i,n) cin>>t[i];
        rep(i,p){
            int x,y;
            double z;
            cin>>x>>y>>z;
            x--,y--;
            g[x].push_back({z,y,0});
            g[y].push_back({z,x,0});
        }
        double dp[30][1<<8];
        Fill(dp, INF);
        priority_queue<Edge,vector<Edge>,greater<Edge>> qu;
        qu.push({dp[a][0] = 0, a,0});
        while(qu.size()){
            Edge cur = qu.top(); qu.pop();
            int v = cur.to;
            int used = cur.used;
            if(dp[v][used] < cur.cost) continue;
            for(Edge e : g[v]){
                rep(k,n){
                    if(used & bit(k)) continue;
                    if( dp[e.to][used|bit(k)] > cur.cost + e.cost/t[k]){
                        dp[e.to][used|bit(k)] = cur.cost + e.cost/t[k];
                        qu.push({dp[e.to][used|bit(k)], e.to, used|bit(k)});
                    }
                }
            }
        }
        double res = INF;
        rep(mask,1<<n){
            res = min(res, dp[b][mask]);
        }
        if(res == INF){
            cout<<"Impossible"<<endl;
        }else{
            printf("%.3f\n",res);
        }
    }
    return 0;
}



Measured memory_bytes: 4628
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using static System.Console;
using static System.Math;
using static MyIO;
using static MyUtil;

public class B { public static void Main() => (new Solver()).Solve(); }

public class Solver
{
	public void Solve()
	{
		WriteLine(GetString().Select(x => (long)(x - '0')).Sum() % 9 == 0 ? "Yes" : "No");
	}
}

public static class MyIO
{
	private static string[] args = new string[0];
	private static int cnt = 0;
	private static IEnumerable<string> getArgs(long N) => Range(0, N).Select(_ => getArg());
	private static string getArg()
	{
		if(cnt == args.Length) { args = Console.ReadLine().Split(); cnt = 0; }
		return args[cnt++];
	}

	public static int GetInt() => int.Parse(getArg());
	public static long GetLong() => long.Parse(getArg());
	public static double GetDouble() => double.Parse(getArg());
	public static decimal GetDecimal() => decimal.Parse(getArg());
	public static string GetString() => getArg();
	public static char GetChar() => getArg()[0];
	public static int[] GetInts(long N) => getArgs(N).Select(int.Parse).ToArray();
	public static long[] GetLongs(long N) => getArgs(N).Select(long.Parse).ToArray();
	public static double[] GetDoubles(long N) => getArgs(N).Select(double.Parse).ToArray();
	public static decimal[] GetDecimals(long N) => getArgs(N).Select(decimal.Parse).ToArray();
	public static string[] GetStrings(long N) => getArgs(N).ToArray();
}

public static class MyUtil
{
	public static void chmax<T>(ref T x, T y) where T : IComparable<T> { if(x.CompareTo(y) < 0) x = y; }
	public static void chmin<T>(ref T x, T y) where T : IComparable<T> { if(x.CompareTo(y) > 0)	x = y; }
	public static void swap<T>(ref T x, ref T y) { T tmp = x; x = y; y = tmp; }
	public static long rightShift(long x, long y) => (x >> (int)y);
	public static long leftShift(long x, long y) => (x << (int)y);
	public static bool contains(long s, long x) => (rightShift(s, x) & 1L) == 1L;
	public static long gcd(long x, long y) => (y == 0) ? x : gcd(y, x % y);
	public static long lcm(long x, long y) => (x / gcd(x,y)) * y;	
	public static IEnumerable<int> Range(long start, long count) => Enumerable.Range((int)start, (int)count);
	public static void Sort(this List<string> source) => source.Sort(StringComparer.Ordinal);
}


Measured memory_bytes: 27472
#include<iostream>
#include<map>
#include<vector>
#include<algorithm>
#include<queue>

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

using namespace std;
using ll = long long int;

int main(void) {
    int a, b; cin >> a >> b;
    if (a > 9 || b > 9) cout << -1 << endl;
    else cout << a * b << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <map>
#include <unordered_map>
#include <set>
#include <queue>
#include <cmath>
#include <numeric>
#include <utility>
#include <iomanip>

using namespace std;
using int64 = long long;

struct aaa{aaa(){cin.tie(nullptr); ios::sync_with_stdio(false); cout<<fixed<<setprecision(20);};}aaa;

int main() {
    int n;
    cin >> n;
    unordered_map<int, int> a, b;
    for (int i=0; i<n; i++) {
        int v;
        cin >> v;
        if (i%2 == 0)
            a[v]++;
        else
            b[v]++;
    }

    pair<int, int> a1, a2, b1, b2;
    for (auto [i, v] : a) {
        if (a1.second <= v) {
            a2 = a1;
            a1 = {i, v};
            continue;
        }
        if (a2.second <= v)
            a2 = {i, v};
    }
    for (auto [i, v] : b) {
        if (b1.second <= v) {
            b2 = b1;
            b1 = {i, v};
            continue;
        }
        if (b2.second <= v)
            b2 = {i, v};
    }

    if (a1.first != b1.first) {
        cout << n - (a1.second + b1.second) << endl;
        return 0;
    }

    cout << n - max((a1.second + b2.second), (a2.second + b1.second)) << endl;
}


Measured memory_bytes: 6924
n=gets.to_i
a=[]
$<.map{|s|
    x,l=s.split.map &:to_i
    a<<[x-l,x+l]
}
a.sort_by!{|s,t|t}
c=0
u=a[0][0]
a.map{|s,t|
    if u<=s
        c+=1
        u=t
    end
}
p c

Measured memory_bytes: 13432
a,b,c = [str(input()) for i in range(3)]
current = 'a'
while True:
  try:
    cur = current[len(current)-1]
    if cur == 'a':
      current+=a[0]
      a=a[1:]
    elif cur == 'b':
      current+=b[0]
      b=b[1:]
    elif cur == 'c':
      current+=c[0]
      c=c[1:]
  except:
      print(current[len(current)-1].upper())
      break

Measured memory_bytes: 9032
n=int(input())
h=list(map(int,input().split()))
dp=[0 for i in range(n)]
dp[0]=0
dp[1]=abs(h[1]-h[0])
for i in range(2,n):
  dp[i]=min(dp[i-1]+abs(h[i]-h[i-1]),dp[i-2]+abs(h[i]-h[i-2]))
print(dp[n-1])

Measured memory_bytes: 13980
import sys
input = sys.stdin.readline
N, M = map(int,input().split())
ABs = list([list(map(int,input().split())) for _ in range(M)])
 
ship1 =[]
shipn =[]
 
for ab in ABs:
    if ab[0]==1:ship1.append(ab[1])
    elif ab[1]==N:shipn.append(ab[0])
 
      
if list(set(ship1) & set(shipn)) ==[]:print('IMPOSSIBLE')
else:print('POSSIBLE')


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

string calcAddition( string a, string b )
{
    int as = a.size(), bs = b.size(), d = as > bs ? as - bs : bs - as;
    string s = "0", t = "0";
    for( int i = 0; i < d; i++ )
        as > bs ? t += "0" : s += "0";
    s += a; t += b;

    for( int i = s.size() - 1; i >= 1; i-- )
    {
        s[i] += t[i] - '0';
        if( s[i] > '9' )
        {
            s[i] -= 10;
            s[i-1]++;
        }
    }

    bool j = true;
    for( int i = 0; i < s.size(); i++ )
        if( s[i] != '0' )
            j = false;
    if( j )
        return "0";
    return s[0] == '0' ? s.substr( 1, s.size() ) : s;
}

string calcSubtraction( string a, string b )
{
    int as = a.size(), bs = b.size(), d = as > bs ? as - bs : bs - as;
    string s = "", t = "";
    for( int i = 0; i < d; i++ )
        as > bs ? t += "0" : s += "0";
    s += a; t += b;

    if( s < t )
    {
        string temp = s;
        s = t;
        t = temp;
    }

    for( int i = s.size() - 1; i >= 0; i-- )
    {
        if( s[i] < t[i] )
        {
            s[i] += 10;
            if( s[i-1] >= '1' )
                s[i-1]--;
            else
            {
                int j = i - 1;
                while( s[j] == '0' )
                    s[j--] += 9;
                s[j]--;
            }
        }
        s[i] -= ( t[i] - '0' );
    }
    if( s.size() == 1 )
        return s;
    return s[0] == '0' ? calcAddition( s.substr( 1, s.size() ), "0" ) : s;
}

int main()
{
    string a, b;

    cin >> a >> b;

    int as = a.size(), bs = b.size();
    string s = a.substr( 1, as ), t = b.substr( 1, bs );
    int ss = s.size(), ts = t.size();

    if( a[0] == '-' && b[0] == '-' )
    {
        if( ss > ts || ss == ts && s > t )
            cout << "-";
        cout << calcSubtraction( s, t ) << endl;
    }
    else if( a[0] >= '0' && b[0] >= '0' )
    {
        if( as < bs || as == bs && a < b )
            cout << "-";
        cout << calcSubtraction( a, b ) << endl;
    }
    else if( a[0] == '-' )
        cout << "-" << calcAddition( s, b ) << endl;
    else
        cout << calcAddition( a, t ) << endl;

    return 0;
}



Measured memory_bytes: 4224
N,K = map(int,input().split())
p = sorted([list(map(int,input().split())) for _ in range(N)])
x, y = zip(*p)
inf = float('inf')
ans = inf

for i in range(N-K+1):
    for j in range(K+i-1, N):
        Ys = sorted(y[i:j+1])
        for k in range(len(Ys)-K+1):
            ans = min(ans, (x[j]-x[i])*(Ys[k+K-1]-Ys[k]))
print(ans)


Measured memory_bytes: 3064
#include <iostream>
//#include <iomanip>
//#include <string>
#include <vector>
//#include <algorithm>
//#include <utility>
//#include <set>
//#include <map>
//#include <queue>
//#include <deque>
//#include <bitset>
//#include <math.h>
using namespace std ;
using ll = long long ;
//using ld = long double ;
//using vll = vector<ll> ;
//using vvll = vector<vll> ;
//using vc = vector<char> ;
//using vvc = vector<vc> ;
//using vb = vector<bool> ;
//using vvb = vector<vb> ;
//using pll = pair<ll,ll> ;

//ll mod = 1000000007 ;
//long double pie = acos(-1) ;

//string yorn(bool a){if(a) return"Yes" ; return "No" ;}
//string YorN(bool a){if(a) return"YES" ; return "NO" ;}
ll gcd(long long a,long long b){if(b==0) return a ; return gcd(b,a%b) ;}
//ll lcm(long long a,long long b){return a/gcd(a,b)*b ;}
//ll sa(long long a,long long b){if(a>b) return a-b ; return b-a ;}
//void mysort(vector<long long> &a){sort(a.begin(),a.end()) ;}
//void myrev(vector<long long> &a){reverse(a.begin(),a.end()) ;}

int main(){
	ll n,k ;
	cin >> n >> k ;
	ll g = 0 ;
	ll mx = 0 ;
	for(int i=0;i<n;i++){
		ll a ; cin >> a ;
		g = gcd(g,a) ;
		if(mx<a) mx = a ;
	}
	if(mx>=k&&k%g==0) cout << "POSSIBLE" << endl ;
	else cout << "IMPOSSIBLE" << endl ;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using lli = long long;
#define rep(i,n) for(int i=0;i<n;i++)
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; }

string s;

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


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

using namespace std; 
#define REP(i, n) for (int i = 0; i < (n); i++)
const int MAX = 1000000;
bool IsPrime[MAX];
vector<int> Era(int n = MAX) {
    vector<int> res;
    IsPrime[0] = false; IsPrime[1] = false; 
    for (int i = 2; i < n; ++i) IsPrime[i] = true;
    for (int i = 2; i < n; ++i) {
        if (IsPrime[i]) {
            res.push_back(i);
            for (int j = i*2; j < n; j += i) IsPrime[j] = false;
        }
    }
    return res;
}
typedef long long ll;
int main(int argc, char const *argv[])
{
    cin.tie(0);
   	ios::sync_with_stdio(false);
    Era();
    int X; cin >> X;
    while(IsPrime[X]!=true) {
        X++;
    }
    cout << X << endl;
    return 0;
}


Measured memory_bytes: 1916
#include <bits/stdc++.h>
#define _overload3(_1, _2, _3, name, ...) name
#define _rep(i, n) repi(i, 0, n)
#define repi(i, a, b) for (int i = (a); i < (b); ++i)
#define rep(...) _overload3(__VA_ARGS__, repi, _rep, )(__VA_ARGS__)
#define ALL(x) x.begin(), x.end()
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
using namespace std;
using ll = long long;
using lld = long double;
using VI = vector<int>;
using VVI = vector<VI>;
using VL = vector<ll>;
using VVL = vector<VL>;
using PII = pair<int, int>;
random_device rnd;
mt19937 mt(rnd());

double PI = 6.28318530717958623200 / 2.0;

const int IINF = 1 << 30;
const ll INF = 1ll << 60;
const ll MOD = 1e9 + 7;
int main()
{
    int n;
    cin >> n;
    map<int, int> mp;
    rep(i, 1, n)
    {
        int t;
        cin >> t;
        t--;
        mp[t]++;
    }
    rep(i, n)
    {
        cout << mp[i] << endl;
    }
    return 0;
}


Measured memory_bytes: 13024
def read():
    N = int(input().strip())
    A = list(map(int, input().strip().split()))
    return N, A


def next_state(c, a, n_patterns):
    # c := c[0] >= c[1] >= c[2]
    idx = -1
    for i in range(3):
        if c[i] == a:
            idx = i
            break
    if idx == -1:
        return -1, -1
    n_equals = 1
    n_equals += 1 if c[idx%3] == c[(idx + 1) % 3] else 0
    n_equals += 1 if c[idx%3] == c[(idx + 2) % 3] else 0
    c[idx%3] += 1
    n_patterns *= n_equals
    n_patterns %= 1000000007
    return c, n_patterns

def solve(N, A):
    c = [0, 0, 0]
    n = 1
    for a in A:
        c, n = next_state(c, a, n)
        if c == -1 and n == -1:
            return 0
    return n
    
if __name__ == '__main__':
    inputs = read()
    output = solve(*inputs)
    print("%d" % output)


Measured memory_bytes: 14072
line = readlines
len = line.length
i = 0
k=1
while i < len
    line[i] = line[i].chomp.split(' ')
    i += 1
end
a=line[1]
n=1
a.length.times do|m|
  if a[m].to_i==0
    n=0
    k=a.length
  end
end 

a.length.times do|m|
if k==a.length
  break
end
      n=n*a[m].to_i
      if n>10**18
        n=-1
       k=a.length
      end
   end



p n

Measured memory_bytes: 22676
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rrep(i, n) for (int i = 1; i < (n+1); ++i)
using namespace std;
using ll = long long;
const int INF = -100100100;
typedef pair<int,int> P;

int main(){
    int n,m;
    cin >> n >> m;
    ll ans;
    vector<int> x(m),y(m);
    rep(i,m) cin >> x[i];
    sort(x.begin(),x.end());
    if(n>=m){
        cout << 0 << endl;
        return 0;
    }
    rep(i,m-1){
        y[i] = x[i+1] - x[i];
    }
    sort(y.begin(),y.end(),greater<int>());
    if(n>1){
        for(int i = n-1; i<m;i++)ans+=y[i];
        cout << ans << endl;
        return 0;
    }else{
        rep(i,m-1)ans+=y[i];
        cout << ans << endl;
        return 0;
    }
}

Measured memory_bytes: 1024
#include <iostream>
using namespace std;
const int mod = 1e9 + 7;
int main() {
    int n, m;
    cin >> n >> m;
    int s[n], t[m];
    for(int i = 0; i < n; i++)
        cin >> s[i];
    for(int i = 0; i < m; i++)
        cin >> t[i];

    long dp[m + 1] = {};
    for(int i = 0; i < n; i++) {
        long tmpdp[m + 1] = {};
        for(int j = 1; j <= m; j++) {
            if(t[j - 1] == s[i]) {
                tmpdp[j] += dp[j - 1] + 1;
                tmpdp[j] %= mod;
            }
        }
        for(int j = 1; j <= m; j++) {
            tmpdp[j] += tmpdp[j - 1];
            tmpdp[j] %= mod;
            dp[j] += tmpdp[j];
            dp[j] %= mod;
        }
    }

    cout << dp[m] + 1 << endl;
    return 0;
}


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

int main(){
    int n,cnt=0;
    string a,b,c;
    cin >> n >> a >> b >> c;
    for(int i=0; i<n; i++){
        if(a[i]==b[i] && a[i]==c[i]){
            //do nothing
        }else if(a[i]==b[i] && a[i]!=c[i]){
            c[i] = a[i];
            cnt++;
        }else if(a[i]==c[i] && a[i]!=b[i]){
            b[i] = a[i];
            cnt++;
        }else if(c[i]==b[i] && a[i]!=c[i]){
            a[i] = b[i];
            cnt++;
        }else{
            b[i] = a[i];
            cnt++;
            c[i] = a[i];
            cnt++;
        }
    }
   
    cout << cnt << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<set>
#include<math.h>
#include<vector>
#include<sstream>
#include<queue>
#include<functional>
#include<bitset>
#include<cstdio>
#include<iomanip>
#include<map>
#include<unordered_map>
#include<unordered_set>
#include <string.h>

using ll = long long;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define reps(i, x) for(int i=1;i<=(int)(x);i++)
#define rrep(i, x) for(int i=((int)(x)-1);i>=0;i--)
#define rreps(i, x) for(int i=(int)(x);i>0;i--)
#define all(x) (x).begin(),(x).end()
#define m0(x) memset(x,0,sizeof(x))
#define vll vector<ll>
#define vi vector<int>
#define vpll vector<pair<ll,ll>>
#define vpi vector<pair<int,int>>
#define mod 1000000007
#define put2darr(arr, row, col) rep(i, row) { rep(j, col) { printf("%18d", arr[i][j]); } cout << endl; }

using namespace std;

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

/* 1..10
 * rep:   0 1 2 3 4 5 6 7 8 9
 * reps:  1 2 3 4 5 6 7 8 9 10
 * rrep:  9 8 7 6 5 4 3 2 1 0
 * rreps: 10 9 8 7 6 5 4 3 2 1
 */

using Int = long long;
int main() {
    Int l,r;
    cin>>l>>r;
    if(r-l>1e4){
        cout<<0<<endl;
        return 0;
    }
    Int ans=2019;
    for(Int i=l;i<r;i++)
        for(Int j=i+1;j<=r;j++)
            chmin(ans,i*j%2019);
    cout<<ans<<endl;
    return 0;
}



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

int top,S[100];

void push(int x){
  S[++top] = x;
}

int pop(){
  top--;
  return S[top+1];
}

int main(){
  int a,b;
  top = 0;
  char s[100];

  while( scanf("%s",s) != EOF){
    if(s[0] == '+'){
      a = pop();
      b = pop();
      push(a + b);
    }
    else if(s[0] == '-'){
      b = pop();
      a = pop();
      push(a - b);
    }
    else if(s[0] == '*'){
      a = pop();
      b = pop();
      push(a * b);
    }
    else{
      push(atoi(s));
    }
  }

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

  return 0;

}

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

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

    bool win_flg = false;
    for ( int i = 0; i < n; i++ ) {
        int a = 0;
        cin >> a;
        h -= a;
        if ( h <= 0 ) {
            win_flg = true;
        }
    }

    if ( win_flg == true ) {
        cout << "Yes" << endl;
    }
    else {
        cout << "No" << endl;
    }

    return 0;
}

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

int n;
long long a[100055];
long long suff[100055];

int main() {
    cin >> n;

    for (int i = 0; i <= n; i++) {
        scanf("%lld", &a[i]);
    }

    if (a[0] > 1 || (a[0] == 1 && n != 0)) {
        puts("-1");
        return 0;
    }

    for (int i = n; i >= 0; i--) {
        suff[i] = a[i] + suff[i + 1];
    }

    long long cur = 1;
    long long res = 1;

    for (int i = 1; i <= n; i++) {
        long long can = min(cur * 2, suff[i]);

        res += can;
        cur = can - a[i];

        if (cur < 0) {
            puts("-1");
            return 0;
        }
    }

    cout << res;

    return 0;
}


Measured memory_bytes: 5308
#include<iostream>
#include<algorithm>
#include<string.h>
using namespace std;

int main() {
  long int N;
  long int X[200001], Y[200001];
  cin>>N;
  for (int i = 0; i < N; i++) {
    cin>>X[i];
  }
  memcpy(Y, X, sizeof(long int)*N);
  sort(Y, Y+N);
  
  for (long int i = 0; i < N; i++) {
    if (X[i] <= Y[N/2-1]) {
      cout<<Y[N/2]<<endl;
      continue;
    }
    if (X[i] >= Y[N/2]) {
      cout<<Y[N/2-1]<<endl;
      continue;
    }
  }

  return 0;
}


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

struct Fast {Fast(){cin.tie(0);ios::sync_with_stdio(0);}} fast;
using intpair = pair<int, int>;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define reps(i, n, m) for (int i = (int)(n); i <= (int)(m); i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define rALL(obj) (obj).rbegin(), (obj).rend()
#define ceiv(a, b) ((int)((a) + (b) - 1)/(int)(b))
#define int long long

signed main(){
    int a, b; string s;
    cin >> a >> b >> s;
    bool ans = count(ALL(s),'-')==1 && s[a] == '-';
    cout << (ans ? "Yes" : "No") << endl;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main()
{
  int n;
  string s;
  cin >> n >> s;
  string t = s.substr(n / 2);
  if (n > 1 and s == t + t) {
    cout << "Yes\n";
  } else {
    cout << "No\n";
  }
}


Measured memory_bytes: 256
#include<string>
#include<iostream>
#include<vector>
#include<algorithm>
#include<cmath>

using namespace std;

int main(void)
{
  int n;
  cin >> n;
  
  vector<int> x(n);
  for(int i = 0; i < n; i++)
  {
    cin >> x[i];
  }
  
  int average = 0;
  for(int i = 0; i < n; i++)
  {
    average += x[i];
  }
  average = average / n;
  
  int total[3] = {0,0,0};
  for(int j = 0; j < 3; j++)
  {
    if(j == 1)
    {
      average++;
    }
    else if(j == 2)
    {
      average -= 2;
    }
    for(int i = 0; i < n; i++)
    {
      total[j] += (x[i] - average)*(x[i] - average);
    }
  }
  
  int min = 0;
  if(total[0] < total[1])
  {
    min = total[0];
    if(min < total[2])
    {
      min = total[0];
    }
    else
    {
      min = total[2];
    }
  }
  else
  {
    min = total[1];
    if(min < total[2])
    {
      min = total[1];
    }
    else
    {
      min = total[2];
    }
  }
  
  cout << min;
}


Measured memory_bytes: 256
#pragma region
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <vector>
#include <map>
#include <queue> 
#include <stack>
#include <set>
#include <list>

using namespace std;
typedef long long ll;
//#define rep(i, s, e) for (int(i) = (s); (i) < (e); ++(i))
#define rep(i, e) for (int(i) = 0; (i) < (e); ++(i))
#define all(x) x.begin(),x.end()
#pragma endregion


int main()
{
	int n, z, w; cin >> n >> z >> w;
	vector<int> a(n);
	rep(i, n)cin >> a[i];
	if (n == 1)cout << abs(a[0] - w) << endl;
	else cout << max(abs(a[n - 1] - w), abs(a[n - 1] - a[n - 2])) << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main() {
    int sum = 0;
    for(int i = 0; i < 3; ++i) {
        int a;
        cin >> a;
        sum += a;
    }
    if(sum > 21) {
        cout << "bust" << endl;
    }else {
        cout << "win" << endl;
    }
}

Measured memory_bytes: 256
using System;
using System.Linq;
class Program
{
    static void Main()
    {
        int[] input = Console.ReadLine().Split().Select(i => int.Parse(i)).ToArray(); 
        //int a=int.Parse(Console.ReadLine());
        //string a = Console.ReadLine();
        
        Console.WriteLine(Math.Max(input[0]-input[1],0));
        Console.ReadLine();
    }
}


Measured memory_bytes: 13268
#include<bits/stdc++.h>
using namespace std;
const int maxn = 10000 + 10;
char A, B, temp;

int main(){
    cin >> A >> B;
    if(A > B) cout << '>' << "\n";
    else if(A < B) cout << '<' << "\n";
    else cout << '=' << "\n";
    return 0;
}


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

// #include <unordered_set>
using namespace std;

#define ll long long
#define endl '\n'
#ifndef _WINDOWS
// no getchar_unlocked on Windows so just call getchar
#define getchar getchar_unlocked
#endif

template <typename Func>
inline void loop(int e, Func&& f) {
    for (int i = 0; i < e; i++) {
        std::forward<Func>(f)(i);
    }
}
template <typename Func>
inline void loop(int s, int e, Func&& f) {
    for (int i = s; i < e; i++) {
        std::forward<Func>(f)(i);
    }
}
template <typename T>
inline void scanpn(T& num) {
    int c;
    num = 0;
    c = getchar();
    // bool negative = false;
    // if (c == '-') {
    // 	negative = true;
    // 	c = getchar();
    // }
    for (; (c > 47 && c < 58); c = getchar()) num = num * 10 + c - 48;
    // if (negative)
    //     number = -number;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin >> n;
    string s;
    cin >> s;
    unordered_map<char, unordered_set<int>> mapping{{'R', unordered_set<int>{}}, {'G', unordered_set<int>{}}, {'B', unordered_set<int>{}}};
    for (int i = 0; i < n; i++) mapping[s[i]].insert(i);
    ll ans = mapping['R'].size() * mapping['G'].size() * mapping['B'].size();
    if (ans == 0) {
        cout << ans << endl;
        return 0;
    }
    int max_inv = (n & 1) ? n / 2 : n / 2 - 1;
    for (int inv = 1; inv <= max_inv; inv++) {
        for (int i = 0; i < n - 2 * inv; i++) {
            int a = i, b = i + inv, c = i + inv + inv;
            int r1 = (mapping['R'].count(a) + mapping['R'].count(b) + mapping['R'].count(c));
            int r2 = mapping['G'].count(a) + mapping['G'].count(b) + mapping['G'].count(c);
            int r3 = mapping['B'].count(a) + mapping['B'].count(b) + mapping['B'].count(c);
            // cout << !r1 << ' ' << !r2 << ' ' << !r3 << endl;
            if (r1 && r2 && r3) {
                ans--;
            }
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3808
n = gets.chomp.to_i
a = gets.chomp.split(" ").map(&:to_i)
a.unshift(0)
# 偶数番目：正、奇数番目：負

ans = 0
count = 0
sum = 0
for i in 1..n
    if i % 2 == 0
        if sum + a[i] <= 0
            count += (sum + a[i]).abs + 1
            sum = 1
        else
            sum += a[i]
        end
    else
        if sum + a[i] >= 0
            count += (sum + a[i]).abs + 1
            sum = -1
        else
            sum += a[i]
        end
    end
end

ans = count

# 偶数番目：負、奇数番目：正
count = 0
sum = 0
for i in 1..n
    if i % 2 == 0
        if sum + a[i] >= 0
            count += (sum + a[i]).abs + 1
            sum = -1
        else
            sum += a[i]
        end
    else
        if sum + a[i] <= 0
            count += (sum + a[i]).abs + 1
            sum = 1
        else
            sum += a[i]
        end
    end
end

ans = count if ans > count

puts ans

Measured memory_bytes: 9996
#include<bits/stdc++.h>
using namespace std;
#define ALL(A) A.begin(),A.end()
const long long mod=1000000007;
int main(){
    int n;vector<tuple<int,int,int>> w;
    int x,y,h;
    cin>>n;
    for(int i=0;i<n;i++)
    {
        cin>>x>>y>>h;
        w.push_back(make_tuple(h,x,y));
    }
    sort(w.begin(),w.end());
    
    int height;bool flag;
    for(int i=0;i<101;i++)
    {
        for(int j=0;j<101;j++)
        {
            flag=true;
            height=get<0>(w[n-1])+abs(i-(get<1>(w[n-1])))+abs(j-(get<2>(w[n-1])));
            for(int k=0;k<n;k++)
            {
                if(get<0>(w[k])==0)
                {
                    if(abs(i-get<1>(w[k]))+abs(j-get<2>(w[k]))<height)
                    flag=false;
                }
                else
                {
                    if(height!=get<0>(w[k])+abs(i-get<1>(w[k]))+abs(j-get<2>(w[k])))
                    flag=false;
                }
                
            }
            if(flag==true)
            {
                cout<<i<<' '<<j<<' '<<height<<endl;
            }
        }
    }
    return 0;
}

Measured memory_bytes: 256
class BinaryTree {
  constructor() {
    this.root = null;
    BinaryTree.Node = BinaryTree.Node || BinaryTree._createNodeClass();
  }

  static _createNodeClass() {
    return class Node {
      constructor(key, parent = null, left = null, right = null) {
        this.key = key;
        this.parent = parent;
        this.left = left;
        this.right = right;
      }

      getChildrenNumber() {return Number(this.left !== null) + Number(this.right !== null);}

      isLeftChild() {return this.parent ? this.parent.left === this : null;}

      getLeftOrRight() {return this.isLeftChild() ? 'left' : 'right';}

      getSuccessor() {
        let n;
        if (this.right !== null) {
          n = this.right;
          while (n.left !== null) n = n.left;
        } else {
          n = this.parent;
          while (!n.isLeftChild && n.parent != null) n = n.parent;
        }
        return n;
      }
    };
  }

  insert(key) {
    if (this.root === null) {
      this.root = new BinaryTree.Node(key);
      return;
    }
    let x = this.root, y;
    let newNode = new BinaryTree.Node(key);
    while (x !== null) {
      y = x;
      x = x[key < x.key ? 'left' : 'right'];
    }
    newNode.parent = y;
    y[key < y.key ? 'left' : 'right'] = newNode;
  }

  find(key, n = this.root) {
    if (n === null || n.key === key) return n;
    return this.find(key, n[key < n.key ? 'left' : 'right']);
  }

  delete(key) {
    const n = this.find(key);
    const leftOrRight = n.getLeftOrRight();
    switch (n.getChildrenNumber()) {
    case 0:
      n.parent[leftOrRight] = null;
      break;
    case 1:
      n.parent[leftOrRight] = n.left || n.right;
      n.parent[leftOrRight].parent = n.parent;
      break;
    default:
      const skey = n.getSuccessor().key;
      this.delete(skey);
      n.key = skey;
    }
  }

  printByIneorder() {
    let str = '';
    const innerFunc = (n) => {
      if (n === null) return;
      innerFunc(n.left);
      str += ` ${n.key}`;
      innerFunc(n.right);
    }
    innerFunc(this.root);
    console.log(str);
  }

  printByPreorder() {
    let str = '';
    const innerFunc = (n) => {
      if (n === null) return;
      str += ` ${n.key}`;
      innerFunc(n.left);
      innerFunc(n.right);
    }
    innerFunc(this.root);
    console.log(str);
  }

  print() {
    this.printByIneorder();
    this.printByPreorder();
  }
}

(function main(){
  const lines = require('fs').readFileSync('/dev/stdin', 'utf8').trim().split('\n');
  const n = Number(lines.shift());

  const tree = new BinaryTree();
  lines.forEach(function(cmd) {
    switch (cmd.charAt(0)) {
    case 'i': tree.insert(Number(cmd.split(' ')[1])); break;
    case 'f': console.log(tree.find(Number(cmd.split(' ')[1])) ? 'yes' : 'no'); break;
    case 'd': tree.delete(Number(cmd.split(' ')[1])); break;
    default: tree.print();
    }
  });
})();



Measured memory_bytes: 203552
N = int(input())
cnt = 0
flg = False

for i in range(N):
    D = [int(x) for x in input().split()]
    if D[0] == D[1]:
        cnt += 1
        if cnt == 3:
            flg = True
            break
    else:
        cnt = 0

if flg:
    print('Yes')
else:
    print('No')

Measured memory_bytes: 9180
// AtCoder Beginner Contest 153 E.cpp

#include <iostream>
#include <vector>
#include <climits>

using namespace std;

int main()
{
	int h = 0, n = 0, answer = INT_MAX, max_power = 0, min_magic = INT_MAX;
	cin >> h >> n;
	vector<int>a(n);
	vector<int>b(n);
	for (int i = 0; i < n; i++) {
		cin >> a[i] >> b[i];
		if (b[i] < min_magic) { //魔力最小探し
			min_magic = b[i];
			continue;
		}
		if (a[i] > max_power) { //攻撃力最大探し
			max_power = a[i];
		}
	}
	vector<int>dp(h + max_power + 1, INT_MAX); //INT_MAXで埋めた"h+max_power"なdp配列

	dp[0] = 0; dp[1] = min_magic; //先に入れる体力が0と1のとき
	for (int i = 2; i < int(dp.size()); i++) {
		for (int j = 0; j < int(a.size()); j++) {
			if (0 < i - a[j]) {                 //候補の攻撃で倒しきれないとき
				if (dp[i] > dp[i - a[j]] + b[j])
					dp[i] = dp[i - a[j]] + b[j]; //かつ値が小さくなっていたら更新
			}
			else {                //候補の攻撃で倒しきれるとき
				if (dp[i] > b[j])
					dp[i] = b[j]; //かつ値が小さくなっていたら更新
			}
		}
	}

	/*for (auto i : dp) {
		cout << i << endl;
	}
	cout << endl;*/

	for (int i = h; i < int(dp.size()); i++) { //倒しきれる中での最小を探す
		if (answer > dp[i])
			answer = dp[i];
	}

	cout << answer << endl;

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ff first
#define ss second
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define mset(x, y) memset((x), (y), sizeof(x))
#define sz(x) ((int)(x).size())
#define rep(i, a, b) for(i = a; i < b; i++)
#define per(i, a, b) for(i = a; i >= b; i--)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define cerr cout
#define endl '\n'
using namespace std;

string to_string(string s) { return '"' + s + '"';}
string to_string(char s) { return string(1, s);}
string to_string(const char* s) { return to_string((string) s);}
string to_string(bool b) { return (b ? "true" : "false");}
template <typename A> string to_string(A);
template <typename A, typename B>string to_string(pair<A, B> p) {return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";}
template <typename A> string to_string(A v) {bool f = 1; string r = "{"; for (const auto &x : v) {if (!f)r += ", "; f = 0; r += to_string(x);} return r + "}";}
void debug_out() { cerr << endl; }
template <typename Head, typename... Tail> void debug_out(Head H, Tail... T) {cerr << " " << to_string(H); debug_out(T...);}
#define pr(...) cerr << "[" << #__VA_ARGS__ << "] :", debug_out(__VA_ARGS__)

typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<pii> vpii;
typedef vector<pll> vpll;
const ld eps = 1e-7;
const ll mod = 1000000007;
const ll N = 998244353;

ll binpow(ll b, ll p){ ll ans = 1; while(p > 0){if(p & 1) ans = (ans * b) % mod; b = (b * b) % mod; p >>= 1;}return ans;}
ll modinv(ll x){return binpow(x, mod - 2);}

signed main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);

	string s;
	int n, c = 0, i;
	cin >> n >> s;
	int x = count(all(s), 'R');
	for(i = x; i < n; i++)
	{
		if(s[i] == 'R')
			c++;
	}
	cout << c << endl;

	// rep(i, 0, n + 1)
	// string sw(i, 'W');
	// string sr(n - i, 'R');
	// string t = sr + sw;
}

Measured memory_bytes: 3688
// just testing. 

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

int n, k;
vector<int> one;
#define ll long long int
vector<ll> sums;
int cntt(ll a)
{
	int ret = 0;
	for (ll v : sums) if ((v & a) == a) ++ret;
	return ret;
}

int main() {
    // freopen("z.in", "r", stdin);

    cin >> n >> k; 
    one.resize(n, 0);
        
    for(int i = 0; i < n; ++i) {
    	cin >> one[i];
    }
    for(int i = 0; i < n; ++i) {
    	ll acc = 0; 
    	for(int j = i; j < n; ++j) {
    		acc += one[j];
    		sums.push_back(acc);
    	}
    }

    ll mask = 0; 

    for(int i = 40; i >= 0; --i) {
    	if(cntt(mask | (1LL << i)) >= k) 
    		mask |= (1LL << i);
    }

    cout << mask << endl;

    return 0;
}


Measured memory_bytes: 6132
function Main (input) {
  const inputs = input.split(/\s/g)[0];
  const base = 700;
  const mached = inputs.match(/o/g);
  const total = base + (mached ? mached.length * 100 : 0);
  
  console.log('%s', total);
}

Main(require("fs").readFileSync("/dev/stdin", "utf8"));


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

int main(){
  ll x;
  cin>>x;
  ll y = x/500;
  y *= 1000;
  ll z = x % 500;
  z /= 5;
  z *=5;
  cout << y + z << endl;
}
  
  

Measured memory_bytes: 256