akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<vector>

using namespace std;

#define int long long
const long long INF = (long long)1e18;

/*
ベルマン–フォード法
	単一始点の最短経路および負の閉路が存在するかをを時間計算量O(VE)で求める(V:頂点の数,E:辺の数)
	負の辺が存在している場合でも動作する
引数: V->頂点の数(頂点の番号はV以下), S->始点, edge->辺(firstは頂点の対,secondは重み), dis->始点からの最短距離を入れるためのvector
返り値: true->負の閉路が存在する, false->負の閉路が存在しない
*/

bool Bellman_Ford(int V, int S, vector<pair<pair<int,int>,int>> &edge, vector<int> &dis){
	dis.clear();
	dis.resize(V,INF);
	dis[S] = 0;
	
	for(int i = 0; i < V; i++){
		bool flag = false;
		for(int j = 0; j < edge.size(); j++){
			if(dis[edge[j].first.first] != INF && dis[edge[j].first.second] > dis[edge[j].first.first] + edge[j].second){
				dis[edge[j].first.second] = dis[edge[j].first.first] + edge[j].second;
				flag = true;
				if(i == V-1) return true;
			}
		}
		if(!flag) break;
	}
	
	return false;
}

signed main(){
	int V, E, s;
	vector<pair<pair<int,int>,int>> edge;
	vector<int> dis;
	
	cin>>V>>E>>s;
	
	for(int i = 0; i < E; i++){
		int s, t, d;
		
		cin>>s>>t>>d;
		
		edge.push_back({{s, t}, d});
	}
	
	if(!Bellman_Ford(V, s, edge, dis)) {
		
		for(int d : dis){
			if(d < INF)cout<<d<<endl;
			else cout<<"INF"<<endl;
		}
		
	} else {
		cout<<"NEGATIVE CYCLE"<<endl;
	}
	return 0;
}


Measured memory_bytes: 3172
#include<bits/stdc++.h>
using namespace std;
const int N=1e5+5;
typedef long long ll;
typedef pair<int,int>pii;
priority_queue<pii>q1,q2;
int n,l[N],r[N],i,x,y,dt;
bool b[N];
ll ans;
inline ll calc(){
	ll ans=y=0;
	for(i=1;i<=n;++i)q1.push(pii(l[i],i)),q2.push(pii(-r[i],i));
	memset(b+1,0,n);
	for(i=1;i<=n;++i){
		for(;b[q1.top().second];q1.pop());
		for(;b[q2.top().second];q2.pop());
		if(i&1)x=q1.top().second,ans+=dt=max(0,q1.top().first-y),y+=dt,q1.pop();
			else x=q2.top().second,ans+=dt=max(0,y+q2.top().first),y-=dt,q2.pop();
		b[x]=1;
	}
	for(;!q1.empty();q1.pop());for(;!q2.empty();q2.pop());
	return ans+abs(y);
}
int main(){
	scanf("%d",&n);
	for(i=1;i<=n;++i)scanf("%d%d",l+i,r+i);
	ans=calc();for(i=1;i<=n;++i)swap(l[i],r[i]),l[i]*=-1,r[i]*=-1;
	ans=max(ans,calc());printf("%lld\n",ans);
}

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

using namespace std;

#define MAX 114514

int par[MAX], rnk[MAX];

void init(int N)
{
    for (int i = 0; i < N; i++) {
        par[i] = i;
        rnk[i] = 0;
    }
}

int find(int x)
{
    if (par[x] == x) {
        return x;
    }
    return par[x] = find(par[x]);
}

void unite(int x, int y)
{
    x = find(x); y = find(y);
    if (x == y) return;

    if (rnk[x] < rnk[y]) {
        par[x] = y;
    } else {
        par[y] = x;
        if (rnk[x] == rnk[y]) rnk[x]++;
    }
}

bool same(int x, int y)
{
    return (find(x) == find(y));
}

typedef pair<int, int> pii;
typedef pair<int, pii> P;

int kruscal(P *p, int N, int M)
{
    sort(p, p + M);
    init(N);
    int res = 0;
    for (int i = 0; i < M; i++) {
        int a = p[i].second.first, b = p[i].second.second;
        if (!same(a, b)) {
            unite(a, b);
            res += p[i].first;
        }
    }
    return res;    
}

int main()
{
    int N, M;
    while (cin >> N, N) {
        cin >> M;
        P p[MAX];
        char x;
        for (int i = 0; i < M; i++) {
            int a, b, c;
            cin >> a >> x >> b >> x >> c;
            p[i] = P(c/100-1, pii(a, b));
        }
        cout << kruscal(p, N, M) << endl;
    }
    return 0;
}

Measured memory_bytes: 4328
#include<stdio.h>
#include<iostream>
using namespace std;


long long int left[3000];
long long int right[3000];
int MOD = 1e9+7;

long long int modpow(long long int a,int b) {
    if( b == 0) return 1;
    if(b%2 == 0) {
        long long int half = modpow(a,b/2);
        return half * half % MOD;
    } else {
        return a * modpow(a,b-1) % MOD;
    }
}

long long int calc (int l, int r) {
    long long int res = 1;
    long long int mul = 1;
    int x = l;
    for(int i=0;i<r;i++) {
        res = ((res * x) % MOD);
        x--;
    }
    long long int z = r;
    for(int i=0;i<r;i++) {
        mul = ((mul * z) % MOD);
        z--;
    }
    res = (res * modpow(mul,MOD-2) % MOD );
    return res;
}

int N,K;
int main (){
    cin >> N >> K;
    int b = K;
    int r = N-K;
    long long int ans = 0;
    for(int i=1;i<=K;i++) {
            cout << (calc(1+r,i) * calc(K-1,i-1) % MOD) << endl;;
    }
    return 0;  
}

Measured memory_bytes: 256
/* Author: Rennan Rocha
 * Time: $%Y%$-$%M%$-$%D%$ $%h%$:$%m%$:$%s%$
**/

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

#define F first
#define S second
#define PB push_back
#define MP make_pair

#define ll long long
#define vi vector<int>
#define vll vector<ll>
#define pi pair<int,int>
#define pll pair<ll, ll>
#define vpi vector<pi>
#define vpll vector<pll>

using namespace std;
using namespace __gnu_pbds;

typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
//*find_by_order(); order_of_key();

int arr[200010];

int main() {
    ios_base::sync_with_stdio(false);

    int n;
    cin >> n;
    for(int i = 0; i < n-1; i++) {
        int x;
        cin >> x;
        arr[x]++;
    }
    for(int i = 1; i <= n; i++) {
        cout << arr[i] << "\n";
    }
}


Measured memory_bytes: 4428
N = int(input())
A = list(map(int,input().split()))
C = {}
for i in range(N):
    if A[i] not in C:
        C[A[i]] = 0
    C[A[i]] += 1
if len(C)>3:
    print("No")
else:
    if N%3==0:
        if 0 in C:
            if len(C)==1:
                print("Yes")
            elif len(C)==2:
                if C[0]==N//3:
                    print("Yes")
                else:
                    print("No")
            else:
                print("No")
        else:
            if len(C)!=3:
                print("No")
            else:
                flag = 0
                for a in C:
                    if C[a]!=N//3:
                        flag = 1
                        break
                if flag==0:
                    C = list(C.keys())
                    if C[0]^C[1]==C[2]:
                        print("Yes")
                    else:
                        print("No")
                else:
                    print("No")
    else:
        if len(C)==1 and 0 in C:
            print("Yes")
        else:
            print("No")

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

typedef long long ll;
 
int main(){
  int a, b, x;
  cin >> x >> a >> b;
  string ans;
  if(abs(x-a)<abs(x-b)) ans = "A";
  else ans = "B";
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include <algorithm>
#include<string>
#include <numeric>
#include<math.h>
#include <bits/stdc++.h>
using namespace std;

int main(void) {
  string sa;
  cin >>sa;
  int a,b,c;
  for(int i=0;i<sa.size();i++)
  {
      if(sa[i]=='/')sa[i]=' ';
  }
  istringstream s(sa);
  s >> a >> b >> c;
  if(a<2019)cout<<"TBD"<<endl;
  else if(b>4)cout<<"TBD"<<endl;
  else cout<<"Heisei"<<endl;
  return 0;
}


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

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

  if (N == 1){
    cout << "1" << endl;
    return 0;
  }

  int64_t Lm2 = 2;
  int64_t Lm1 = 1;
  int64_t L;

  for (int n = 1; n < N; n++){
    L = Lm1 + Lm2;
    Lm2 = Lm1;
    Lm1 = L;
  }
  cout << L << endl;
}


Measured memory_bytes: 256
using System;
using System.Linq;//リストの使用
using System.Collections.Generic;
using System.Text;//テキストの高速出力に必要
class Program
{
	static void Main()
	{
		int n = int.Parse(Console.ReadLine());
		long[] nums = Array.ConvertAll(Console.ReadLine().Split(' '),long.Parse);
    Array.Sort(nums);
    bool answer = true;

    if(n % 3 != 0)
    {
      for(int i = 0; i < n; i++)
      {
        if(nums[i] != 0) answer = false;
      }
    }else
    {
      for(int i = 1; i < n/3; i++)
      {
        if(nums[i] != nums[i-1]) answer = false;
      }
      for(int i = n/3+1; i < n*2/3; i++)
      {
        if(nums[i] != nums[i-1]) answer = false;
      }
      for(int i = n*2/3+1; i < n; i++)
      {
        if(nums[i] != nums[i-1]) answer = false;
      }
      if(((nums[0]^nums[n/3])^nums[n*2/3]) != 0) answer = false;
    }
    
		Console.WriteLine(answer?"Yes":"No");
	}
}

Measured memory_bytes: 19808
//....SARANSH GUPTA....\\

#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define fo(p,n) for(int i=p;i<n;i++)
#define FIO ios_base::sync_with_stdio(false);   cin.tie(NULL);   cout.tie(NULL);
#define endl "\n"
#define mp make_pair
#define pb push_back
#define mod 1000000007

int main()
{
    FIO
    int n;
    cin>>n;
    int a[n];
    fo(0,n)
    cin>>a[i];
    int count=0;
    for(int i=0;i<n;i++)
    {
        for(int j=i+1;j<n;j++)
        {
            for(int k=j+1;k<n;k++)
            {
                if((a[i]+a[j]>a[k])&&(a[i]+a[k]>a[j])&&(a[j]+a[k]>a[i])&&(a[i]!=a[j])&&(a[j]!=a[k])&&(a[i]!=a[k]))
                count++;
            }
        }
    }
    cout<<count<<endl;
}

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

namespace 演習4_1_2
{
    class Program
    {
        static void Main(string[] args)
        {
            var x = Console.ReadLine().Split(' ');
            if ((x[0] == x[1] && x[0] == x[2]) || (x[0] != x[1] && x[0] != x[2] && x[1] != x[2])) 
                Console.WriteLine("No");
            else
                Console.WriteLine("Yes");
        }
    }
}


Measured memory_bytes: 13140
#include<stdio.h>
main()
{
  int n, a, b, c, cn;//(cn= テδ、テつサテつ甘δ」テつつョn)

  scanf("%d", &n);//the number of date set

  for(cn=0 ; cn < n ; cn++){

    scanf("%d %d %d", &a, &b, &c);
  
    if(a*a== b*b +c*c || b*b== a*a + c*c || c*c == a*a + b*b){

      printf("YES\n");
    }
      else{printf("NO\n");

      }

    
  }
  return 0;

}

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

using namespace std;

int main(){
    int n, k;
    cin >> n >> k;
    int ans = 1;
    for(int i = 0; i < n; ++i){
        ans = min(2 * ans, ans + k);
    }
    cout << ans;
    return 0;
}


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

using namespace std;

string S;
int main(){
    cin >> S;
    int red=0,blue=0;
    for(int i=0;i<S.length();i++){
        if(S[i]=='0') red++;
        else blue++;
    }
    cout << 2*min(red,blue);
}

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

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

  if (a % 2==0) {
    cout << "Even" << endl;
  }
  else if (b % 2==0) {
    cout << "Even" << endl;
  }
  else{
    cout << "Odd" << endl;
  }
  
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define int long long
signed main(){
    int a,b;
    cin>>a>>b;
    if(a==1){
        cout<<b<<endl;
        return 0;
    }
    int sum=1;
    for(int i=0;i<a-1;i++){
        sum=sum*(b-1);
    }
    cout<<sum*b<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define all(x) (x).begin(), (x).end()
using namespace std;
typedef long long ll;
const int MOD = 1e9 + 7;

int main() {
  ll a, b, c;
  cin >> a >> b >> c;
  if (a % 2 == 0 || b % 2 == 0 || c % 2 == 0) {
    cout << 0 << endl;
  } else {
    cout << min({a * b, b * c, c * a}) << endl;
  }
  return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(){
    int matrix[3][3];
    char x;
    for(int i=0;i<3;i++){
        for(int j=0;j<3;j++){
            scanf("%d", &matrix[i][j]);
        }
    }
    int n;
    scanf("%d",&n);
    int input[n];
    for(int k=0;k<n;k++){
        scanf("%d", &input[k]);
        for(int i=0;i<3;i++){
            for(int j=0;j<3;j++){
                if(input[k] == matrix[i][j]){
                    matrix[i][j] = x;
                }
            }
        }
    }
    int ctr[8] = {0};
    int last=2;
    for(int i=0;i<3;i++){
        if(matrix[i][0]==x){
            ++ctr[0];
        }
        if(matrix[i][2]==x){
            ++ctr[1];
        }
        if(matrix[0][i]==x){
            ++ctr[2];
        }
        if(matrix[2][i]==x){
            ++ctr[3];
        }
        if(matrix[i][i]==x){
            ++ctr[4];
        } 
        if(matrix[i][last--]==x){
            ++ctr[5];
        }
        if(matrix[1][i]==x){
            ++ctr[6];
        }
        if(matrix[i][1]==x){
            ++ctr[7];
        }
    }
    int flag = 0;
    for(int i=0;i<8;i++){
        if(ctr[i]==3){
            flag = 1;
        }
    }
    printf("%s\n", (flag == 1) ? "Yes" : "No");

    return 0;
}

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

int main() {
  int64_t N,Q=1000000007,Z=0;
  cin>>N;
  vector<vector<vector<vector<int64_t>>>>p(N-2,vector<vector<vector<int64_t>>>(4,vector<vector<int64_t>>(4,vector<int64_t>(4))));
  for(int i=0;i<4;i++){
    for(int j=0;j<4;j++){
      for(int k=0;k<4;k++){
        if(!(i*16+j*4+k==6||i*16+j*4+k==9||i*16+j*4+k==18)){
          p.at(0).at(i).at(j).at(k)=1;
        }
      }
    }
  }
  for(int i=1;i<N-2;i++){
    for(int a=0;a<4;a++){
      for(int b=0;b<4;b++){
        for(int c=0;c<4;c++){
          for(int d=0;d<4;d++){
            if(!((a==0&&b==1&&d==2)||(a==0&&c==1&&d==2)||(b==0&&c==1&&d==2)||(b==1&&c==0&&d==2)||(b==0&&c==2&&d==1))){
              p.at(i).at(b).at(c).at(d)=(p.at(i).at(b).at(c).at(d)+p.at(i-1).at(a).at(b).at(c))%Q;
            }
          }
        }
      }
    }
  }
  for(int a=0;a<4;a++){
    for(int b=0;b<4;b++){
      for(int c=0;c<4;c++){
        Z=(Z+p.at(N-3).at(a).at(b).at(c))%Q;
      }
    }
  }
  cout<<Z<<endl;
}

Measured memory_bytes: 384
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <bitset>
#include <string>
#include <cstring>
#include <cmath>
#include <iomanip>
#include <sstream>

#define fi first
#define se second
#define pb push_back
#define fore(i, a, b) for (int i = (a), _b = (b); i < (_b); ++i)
#define fort(i, a, b) for (int i = (a), _b = (b); i <= (_b); ++i)
#define ford(i, a, b) for (int i = (a), _b = (b); i >= (_b); --i)

using namespace std;

typedef long long LL;
typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ii> vii;
typedef vector<vii> vvii;

const int INF = 1e9 + 3;
const int MOD = 1e9 + 7;
const int N = 1e5 + 3;

int n, k, q, cnt, a[N];

int main() {
    ios_base::sync_with_stdio(0); cin.tie(0);
    cin >> n >> k >> q;
    int x;
    fort(i, 1, q) {
        cin >> x;
        --a[1]; ++a[x];
        --a[x + 1];
    }
    fort(i, 1, n) a[i] += a[i - 1];
    fort(i, 1, n) cout << (k + a[i] > 0 ? "Yes\n" : "No\n");
    return 0;
}


Measured memory_bytes: 1024
import static java.lang.Math.*;
import static java.util.Arrays.*;
import java.util.*;
import java.io.*;

public class Main {
	
	final long MOD =  (long)(1e9+7);
	void solve() {
		long X = sc.nextLong();
		long Y = sc.nextLong();
		if (Math.abs(X - Y) <= 1)
			out.println("Brown");
		else
			out.println("Alice");
	}
	
	static void tr(Object... os) { System.err.println(deepToString(os)); }
	static void tr(int[][] as) { for (int[] a : as) tr(a); }

	void print(int[] a) {
		out.print(a[0]);
		for (int i = 1; i < a.length; i++) out.print(" " + a[i]);
		out.println();
	}

	public static void main(String[] args) throws Exception {
		new Main().run();
	}

	MyScanner sc = null;
	PrintWriter out = null;
	public void run() throws Exception {
		sc = new MyScanner(System.in);
		out = new PrintWriter(System.out);
		for (;sc.hasNext();) {
			solve();
			out.flush();
		}
		out.close();
	}

	class MyScanner {
		String line;
		BufferedReader reader;
		StringTokenizer tokenizer;

		public MyScanner(InputStream stream) {
			reader = new BufferedReader(new InputStreamReader(stream));
			tokenizer = null;
		}
		public void eat() {
			while (tokenizer == null || !tokenizer.hasMoreTokens()) {
				try {
					line = reader.readLine();
					if (line == null) {
						tokenizer = null;
						return;
					}
					tokenizer = new StringTokenizer(line);
				} catch (IOException e) {
					throw new RuntimeException(e);
				}
			}
		}
		public String next() {
			eat();
			return tokenizer.nextToken();
		}
		public String nextLine() {
			try {
				return reader.readLine();
			} catch (IOException e) {
				throw new RuntimeException(e);
			}
		}
		public boolean hasNext() {
			eat();
			return (tokenizer != null && tokenizer.hasMoreElements());
		}
		public int nextInt() {
			return Integer.parseInt(next());
		}
		public long nextLong() {
			return Long.parseLong(next());
		}
		public double nextDouble() {
			return Double.parseDouble(next());
		}
		public int[] nextIntArray(int n) {
			int[] a = new int[n];
			for (int i = 0; i < n; i++) a[i] = nextInt();
			return a;
		}
	}
}

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

int main(){
  int n,m; cin>>n>>m;
  int k[m]={},s[m][n]={},p[m]={};
  REP(i,m){
    cin>>k[i];
    REP(j,k[i]) cin>>s[i][j];
  }
  REP(i,m) cin>>p[i];
  
  int ans=0;
  REP(bit,1<<n){
    int t[n]={};
    REP(i,n) t[i]=(bit>>i)&1;
    
    bool judge=true;
    REP(i,m){
      int cnt=0;
      REP(j,k[i]) cnt+=t[s[i][j]-1];
      if(cnt%2==p[i]) continue;
      else judge=false;
    }
    if(judge==true) ans++;
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 256
' Imports System.Collections.Generic
' Imports System.Linq
' Imports System.Text
' Imports System.Text.RegularExpressions

Class Main
    Public Shared Sub Main()
        Dim A, B As Integer
        Dim arr() As String
        arr = Split(Console.ReadLine())
        A = arr(0) : B = arr(1)
        Console.WriteLine(Math.Max(A + B, Math.Max(A - B, A * B)))
        Return
    End Sub
End Class

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

int main(){
    int s;
    int j = 0;
    cin >> s;

    vector<int> v(s);
    vector<int> vTemp(s);
    for(int i = 0; i < s; i++){
      cin >> v[i];
      vTemp[i] = 0;
    }


    while (vTemp[s-1] == 0){
      j++;
      for(int i = 0; i < s; i++){
        vTemp[i] = v[i] % (int)pow(2,j);
      }
      sort(vTemp.begin(), vTemp.end());
    }

    cout << j-1 <<endl;
    return 0;
}

Measured memory_bytes: 256
import numpy as np
N, D = list(map(int, input().split()))
vecs = np.array([list(map(int, input().split())) for _ in range(N)])
cnt = 0
for i in range(N):
    for j in range(i+1,N):
        dist = np.linalg.norm(vecs[i]-vecs[j])
        if dist.is_integer():
            cnt+=1
print(cnt)

Measured memory_bytes: 21804
printn = lambda x: print(x,end='')
inn = lambda : int(input())
inl   = lambda: list(map(int, input().split()))
inm   = lambda:      map(int, input().split())
ins = lambda : input().strip()
DBG = True # and False
BIG = 10**18
R = 10**9 + 7

def ddprint(x):
  if DBG:
    print(x)

a = []
for i in range(3):
    a.append(inl())
b = [[0]*3 for i in range(3)]
n = inn()
for t in range(n):
    x = inn()
    for i in range(3):
        for j in range(3):
            if a[i][j]==x:
                b[i][j] = 1
if sum(b[0])==3 or \
       sum(b[1])==3 or \
       sum(b[2])==3 or \
       b[0][0]+b[1][0]+b[2][0]==3 or \
       b[0][1]+b[1][1]+b[2][1]==3 or \
       b[0][2]+b[1][2]+b[2][2]==3 or \
       b[0][0]+b[1][1]+b[2][2]==3 or \
       b[0][2]+b[1][1]+b[2][0]==3:
        print('Yes')
else:
        print('No')


Measured memory_bytes: 38480
b1, b2, b3 = (int(x) for x in input().split())

if b1==1 and b2==0 and b3== 0 :
    print("Close")
if b1==0 and b2==1 and b3== 0 :
    print("Close")
if b1==1 and b2==1 and b3== 0 :
    print("Open")
if b1==0 and b2==0 and b3== 1 :
    print("Open")
if b1==0 and b2==0 and b3== 0 :
    print("Close")



Measured memory_bytes: 5604
#include <bits/stdc++.h>
using namespace std;
const int INF = 1e9;

int main() {
  int n;
  cin >> n;
  vector<int> h(n);
  for (int i = 0; i < n; ++i) cin >> h[i];

  vector<int> dp(n + 5, INF);
  dp[0] = 0;
  for (int i = 0; i < n; ++i) {
    dp[i + 1] = min(dp[i + 1], dp[i] + abs(h[i] - h[i + 1]));
    dp[i + 2] = min(dp[i + 2], dp[i] + abs(h[i] - h[i + 2]));
  }

  cout << dp[n - 1] << '\n';
  return 0;
}


Measured memory_bytes: 3980
#include <stdio.h>

int main(void)
{
	int h, n, t;
	int i;
	int s = 0;

	scanf("%d %d", &h, &n);

	for (i = 0; i < n; i++)
	{
		scanf("%d", &t);
		s += t;
	}

	printf("%s\n", s >= h ? "Yes" : "No");

	return 0;
}


Measured memory_bytes: 128
#include <iostream>
#include <cstdio>
#include <vector>
#include <queue>
#include <string>
#include <cmath>
#include <algorithm>

using namespace std;

#define pb push_back
#define mp make_pair
#define ff first
#define ss second

typedef long long ll;
typedef vector<ll> vi;
typedef vector<vi> vvi;
typedef pair<ll, ll> pii;
typedef vector<pii> vii;
typedef priority_queue<ll> pq;

const int MOD = 1e9+7;
const int INF = 2e9;
const int MAX_N = 200000;
const int MAX_M = 200000;

int N, ans;
vi a;

int main() {
  cin >> N;
  for (int i = 0; i < N; i++) {
    int tmp; cin >> tmp;
    a.pb(tmp);
  }
  sort(a.begin(), a.end());
  int mx = -1;
  for (int i = 0; i < N-1; i++) {
    int tmp = min(a[i], a[N-1]-a[i]);
    if (tmp > mx) {
      ans = a[i];
      mx = tmp;
    }
  }
  cout << a[N-1] << " " << ans << endl;
  return 0;
}

Measured memory_bytes: 1400
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);

		final int r = sc.nextInt();
		final int d = sc.nextInt();
		final int x = sc.nextInt();

		sc.close();

		int prevx = x;
		for (int i = 1; i < 11; i++) {
			int result = r * prevx - d;
			System.out.println(result);
			prevx = result;
		}

	}

}

Measured memory_bytes: 21716
#include<stdio.h>

int map[10][10];
int main(){
  int x,y,size,count,max;

  count=100;
  max=0;
  while(scanf("%d,%d,%d",&x,&y,&size)!=EOF){
    if(size>=1){
      if(map[y][x]==0) count--;
      map[y][x]++;
      if(max<map[y][x]) max=map[y][x];
      if(y+1<10){
	if(map[y+1][x]==0) count--;
	map[y+1][x]++;
	if(max<map[y+1][x]) max=map[y+1][x];
      }
      if(y-1>-1){
	if(map[y-1][x]==0) count--;
	map[y-1][x]++;
	if(max<map[y-1][x]) max=map[y-1][x];
      }
      if(x+1<10){
	if(map[y][x+1]==0) count--;
	map[y][x+1]++;
	if(max<map[y][x+1]) max=map[y][x+1];
      }
      if(x-1>-1){
	if(map[y][x-1]==0) count--;
	map[y][x-1]++;
	if(max<map[y][x-1]) max=map[y][x-1];
      }
    }
    if(size>=2){
      if(y+1<10&&x+1<10){
	if(map[y+1][x+1]==0) count--;
	map[y+1][x+1]++;
	if(max<map[y+1][x+1]) max=map[y+1][x+1];
      }
      if(y-1>-1&&x+1<10){
	if(map[y-1][x+1]==0) count--;
	map[y-1][x+1]++;
	if(max<map[y-1][x+1]) max=map[y-1][1+x];
      }
      if(y+1<10&&x-1>-1){
	if(map[y+1][x-1]==0) count--;
	map[y+1][x-1]++;
	if(max<map[y+1][x-1]) max=map[y+1][x-1];
      }
      if(y-1>-1&&x-1>-1){
	if(map[y-1][x-1]==0) count--;
	map[y-1][x-1]++;
	if(max<map[y-1][x-1]) max=map[y-1][x-1];
      }
    }
    if(size==3){
      if(y+2<10){
	if(map[y+2][x]==0) count--;
	map[y+2][x]++;
	if(max<map[y+2][x]) max=map[y+2][x];
      }
      if(y-2>-1){
	if(map[y-2][x]==0) count--;
	map[y-2][x]++;
	if(max<map[y-2][x]) max=map[y-2][x];
      }
      if(x+2<10){
	if(map[y][x+2]==0) count--;
	map[y][x+2]++;
	if(max<map[y][x+2]) max=map[y][x+2];
	
      }
      if(x-2>-1){
	if(map[y][x-2]==0) count--;
	map[y][x-2]++;
	if(max<map[y][x-2]) max=map[y][x-2];
      }
    }
  }
  printf("%d\n%d\n",count,max);
  return 0;
}

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

long long  N, a[100000] = {},x;

int main() {
	cin >> N >> x;
	for (long long i = 0; i < N; i++) {
		cin >> a[i];
	}

	long long ans = 0;

	for (long long i = 0; i < N; i++) {
		if (i==0 && a[i] > x) {
			ans += (a[i] - x);
			a[i] = x;
		}

		else if((a[i-1]+a[i])>x) {
			long long tmp=(a[i - 1] + a[i]) - x;
			ans += tmp;
			a[i] -= tmp;
		}
	}
	cout << ans << endl;
	

}

Measured memory_bytes: 1024
package main

import (
	"fmt"
	"math"
)

func main() {
	var n int
	var intArray []int

	fmt.Scanf("%d", &n)
	intArray = make([]int, n)

	l := 0
	r := 0

	for i := 0; i < n; i++ {
		fmt.Scanf("%d", &intArray[i])
		r += intArray[i]
	}
	// sort.Ints(intArray)

	lastRes := 100000000000000000
	res := 0
	t := 1
	for _, v := range intArray {
		l += v
		r -= v
		res = int(math.Abs(float64(l) - float64(r)))

		// fmt.Printf("%d %d : %d : %d %d\n", l, r, t, res, lastRes)

		if lastRes < res {
			res = lastRes
			break
		}
		t++
		lastRes = res
	}

	fmt.Print(res)
}


Measured memory_bytes: 512
import java.util.*;
import java.lang.*;
public class Main {
        public static void main (String[]args){
            Scanner scanner = new Scanner(System.in);
            String input = scanner.next();
            boolean path=false;
            for (int i=0;i<input.length()-1;i++){
                if(input.charAt(i)!=input.charAt(i+1)){
                    path=true;
                    break;
                }
            }
            System.out.println(path ? "Yes":"No");
    }
}





Measured memory_bytes: 22100
# -*- coding: utf-8 -*-
import bisect
import heapq
import math
import random
import sys
from collections import Counter, defaultdict, deque
from decimal import ROUND_CEILING, ROUND_HALF_UP, Decimal
from functools import lru_cache, reduce
from itertools import combinations, combinations_with_replacement, product, permutations
from operator import add, mul, sub

sys.setrecursionlimit(100000)
input = sys.stdin.readline
INF = 2**62-1

def read_int():
    return int(input())


def read_int_n():
    return list(map(int, input().split()))


def read_float():
    return float(input())


def read_float_n():
    return list(map(float, input().split()))


def read_str():
    return input().strip()


def read_str_n():
    return list(map(str, input().split()))


def error_print(*args):
    print(*args, file=sys.stderr)


def mt(f):
    import time

    def wrap(*args, **kwargs):
        s = time.time()
        ret = f(*args, **kwargs)
        e = time.time()

        error_print(e - s, 'sec')
        return ret

    return wrap


@mt
def slv(N, A):
    ans = 0
    sa = [0]
    
    for a in A:
        sa.append(sa[-1]+a)
    
    ans = INF
    for i in range(1, N):
        l = sa[i] - sa[0]
        r = sa[-1] - sa[i]
        ans = min(ans, abs(r-l))
    return ans


def main():
    N = read_int()
    A = read_int_n()
    print(slv(N, A))


if __name__ == '__main__':
    main()


Measured memory_bytes: 27516
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <bits/stdc++.h>
using namespace std;
using namespace __gnu_pbds;

// types - only for stuff used a lot 
using ll = long long;
using pll = pair<ll,ll>;
using ordered_set = tree<
	pll,
	null_type,
	less<pll>,
	rb_tree_tag,
	tree_order_statistics_node_update>;
// insert, find_by_order, and order_of_key
#define vv vector
#define Pp pair

// IO
#define get(x) scanf("%d",&x)
#define getl(x) scanf("%lld",&x);

// Operations
#define pb push_back
#define pob pop_back
#define sz(a) int(a.size()) 
#define re(a,b) a=max(a,b) // relax
#define ri(a,b) a=min(a,b) // relaxi

// Debugging

#ifndef LOCAL
#define cerr if (0) cerr
#else
#define cerr cout
#endif

#define print(arr,n) {for (int _ = 0; _ < n; _++) cerr<<arr[_]<<" "; cerr << endl; }
#define printv(vec)  {for (int _ : vec) cerr<<_<<" "; cerr<<endl;}

const int mod = 1e9+7, oo = 1e9;
const ll loo = 1e18;

// Functions 
ll modpow(ll a, ll b) {
	ll ans = 1; // faster modpow than recursive
	for (; b; b/=2,a=a*a%mod)
		if (b&1) ans = (ans*a)%mod;
	return ans;
}
ll gcd(ll a, ll b) {
	while (a) b%=a,swap(a,b);
	return b;
}
#define bitcount __builtin_popcountll
#define f(i,a,b) for (int i = a; i < b; i++)
#define fr(i,a,b) for (int i = b-1; i >= a; i--)


/* 

   ALRIGHT HACKERS, THIS IS WHERE THE ACTUAL CODE BEGINS
   Time to get demoted :)

 */

const bool DEBUG = 1;
using vi = vector<int>;

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
#ifdef LOCAL
	if (DEBUG) freopen("input.txt", "r", stdin);
	if (DEBUG) freopen("output.txt", "w", stdout);
	clock_t start = clock();
#endif
	
  	int N,Q; cin>>N>>Q;
  	int val[N];
  	fill(val,val+N,0);
  	vi adj[N];
  	f(i,0,N-1) {
		int a,b; cin>>a>>b;
      	adj[--a].pb(--b);
      	adj[b].pb(a);
    }
  	f(q,0,Q) {
    	int v,x; cin>>v>>x;
      	val[--v] += x;
    }
  	function<void(int,int)> dfs = [&](int v, int p) {
      	if (p != -1) val[v] += val[p];
      	for (int w : adj[v]) if (w != p)
        	dfs(w,v);
    };
  	dfs(0,-1);
  	f(i,0,N) cout << val[i] << " \n"[i == N-1];

#ifdef LOCAL
	cout << setprecision(12) << (long double)(clock()-start) / CLOCKS_PER_SEC << endl;
#endif
	return 0;
}

Measured memory_bytes: 26624
#include <stdio.h>

int main(void) {
    int N;
    scanf("%d", &N);
    int A[200000] = { 0 };
    for (int i = 0; i < N - 1; i++) {
        int a = 0;
        scanf("%d", &a);
        A[a - 1] += 1;
    }

    for (int i = 0; i < N; i++) {
        printf("%d\n", A[i]);
    }

    return 0;
}

Measured memory_bytes: 2932
#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> ;
//#define all(v) v.begin(),v.end()
//ll mod = 998244353 ;
//long double pie = acos(-1) ;
//ll INF = 1000000000000 ;

//void yorn(bool a){if(a) cout << "Yes" << endl ; else cout << "No" << endl ;}
//void YorN(bool a){if(a) cout << "YES" << endl ; else cout << "NO" << endl ;}
//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 fix_cout(){cout << fixed << setprecision(20) ;}
//ld dis(ll a,ll b,ll c,ll d){return sqrt((a-c)*(a-c)+(b-d)*(b-d)) ;}

int main(){
	ll n ; cin >> n ;
	ll k = 1 ;
	while(k*(k-1)<2*n) k++ ;
	if(k*(k-1)!=2*n) cout << "No" << endl ;
	else{
		cout << "Yes" << endl ;
		vvll a(k,vll(0)) ;
		ll num = 0 ;
		for(int i=0;i<k;i++){
			for(int j=0;j<k-1-i;j++){
				num++ ;
				a.at(i).emplace_back(num) ;
			}
		}
		num = 0 ;
		for(int i=0;i<k-1;i++){
			for(int j=1+i;j<k;j++){
				num++ ;
				a.at(j).emplace_back(num) ;
			}
		}
		cout << k << endl ;
		for(int i=0;i<k;i++){
			cout << k-1 << " " ;
			for(int j=0;j<k-1;j++) cout << a.at(i).at(j) << (j==k-2?'\n':' ') ;
		}
	}
}


Measured memory_bytes: 3200
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double lb;
#define REP(i,j,n) for (int i=j;i<(n);i++)
#define RREP(i,n) for (int i = n; 0<i;i--)
#define print(out) cout<< out  << "\n";
#define mod 1000000007
const int INF = 1e9;
int N;string s;
set<string> a;
void dfs(string now,int j){
  if(now.length()>=N){
    a.insert(now);
    return;
  }
  REP(k,97,j+2){
    string now_=now+(char) k;
    dfs(now_,max(j,k));
  }
}

int main(){
  cin>>N;
  dfs("a",97);
  for(auto s_:a){
    print(s_);
  }
}


Measured memory_bytes: 12416
using System;
using System.Collections.Generic;
using System.Linq;

namespace ProgramingStudying2
{
    class Program
    {

        static void Main(string[] args)
        {
            var xa = Console.ReadLine().Split();
            var x = int.Parse(xa[0]);
            var a = int.Parse(xa[1]);

            Console.WriteLine(x < a ? 0 : 10);
        }
    }
}


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

bool sugar[3001], water[3001];
vector<int> S, W;

int main() {
  int A, B, C, D, E, F;
  cin >> A >> B >> C >> D >> E >> F;
  for (int i = 0; i*C <= F; ++i) {
    for (int j = 0; i*C+j*D <= F; ++j) {
      sugar[i*C+j*D] = true;
    }
  }
  for (int i = 0; 100*i*A <= F; ++i) {
    for (int j = 0; 100*j*B + 100*i*A <= F; ++j) {
      water[100*i*A+100*j*B] = true;
    }
  }
  for (int i = 0; i <= F; ++i) {
    if (sugar[i]) S.push_back(i);
    if (water[i]) W.push_back(i);
  }
  double max = -0.1;
  int s, w;
  for (int i = 0, slen = S.size(); i < slen; ++i) {
    for (int j = 0, wlen = W.size(); j < wlen; ++j) {
      if (S[i] + W[j] == 0) continue;
      if (S[i] + W[j] <= F && (double)W[j] / 100.0 * (double)E >= (double)S[i] && (double)(S[i]*100.0) / (double)(S[i]+W[j]) > max) {
        max = (double)(S[i]*100.0) / (double)(S[i]+W[j]);
        s = S[i]; w = W[j];
      }
    }
  }
  cout << w+s << " " << s << endl;
  return 0;
}


Measured memory_bytes: 256
h,w=map(int,input().split())
l=[]
for i in range(h):
  l.append(input())
l.insert(0,"#"*(w+2))
l.append("#"*(w+2))
for i in range(1,h+1):
  l[i]="#"+l[i]+"#"
for i in range(h+2):
  print(l[i])

Measured memory_bytes: 3060
#input of int(split by space)
def get_i()
  return gets.chomp.split(" ").map(&:to_i)
end
#input of float(split by space)
def get_f()
  return gets.chomp.split(" ").map(&:to_f)
end
#input of string(split by space)
def get()
  return gets.chomp.split(" ")
end
#input of string(split per one character)
def get_nsp()
  return gets.chomp.split("")
end
#yes or no decision
def yn_judge(bool,y="Yes",n="No")
  return bool ? y : n 
end
#create of array
def array(size1,init=nil,size2=-1)
  if size2==-1
      return Array.new(size1){init}
  else
      return Array.new(size2){Array.new(size1){init}}
  end
end

def max(a,b)
    return a>b ? a : b
end

def min(a,b)
    return a>b ? b : a
end

INF=Float::INFINITY

N=gets.to_i
a=array(N)
kind_a=Hash.new(0)
N.times do|i|
    a[i]=gets.to_i
    kind_a[a[i]]=1
end
ch_a=Hash.new(-1)
kind_a.sort.each_with_index do|arr,i|
    ch_a[arr[0]]=i
end
res=0
N.times do|i|
    a[i]=ch_a[a[i]]
    res+=1 unless (i.odd? and a[i].odd?) or (i.even? and a[i].even?)
end
puts res/2

Measured memory_bytes: 30208
#include<iostream>
#include<vector>
#include<string>
#include<map>
#include<cstdio>
#include<algorithm>
using namespace std;

int main() {
	int a;
	while (scanf("%d", &a), a) {
		map<string, int>b;
		for (int c = 0; c < a; c++) {
			string d; int e;
			cin >> d;
			scanf("%d", &e);
			b[d] = e;
		}
		int f;
		scanf("%d", &f);
		map<string, vector<string>>h;
		for (int g = 0; g < f; g++) {
			string i; int j;
			cin >> i;
			scanf("%d", &j);
			vector<string>k(j);
			for (int l = 0; l < j; l++)cin >> k[l];
			h[i] = k;
		}
		for (int x = 0; x < a; x++) {
			bool y = false;
			for (auto z = h.begin(); z != h.end(); z++) {
				int q = 0;
				for (int p = 0; p < z->second.size(); p++) {
					q += b[z->second[p]];
				}
				if (q < b[z->first]) {
					y = true;
					b[z->first] = q;
				}
			}
			if (!y)break;
		}
		string s;
		cin >> s;
		cout << b[s] << endl;
	}
}

Measured memory_bytes: 3232
cards_map = {}
cards_map['A'] = list(input().upper())
cards_map['B'] = list(input().upper())
cards_map['C'] = list(input().upper())
current = 'A'
while True:
    if len(cards_map[current]) == 0:
        break
    else:
        current = cards_map[current].pop(0)
print(current)

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

using namespace std;

int A[10005];

int main() {

	// freopen("input.txt", "r", stdin);
	// freopen("output.txt", "w", stdout);

	long long n, m;
	cin >> n >> m;
	long long total = 0;
	for (int i = 0; i < m; ++i) {
		cin >> A[i];
		total += A[i];
	}
	total = n - total;
	if (total >= 0) cout << total << '\n';
	else cout << -1 << '\n';
	return 0;
}

Measured memory_bytes: 3636
#include<bits/stdc++.h>
using namespace std;
#define dd double
#define pb push_back
#define pf push_front
#define popb pop_back
#define popf pop_front
#define ll long long
#define ull unsigned long long
#define ld long double
#define mx 200005
#define mod 1000000007
#define fr first
#define cti(a) (a-48)
#define itc(a) char(a+48)
#define se second
#define End cout<<"\n"
#define fast ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define memo(Array,val) memset(Array, val, sizeof Array)
#define PI acos(-1)
bool check(ll n, ll pos){ return (n&(1<<pos)); }
bool Set(ll n, ll pos) {  return (n | (1<<pos)); }
ld LOG(ld b, ld e){ return log(b)/log(e); }

bool func(string s1)
{
    int l=0, r = s1.size()-1;
    while(l<r){
        if(s1[r] != s1[l]) return 0;
        l++,r--;
    }
    return 1;
}

void solve()
{
    string s1;
    cin >> s1;
    if(s1.size()&1 == 0 || !func(s1)) cout << "No\n";
    else{

        int mid = (s1.size()+1)/2;
        string st1="", st2="";
        int l=0,r = mid+1;
        while(l<mid-1){
            st1+=s1[l], ++l;
        }
        l = mid;
        while(l<s1.size()){
            st2+=s1[l], ++l;
        }
        st1 == st2 ? cout << "Yes\n" : cout << "No\n";

    }

}

int main()
{
    fast;
	int t;
	t=1;
	while(t--) solve();
	return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
main(){
  int a[6]={0},n,i,j;
  double b;
  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%lf",&b);
    if(b<165.0)a[0]++;
    else if(b<170.0)a[1]++;
    else if(b<175.0)a[2]++;
    else if(b<180.0)a[3]++;
    else if(b<185.0)a[4]++;
    else a[5]++;
  }

  for(i=0;i<6;i++){
    printf("%d:",i+1);
    for(j=0;j<a[i];j++){
      printf("*");
    }
    printf("\n");
  }
  return 0;
}

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

using ll = long long;

int main() {
    int n;
    while(cin >> n, n != -1) {
        string res;
        while(n > 0) {
            res += '0' + (n % 4);
            n /= 4;
        }
        reverse(res.begin(), res.end());
        if(res.size() == 0) {
            res += '0';
        }
        cout << res << endl;
    }
}

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;
typedef pair<ll,ll> l_l;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
typedef pair<l_l,ll> lll;
typedef vector<string> vs;
const ll dx[4]={1,-1,0,0};
const ll dy[4]={0,0,1,-1};
#define pb push_back
#define sz(x) (int)(x).size()
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
const int INF=1001001000;
const int mINF=-1001001000;
const ll LINF=1010010010010010000;
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;
}
//グリッド：（典型）dp,dfs,bfs,最短経路,その他
int main(){
    ll n;cin>>n;
    vl a(n),b(n);
    rep(i,n)cin>>a[i]>>b[i];
    sort(a.begin(),a.end());
    sort(b.begin(),b.end());
    if(n%2==0){
        ll x1=abs(a[n/2-1]-b[n/2-1])+1;
        ll x2=abs(a[n/2]-b[n/2])+1;
        //cout<<x1<<" "<<x2<<endl;
        cout<<x1+x2-1<<endl;
    }
    else{
        ll x=abs(a[(n+1)/2-1]-b[(n+1)/2-1])+1;
        cout<<x<<endl;
    }
    return 0;
}

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


struct node{
  struct node* right;
  struct node* left;
  struct node* p;
  int key;
};

typedef struct node *Node;

Node root;

void insert(int  k){
  Node y = NULL;
  Node x = root;
  Node z;

  z = (Node)malloc(sizeof(struct node));
  z->key = k;
  z->left = NULL;
  z->right = NULL;
  
  while(x != NULL){
    y = x;
    if(z->key < x->key) x = x->left;
    else x = x->right;
  }
  
    z->p = y;

    if(y == NULL) root = z;
    else if(z->key < y->key) y->left = z;
    else y->right = z;
}

void inorder(Node u){
  if(u != NULL){
    inorder(u->left);
    printf(" %d",u->key);
    inorder(u->right);
  }
}

void preorder(Node u){
  if(u != NULL){
    printf(" %d",u->key);
    preorder(u->left);
    preorder(u->right);
  }
}

int find(Node u, int k){
  while(u != NULL){
    if(k == u->key) return 1;
    else if(k < u->key) u = u->left;
    else u = u->right;
  }

  return 0;
}
int main(){
  int n,i,k;
  char com[10];
  
  scanf("%d",&n);
  
  for(i=0;i<n;i++){
    scanf("%s",com);
    
    if(com[0] == 'i'){
      scanf("%d",&k);
      insert(k);
    }
    else if(com[0] == 'p'){
      inorder(root);
      printf("\n");
      preorder(root);
      printf("\n");
    }
  
    else{
      scanf("%d",&k);
      if(find(root,k)) printf("yes\n");
      else printf("no\n");
    }
  }
  
  return 0;
}



Measured memory_bytes: 20556
N,L=(int(x) for x in input().split())
aji=[]
aji_abs=[]
for n in range(N):
    a=L+n
    aji.append(a)
    aji_abs.append(abs(a))
ba=aji_abs.index(min(aji_abs))
wa=0
for n in range(N):
    wa=wa+aji[n]
print(wa-aji[ba])


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

int main() {
	string s1,s2;
	cin>>s1>>s2;
	int a,b;
	cin>>a>>b;
	string s;
	cin>>s;
	if(s==s1)a--;
	else if(s==s2)b--;
	cout<<a<<" "<<b<<endl;
	return 0;
}


Measured memory_bytes: 256
/* package codechef; // don't place package name! */

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

/* Name of the class has to be "Main" only if the class is public. */
public class Main
{
	public static void main (String[] args) throws java.lang.Exception
	{
		Scanner s=new Scanner(System.in);
		String c=s.next();
		switch(c)
		{case "MON":
		System.out.println("6");
		break;
		case "TUE":
		System.out.println("5");
		break;
		case "WED":
		System.out.println("4");
		break;
		case "THU":
		System.out.println("3");
		break;
		case "FRI":
		System.out.println("2");
		break;
		case "SAT":
		System.out.println("1");
		break;
		default:
		System.out.println("7");}}}

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

int main() {
	int n, x; cin >> n >> x;
	vector<int>m(n); for (auto&& i : m)cin >> i;

	int ans = 0;
	for (int i = 0; i < m.size(); i++) {
		x -= m[i]; ans++;
	}
	sort(m.begin(), m.end());
	ans += (x / m[0]);
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 3620
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <climits>
#include <random>
#include <iomanip>

using namespace std;
using P = pair<long, long>;

typedef long long int ll;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))

#define fillInt(xs, x)        \
  for (int i = 0; i < (x); i++) \
    scanf("%d", &xs[i]);
#define fillLong(xs, x)       \
  for (int i = 0; i < (x); i++) \
    scanf("%ld", &xs[i]);
#define fillString(xs, x)       \
  for (int i = 0; i < (x); i++) \
    cin >> xs[i];
#define sortv(xs) sort(xs.begin(), xs.end())
#define sortvinv(xs) sort(xs.begin(), xs.end(), std::greater<long>())
#define lbv(xs, x) lower_bound(xs.begin(), xs.end(), x) - xs.begin()
#define ubv(xs, x) upper_bound(xs.begin(), xs.end(), x) - xs.begin()
#define bs(xs, x) binary_search(xs.begin(), xs.end(), x)
#define index_of(as, x) \
  distance(as.begin(), lower_bound(as.begin(), as.end(), x))

#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define concat(xs, ys) (xs).insert((xs).end(), (ys).begin(), (ys).end())

const int mod = 1000000007;

struct mint {
    ll x;
    mint(ll x=0):x(x%mod){}

    mint& operator+=(const mint a) {
        if((x += a.x) >= mod) x -= mod;
        return *this;
    }

    mint& operator-=(const mint a) {
        if((x -= mod-a.x) >= mod) x -= mod;
        return *this;
    }

    mint& operator*=(const mint a) {
        x = (x * a.x) % mod;
        return *this;
    }

    mint& operator/=(const mint a) {
        *this *= a.inv();
        return *this;
    }

    mint operator+(const mint a) const {
        mint res(*this);
        return res += a;
    }

    mint operator-(const mint a) const {
        mint res(*this);
        return res -= a;
    }

    mint operator*(const mint a) const {
        mint res(*this);
        return res *= a;
    }

    mint operator/(const mint a) const {
        mint res(*this);
        return res /= a;
    }

    mint pow(ll n) const {
        mint a(*this);
        mint res = 1;
        while (n > 0) {
            if (n & 1) res *= a;
            a *= a;
            n >>= 1;
        }
        return res;
    }

    mint inv() const {
        return pow(mod - 2);
    }
};

mint dp[100005][4];

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

  string s;
  cin >> s;

  dp[0][0] = 1;
  dp[0][1] = 0;
  dp[0][2] = 0;
  dp[0][3] = 0;

  rep(i, s.length()) {
    rep(j, 4) {
      dp[i+1][j] = dp[i][j];
    }
    if (s[i] == 'A') {
      dp[i+1][1]+=dp[i][0];;
    } else if (s[i] == 'B') {
      dp[i+1][2]+=dp[i][1];
    } else if (s[i] == 'C') {
      dp[i+1][3]+=dp[i][2];
    } else {
      dp[i+1][0]=dp[i][0]*3;
      dp[i+1][1]=dp[i][1]*3 + dp[i][0];
      dp[i+1][2]=dp[i][2]*3 + dp[i][1];
      dp[i+1][3]=dp[i][3]*3 + dp[i][2];
    }
  }

  cout << dp[s.length()][3].x << endl;
}

Measured memory_bytes: 3712
import os
import sys
from atexit import register
from io import BytesIO
sys.stdin = BytesIO(os.read(0, os.fstat(0).st_size))
sys.stdout = BytesIO()
register(lambda: os.write(1, sys.stdout.getvalue()))
input = lambda: sys.stdin.readline().rstrip('\r\n')
raw_input = lambda: sys.stdin.readline().rstrip('\r\n')

x,k,d = [abs(int(x)) for x in input().split()]

if x >= k*d:
    ans = x - k*d
else:
    moves = x // d
    if k % 2 == moves % 2:
        ans = x - moves*d
    else:
        ans = abs(x - (moves+1)*d)
print(ans)

Measured memory_bytes: 65004
/* Atcoder abc149b
 * See tasks at: https://atcoder.jp/contests/abc149/tasks/abc149_b
 */
#include <iostream>
#include <vector>
#include <algorithm>

#define until(symbol, max) for (int symbol = 0; (symbol) < (max); (symbol)++)

using namespace std;
using ll = uint64_t;
int main()
{
    ll a, b, k;
    cin >> a >> b >> k;
    
    if (a > k)
    {
        cout << a - k;
    }
    else
    {
        cout << 0;
    }

    cout << " ";
    
    if (k > a)
    {
        if (b > (k - a))
        {
            cout << (b - (k - a));
        }
        else
        {
            cout << 0;
        }
    }
    else
    {
        cout << b;
    }
    
    return 0;
}


Measured memory_bytes: 256
import java.util.*;

public class Main {

  public static void main(String[] args) {

    Scanner sc = new Scanner(System.in);
    int k = sc.nextInt();

    if (k%2 == 0) {
      System.out.println((k/2) * (k/2));
    } else {
      System.out.println((k/2+1) * (k/2));
    }

  }
}


Measured memory_bytes: 22612