akhauriyash/Code-Regression huggingface dataset:
#include "bits/stdc++.h"
#define rep(i,b) for(ll i=0;i<b;i++)
#define ll long long
using namespace std;
/*--Input//////////////////////////////////////////////////*/
inline void IN(void){return;}
template <typename First, typename... Rest>
void IN(First& first, Rest&... rest){
    cin >> first;
    IN(rest...);
    return;
}
#define SS(T, ...)      T __VA_ARGS__; IN(__VA_ARGS__);
#define SV(type,c,n) vector<type> c(n);for(auto& i:c)cin >> i;
/*--Output/////////////////////////////////////////////////*/
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
inline int p(void){cout << endl; return 0;}
template<class Head> int p(Head&& head){cout << head;p();return 0;} template<class Head,class... Tail> int p(Head&& head,Tail&&... tail){cout<<head<<" ";p(forward<Tail>(tail)...);return 0;}
struct ProconInit {
    static constexpr int IOS_PREC = 15;
    static constexpr bool AUTOFLUSH = false;

    ProconInit() {
        cin.tie(nullptr);
        ios::sync_with_stdio(false);
        cout << fixed << setprecision(IOS_PREC);
        if(AUTOFLUSH)
            cout << unitbuf;
    }
} PROCON_INIT;


#define vl vector<ll>
#define vvl vector<vector<ll>>
#define vvvl vector<vector<vector<ll>>>
#define debug(x) cerr<<#x<<" "<<x<<'\n';
#define all(x) (x).begin(),(x).end()
#define bit(n) (1LL<<(n))

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

const int MOD = 1000000007;

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

int main(){
    int N;
    cin>>N;
    vector<vector<int>> G(N);
    vector<pair<int,int>> vp;
    rep(i,N-1){
        SS(int,a,b)
        a--;b--;
        G[a].emplace_back(b);
        G[b].emplace_back(a);
        vp.emplace_back(a,b);
    }

    int K=0;
    map<pair<int,int>,int> I;
    vector<int> cs(N,0); // color of edge between its parent

    vector<int> used(N,0);
    queue<int> que;
    used[0]=1;
    que.emplace(0);
    while(!que.empty()){ //幅優先
        int v=que.front();que.pop();
        if(K<G[v].size()) K=G[v].size();
        int cur=1;
        for(int u:G[v]){
            if(used[u]) continue;
            if(cur==cs[v]) cur++;
            cs[u]=I[{u,v}]=I[{v,u}]=cur++;
            used[u]=1;
            que.emplace(u);
        }
    }

    p(K);
    for(auto v:vp) p(I[v]);
    return 0;
}

Measured memory_bytes: 20088
#include <iostream>
#include <vector>
#include <cmath>
using namespace std;
#define REP(i, n) for(int i = 0; i < n; i++)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define ALL(x) (x).begin(),(x).end() //sortなどの引数を省略したい
#define SIZE(x) ((ll)(x).size()) //sizeをsize_tからllに直しておく
#define MAX(x) *max_element(ALL(x)) //最大値を求める
#define MIN(x) *min_element(ALL(x)) //最小値を求める
typedef long long ll;

int main(){
    int n;
    cin >>n;
    bool is_1 = false;
    int a, num=1, count=0;
    REP(i,n){
        cin >>a;
        if(a==num){
            num++;
        }else{
            count++;
        }
    }
    int ans;
    if(count==n){
        ans=-1;
    }else{
        ans=count;
    }

    cout<<ans;

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <set>
using namespace std;
int main(){
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int n;
  cin >> n;
  int i;
  string a;
  set < string > s;
  for(i=0;i<n;i++){
    cin >> a;
    s.insert(a);
  }
  cout << s.size() << endl;
  return 0;
}

Measured memory_bytes: 19232
#include <bits/stdc++.h>
#define FOR(i, n, m) for(ll i = n; i < (int)m; i++)
#define REP(i, n) FOR(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define pb push_back
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
constexpr ll inf = 1000000000;
constexpr ll mod = 998244353;
constexpr long double eps = 1e-15;

template <typename T>
struct segment_tree {
private:
    int n;
    const function<T(T, T)> op;
    const T ie;
    vector<T> seq;
    
public:
    segment_tree(int _n, function<T(T, T)> op, const T ie) : op(op), ie(ie) {
        n = 1;
        while(n < _n) n *= 2;
        seq.resize(2 * n - 1);
        for(int i = 0; i < 2 * n - 1; i++) seq[i] = ie;
    }
    void update(int k, const T e) {
        k += n - 1;
        seq[k] = e;
        while(k > 0) {
            k = (k - 1) / 2;
            seq[k] = op(seq[k * 2 + 1], seq[k * 2 + 2]);
        }
    }
    T get(int k) {
        k += n - 1;
        return seq[k];
    }
    T query(int a, int b, int k = 0, int l = 0, int r = -1) {
        if(r == -1) r = n;
        if(r <= a || b <= l) return ie;
        if(a <= l && r <= b) return seq[k];
        T vl = query(a, b, k * 2 + 1, l, (l + r) / 2);
        T vr = query(a, b, k * 2 + 2, (l + r) / 2, r);
        return op(vl, vr);
    }
};

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    vector<string> w(n);
    REP(i, n)cin >> w[i];
    map<string, int> m;
    priority_queue<pair<int, string>, vector<pair<int, string>>, greater<pair<int, string>>> q;
    REP(i, n) FOR(j, i + 1, n) {
        bool ok = true;
        string s = w[i], t = w[j];
        if((int)s.size() > (int)t.size()) swap(s, t);
        REP(k, s.size()) {
            if(s[k] != t[k]) ok = false;
        }
        if(!ok) continue;
        int ncost = (int)t.size();
        string nstr = t.substr((int)s.size(), (int)t.size() - (int)s.size());
        if(!m.count(nstr) || m[nstr] > ncost) {
            m[nstr] = ncost;
            q.push({ncost, nstr});
        }
    }
    int ans = inf;
    while(!q.empty()) {
        int cost = q.top().first;
        string str = q.top().second;
        q.pop();
        if(m[str] != cost) continue;
        REP(i, n) {
            if(str == w[i]) {
                ans = min(ans, cost);
                continue;
            }
            bool ok = true;
            string s = w[i], t = str;
            if((int)s.size() > (int)t.size()) swap(s, t);
            REP(k, s.size()) {
                if(s[k] != t[k]) ok = false;
            }
            if(!ok) continue;
            int ncost = cost;
            if((int)w[i].size() > (int)str.size()) ncost += (int)w[i].size() - (int)str.size();
            string nstr = t.substr((int)s.size(), (int)t.size() - (int)s.size());
            if(!m.count(nstr) || m[nstr] > ncost) {
                m[nstr] = ncost;
                q.push({ncost, nstr});
            }
        }
    }
    if(ans == inf) cout << 0 << endl;
    else cout << ans << endl;
    return 0;
}



Measured memory_bytes: 3448
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

int main(){
  vector<int> h(10);
  for(int i=0;i<10;++i)
	cin >> h[i];
  sort(h.begin(), h.end());
  for(int i=0;i<3;++i)
	cout << h[9-i] << endl;
  return 0;
}

Measured memory_bytes: 1212
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Collections;

public class Main {
	public static void main(String[] args) throws IOException {
		BufferedReader input = new BufferedReader(new InputStreamReader(System.in));

		String[] inputArray = input.readLine().split(" ");
		ArrayList<Integer> inputList = new ArrayList<>();
		for (String each : inputArray) {
			inputList.add(Integer.parseInt(each));
		}
		Collections.sort(inputList);
		Collections.reverse(inputList);
		System.out.println(inputList.get(0) + " " + inputList.get(1) + " " + inputList.get(2) + " "
				+ inputList.get(3) + " " + inputList.get(4));
	}
}

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

using namespace std;
//FILE *fi=freopen("1.txt","r",stdin);
string s;
int status;
deque <char> q;
int main()
{
    cin>>s;
    for(auto c:s)
    {
        q.push_back(c);
    }
    int m;
    cin>>m;
    while(m--)
    {
        int t;
        cin>>t;
        if(t==1)
        {
            status=!status;
        }
        else
        {
            int a;
            char x;
            cin>>a>>x;
            a--;
            if(a==status)
                q.push_front(x);
            else
                q.push_back(x);
        }
    }
    string ans="";
    while(!q.empty())
    {
        ans.push_back(q.front());
        q.pop_front();
    }
    if(status)
        reverse(ans.begin(),ans.end());
    cout<<ans;
    return 0;
}


Measured memory_bytes: 1412
#include <stdio.h>

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

int count[9];

int solve(int used){
	int pos;
	int res;

	rep(pos,9) if(count[pos] != 0) break;
	if(pos == 9) return 1;

	if(count[pos] >= 3){
		count[pos] -= 3;
		res = solve(used);
		count[pos] += 3;
		if(res) return 1;
	}

	if(count[pos] >= 2 && !used){
		count[pos] -= 2;
		res = solve(1);
		count[pos] += 2;
		if(res) return 1;
	}

	if(pos <= 6 && count[pos] >= 1 && count[pos+1] >= 1 && count[pos+2] >= 1){
		count[pos]--; count[pos+1]--; count[pos+2]--;
		res = solve(used);
		count[pos]++; count[pos+1]++; count[pos+2]++;
		if(res) return 1;
	}

	return 0;
}

int main(void){
	int i,j,ansFlg,res;
	int ans[9],size;
	char s[14];

	while(scanf("%s",s) != EOF){
		rep(i,9) count[i] = 0;
		rep(i,13) count[s[i]-'1']++;

		ansFlg = 1;
		rep(i,9) if(count[i] >= 5) ansFlg = 0;

		if(!ansFlg){
			printf("0\n");
			continue;
		}

		size = 0;
		rep(i,9){
			if(count[i] == 4) continue;
			count[i]++;
			if(solve(0)) ans[size++] = i + 1;
			count[i]--;
		}

		if(size == 0) printf("0");
		rep(i,size){
			if(i != 0) printf(" ");
			printf("%d",ans[i]);
		}
		printf("\n");
	}

	return 0;
}

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

int main() {
  int K, N;
  int sum_dis = 0;
//  int ans = 0;
  cin >> K >> N;
  vector<int> vec(N);
  vector<int> distance(N);
  vector<int> min_dis(N);
  for(int i=0; i < N; i++){
    cin >> vec.at(i);
  }
  for(int i=0; i < N - 1; i++){
    distance.at(i) = vec.at(i + 1) - vec.at(i);
  }
  distance.at(N - 1) = vec.at(0) + K - vec.at(N-1);
  for(int i=0; i < N; i++){
    sum_dis += distance.at(i);
  }
  for(int i=0; i < N; i++){
    min_dis.at(i) = sum_dis - distance.at(i);
  }
  sort(min_dis.begin(), min_dis.end());
  cout << min_dis.at(0) << endl;
}

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

int main() {
  int H_1,M_1,H_2,M_2,K_2;
  cin >>H_1>>M_1>>H_2>>M_2>>K_2;
  int h=60*H_1+M_1;
  int m=60*H_2+M_2;
  int answer=m-h-K_2;
    cout<< answer <<endl;
}

Measured memory_bytes: 3636
N, M, X, Y = map(int, input().split())
xs = list(map(int, input().split()))
xs.append(X)
ys = list(map(int, input().split()))
ys.append(Y)
xmax = max(xs)
ymin=  min(ys)
if xmax<ymin:
    print("No War")
else:
    print("War")


Measured memory_bytes: 3060
function over(x){
   if(x>=10)x=x-10+1;
   return x;
}
var input = require('fs').readFileSync('/dev/stdin', 'utf8');
var arr=input.trim().split("\n");
var n=arr.shift()-0;
var id=arr.shift().split("");
id.reverse();
var a=arr.shift()-0;
var ary=arr.shift().split(" ").map(Number);
var k=[];
var sum=0;
id.forEach(function(v,i){
   if(v=="*"){
      if(i%2==0)k.push(1);
      else k.push(2);
   }else{
      if(i%2==0)sum+=v-0;
      else sum+=over((v-0)*2);
   }
});
var dp=[];
for(var i=0;i<=k.length;i++){
   dp[i]=[];
   for(var s=0;s<100;s++)dp[i][s]=0;
}

dp[0][0]=1;

for(var i=0;i<k.length;i++){
   for(var j=0;j<ary.length;j++){
      for(var s=0;s<100;s++){
         dp[i+1][s+over(ary[j]*k[i])]+=dp[i][s];
      }
   }
}
var ans=0;
for(var s=0;s<100;s++){
   if((sum+s)%10==0)ans+=dp[k.length][s];
}
console.log(ans);

Measured memory_bytes: 17716
#include<algorithm>//sort,二分探索,など
#include<bitset>//固定長bit集合
#include<cmath>//pow,logなど
#include<complex>//複素数
#include<deque>//両端アクセスのキュー
#include<functional>//sortのgreater
#include<iomanip>//setprecision(浮動小数点の出力の誤差)
#include<iostream>//入出力
#include<iterator>//集合演算(積集合,和集合,差集合など)
#include<map>//map(辞書)
#include<numeric>//iota(整数列の生成),gcdとlcm(c++17)
#include<queue>//キュー
#include<set>//集合
#include<stack>//スタック
#include<string>//文字列
#include<unordered_map>//イテレータあるけど順序保持しないmap
#include<unordered_set>//イテレータあるけど順序保持しないset
#include<utility>//pair
#include<vector>//可変長配列

// vectorの重複削除
// std::sort(test.begin(), test.end());
// test.erase(std::unique(test.begin(), test.end()), test.end());

using namespace std;
using ll = long long;
using P = pair<int, int>; // vector<P> ba(n); みたいな感じですぐ使える ba[i] = P(a, b); make_pairをしなくてもいい
// typedef vector<int> v;
template <class T>ostream &operator<<(ostream &o,const vector<T>&v){o<<"{";for(int i=0;i<(int)v.size();i++)o<<(i>0?", ":"")<<v[i];o<<"}";return o;}
#define debug(v) {cerr<<"\033[1;36m[debug]\033[m "<<#v<<" : "<<v<<endl;}
#define rep(i, c) for(int i = 0; i < int(c); i++)
#define ALL(x) (x).begin(), (x).end() //sort(ALL(obj))みたいな
#define SIZE(x) ((ll)(x).size()) //sizeをsize_tからllに直しておく
#define MAX(x) *max_element(ALL(x)) //最大値
#define pb push_back //
// const int MOD = 1000000007;
// string alpha="ABCDEFGHIJKLMNOPQRSTUVWXYZ";
// printf("%.20f\n", ans); あれ
// const double PI = 3.141592653589793238462643383;

int main() {
  int n,a; cin>>n>>a;
  cout << (n*3+a)/2 << endl;
}


Measured memory_bytes: 256
import qualified Data.Vector.Unboxed as U

main = do
    n <- getLine
    as <- U.fromList . map read. words <$> getLine :: IO (U.Vector Int)
    let left = U.scanl gcd 0 as
    let right = U.scanr gcd 0 as
    let res = U.zipWith gcd left (U.tail right)
    print $ U.maximum res

Measured memory_bytes: 36220
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<iostream>
#define LL long long
using namespace std;
const LL mod=1e9+7;
LL f[110][20010],n,k,tot;
LL Pow(LL a,LL b)
{
	LL ans=1;
	while(b)
	{
		if(b&1) ans=ans*a%mod;
		a=a*a%mod;b>>=1;
	}
	return ans;
}
int main()
{
	scanf("%lld %lld",&n,&k);
	tot=Pow(k+1,n-1)*n%mod*k%mod*(k+1)%mod*((mod+1)/2)%mod;
	f[k+1][0]=1;
	for(LL i=k+1;i>1;i--)
		for(LL j=0;j<=20000;j++) if(f[i][j])
			for(LL u=0;u<=k;u++)
			{
				if(u>i-1) (f[i-1][j]+=f[i][j])%=mod;
				else (f[i-1][j+(j+u)/(i-1)]+=f[i][j])%=mod;
			}
	for(LL i=1;i<=20000;i++)
		(tot-=f[1][i]*i%mod*Pow(k+1,n-k)%mod)%=mod;
	(tot+=mod)%=mod;
	printf("%lld",tot);
}

Measured memory_bytes: 14720
m = {}
m["A"]="BD"
m["B"]="ACE"
m["C"]="BF"
m["D"]="AEG"
m["E"]="BDFH"
m["F"]="CEI"
m["G"]="DH"
m["H"]="EGI"
m["I"]="FH"

1000.times do
  s = gets.to_s
  flag=true
  for i in 0..s.size-3
    t=m[s[i]]
    ck=false
    for j in 0..t.size-1
      ck=true if t[j]==s[i+1]
    end
    flag=false if ck==false
  end
  puts s if flag
end


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

int main() {
    int N; cin >> N;
    set<string> ans;
    for (int i = 0; i < N; i++) {
        string S; cin >> S;
        ans.insert(S);
    }
    cout << ans.size() << endl;
}


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

#define MOD 1000000007

long long N, M, K;
long long kaidan[1000000];

//フェルマーの小定理:a/b≡a*b^(MOD-2) (mod MOD)

long long modpow(long long ori, long long po){
	long long res = 1;
	while(po > 0){
		if(po&1){
			res *= ori;
			res %= MOD;
		}
		ori *= ori;
		ori %= MOD;
		po >>= 1;
	}
	return res;
}

long long comb(long long A, long long B) {
	if(B == 0){
		return 1;
	}
	long long ans = kaidan[A];
	ans *= modpow(kaidan[B], MOD-2);
	ans %= MOD;
	ans *= modpow(kaidan[A-B], MOD-2);
	ans %= MOD;
	return ans;
}

long long cal(long long maxi) {
	kaidan[0] = 1;
	for(long long i = 1; i <= maxi; i++){
		kaidan[i] = i * kaidan[i-1];
		kaidan[i] %= MOD;
	}
}

int main(){
	cin >> N >> M >> K;
	cal(N*M);

	long long ans = 0;

	long long xans = 0;
	for(long long i = 0; i < M; i++){
		long long tmp = i;
		tmp *= (M-i);
		tmp %= MOD;
		tmp *= N * N;
		tmp %= MOD;
		xans += tmp;
		xans %= MOD;
	}
	xans *= comb(N*M-2, K-2);
	xans %= MOD;

	long long yans = 0;
	for(long long i = 0; i < N; i++){
		long long tmp = i;
		tmp *= (N-i);
		tmp %= MOD;
		tmp *= M * M;
		tmp %= MOD;
		yans += tmp;
		yans %= MOD;
	}
	yans *= comb(N*M-2, K-2);
	yans %= MOD;

	cout << (xans + yans)%MOD << endl;

}



Measured memory_bytes: 1792
#include <stdio.h>

int main(){
    int a, b, c, max;
    
    scanf("%d %d %d", &a, &b, &c);
    
    if(a>b) max = a;
    else    max = b;
    if(max<c) max = c;
    
    printf("%d", a+b+c-max);
    
}

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

int main() {
    string data;
    int result[3];
    int last = 1;
    cin >> data;

    for(int i=0; i<3; i++) {
        result[i] = 0;
    }

    for(int i=0; i<3; i++) {
        if(data[i]=='a') {
            result[0] = 1;
        }
        else if(data[i]=='b') {
            result[1] = 1;
        }
        else if(data[i]=='c') {
            result[2] = 1;
        }
    }

    for(int i=0; i<3; i++) {
        if(result[i]==0) {
            last = 0;
            break;
        }
    }
    if(last==1) {
        cout << "Yes" << endl;
    }
    else {
        cout << "No" << endl;
    }

    return 0;
}

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

#define M 1046527
#define L 14

char H[M][L]; /* Hash Table */

int getChar(char ch){
  if ( ch == 'A') return 1;
  else if ( ch == 'C') return 2;
  else if ( ch == 'G') return 3;
  else if ( ch == 'T') return 4;
}

/* convert a string into an integer value */
long long getKey(char str[]){
  long long sum = 0, p = 1, i;
  for ( i = 0; i < strlen(str); i++ ){
    sum += p*(getChar(str[i]));
    p *= 5;
  }
  return sum;
}

int h1(int key){ return key % M;}
int h2(int key){ return 1+(key%M-1); }

int find(char str[]){

    long long i=0,t,key; // 大きい値の定義
    key=getKey(str);
    while(1)
    {
    	t=(h1(key)+i*h2(key))%M;
    	if(strcmp(H[t],str)==0)
    	{
    		return 1;
    	}
    	else if(strlen(H[t])==0)
    	{
    		return 0;
    	}
    	i++;
    }
    	return 0;
}

int insert(char str[]){

 long long i=0,t,key; // 大きい値の定義
    key=getKey(str);
    while(1)
    {
    	t=(h1(key)+i*h2(key))%M;
    	if(strcmp(H[t],str)==0)
    	{
    		return 1;
    	}
    	else if(strlen(H[t])==0)
    	{
    		strcpy(H[t],str);
    		return 0; 
    	}
    	i++;
    }
    	return 0;
    

}

int main(){
    int i, n, h;
    char str[L], com[9];
    for ( i = 0; i < M; i++ ) H[i][0] = '\0';
    
    scanf("%d", &n);
    
    for ( i = 0; i < n; i++ ){
	scanf("%s %s", com, str);
	
	if ( com[0] == 'i' ){
	    insert(str);
	} else {
	    if (find(str)){
		printf("yes\n");
	    } else {
		printf("no\n");
	    }
	}
    }

    return 0;
}


Measured memory_bytes: 16104
package main
import (
  "fmt"
  "sort"
)

func main() {
  var n, alice, bob int
  fmt.Scan(&n)
  cards := make([]int, n)
  for i := 0; i < n; i++ {
    fmt.Scan(&cards[i])
  }
  
  sort.Sort(sort.Reverse(sort.IntSlice(cards)))
  
  for i := 0; i < n; i += 2 {
    alice += cards[i]
    if i+1 < n {
      bob += cards[i+1]
    }
  }
  fmt.Println(alice - bob)
}

Measured memory_bytes: 512
#include <stdio.h>
#define MAX 10000

struct node{

int p, q, r;
};
struct node T[MAX];
int n;


void preorder(int t){

if(t == -1) return;
  printf(" %d",t);
  preorder(T[t].q);
  preorder(T[t].r);
}

void inorder(int t){
  if(t == -1) return;
  inorder(T[t].q);
  printf(" %d",t);
  inorder(T[t].r);
}

void post(int t){
  if(t == -1) return;
  post(T[t].q);
  post(T[t].r);
  printf(" %d",t);
}


int main(){
  int i, v, q, r, root;

  scanf("%d", &n);
   for(i = 0; i < n; i++) T[i].p = -1;
 

  for(i = 0; i < n; i++){
   scanf("%d %d %d", &v, &q, &r);
    T[v].q = q;
    T[v].r = r;
    if(q != -1) T[q].p = v;
    if(r != -1) T[r].p = v;
  }

  for(i = 0; i < n; i++)
    if(T[i].p == -1) root = i;
  printf("Preorder\n");
  preorder(root);
  printf("\n");
  printf("Inorder\n");
  inorder(root);
  printf("\n");
  printf("Postorder\n");
  post(root);
  printf("\n");

  return 0;
}

Measured memory_bytes: 1820
n=int(input())
A=list(map(int,input().split()))
B=list(map(int,input().split()))
C=list(map(int,input().split()))

counter=0
for i in range(n-1):
  if A[i]==A[i+1]-1:
    counter+=C[A[i]-1]
print(counter+sum(B))

Measured memory_bytes: 3060
N=int(input())
*H,=map(int,input().split())
L=len(H)

ans=0
active=0

for i in range(N):
    if  H[i]<=active: # 低くなってしまった
        active=H[i]
    else: # 同じかそれ以上
        ans+=H[i]-active
        active=H[i]
print(ans)

Measured memory_bytes: 9044
import bisect
from operator import itemgetter
import math
import functools
import itertools
import numpy as np
import sys
MAX_INT = int(10e10)
MIN_INT = -MAX_INT
mod = 1000000007
sys.setrecursionlimit(1000000)
def IL(): return list(map(int,input().split()))
def SL(): return input().split()
def I(): return int(sys.stdin.readline())
def S(): return input()

s = input()
num = s.count("x")

if num <= 7:
    print("YES")
else:
    print("NO")


Measured memory_bytes: 21456
def solve():
    A = [list(map(int, input().split())) for i in range(3)]
    N = int(input())
    b = [int(input()) for i in range(N)]

    for i in range(3):
        if (A[i][0] in b and A[i][1] in b and A[i][2] in b) or (A[0][i] in b and A[1][i] in b and A[2][i] in b):
            print('Yes')
            return
    if (A[0][0] in b and A[1][1] in b and A[2][2] in b) or (A[2][0] in b and A[1][1] in b and A[0][2] in b):
        print('Yes')
        return
    print('No')

solve()


Measured memory_bytes: 3064
while 1:
    n, m = map(int, input().split())
    if n+m == 0:
        break
    B = [int(input(),2) for i in range(n)]
    C = {0: 0}
    for b in B:
        *D, = C.items()
        for k, v in D:
            C[k^b] = max(C.get(k^b, 0), v+1)
    print(C[0])

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

int main(){
    int n;
    cin>>n;
    vector<int> a(n);
    
    rep(i,n) cin>>a[i];
    rep(i,n-1) cout<<a[i]<<' ';
    cout<<a[n-1]<<endl;
    
    for(int i=1;i<n;i++){
        int v=a[i];
        int j=i-1;
        while(j>=0 && a[j]>v){
            a[j+1]=a[j];
            j--;
        }
        a[j+1]=v;
        
        rep(j,n-1)
            cout<<a[j]<<' ';
        cout<<a[n-1]<<endl;
    }
    
    return 0;
}


Measured memory_bytes: 3104
#include <bits/stdc++.h>
#include<iostream>
#include<cmath>
#define rep(i,n) for(int i=0;i<(n);++i)
using namespace std;
using ll=long long;
using P=pair<int,int>;
const int INF=1001001001;

vector<int> to[100005];

int main(){
   int n,m; cin>>n>>m;
   rep(i,m){
      int a,b; cin>>a>>b;
      --a;--b;
      to[a].push_back(b);
      to[b].push_back(a);
   }
   queue<int> q;
   vector<int> dist(n,INF);
   vector<int> pre(n,-1);
   dist[0]=0;
   q.push(0);
   while(!q.empty()){
      int v=q.front(); q.pop();
      for(int u:to[v]){
         if(dist[u]!=INF) continue;
         dist[u]=dist[v]+1;
         pre[u]=v;
         q.push(u);
      }
   }

   cout<<"Yes"<<endl;
   rep(i,n){
      if(i==0) continue;
      int ans=pre[i];
      ++ans;
      cout<<ans<<endl;
   }
   return 0;
}


Measured memory_bytes: 10616
#include <stdio.h>
#include <iostream>
#include <vector>
#include <string>
#include <set>
#include <list>
#include <map>
#include <queue>
#include <stack>
#include <math.h>
#include <algorithm>
using namespace std;
#define ll long long
const double EPS = 1e-10;

string s;

int main (){
  cin>>s;
  ll n=s.size();
  list<int> lst;
  for(ll i=0;i<n;i++){
    lst.push_back(s[i]-'0');
  }
  ll ans=n;
  for(auto itr=lst.begin();ans>1&&itr!=lst.end();){
    auto itr2=itr;
    auto itr3=itr;
    if(itr!=lst.begin()){
      itr2--;
    }
    if(itr!=(--lst.end())){
      itr3++;
    }
    if(itr!=lst.begin()&&*itr!=*itr2){
      itr--;
      itr=lst.erase(itr);
      itr=lst.erase(itr);
      ans-=2;
    }
    else if(itr!=(--lst.end())&&*itr!=*itr3){
      itr=lst.erase(itr);
      itr=lst.erase(itr);
      ans-=2;
    }
    else{
      itr++;
    }
  }
  cout<<n-ans<<endl;
}


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

int wa[51][11];

struct Team {
    int ac, wa, id;
};
bool operator<(const Team &t, const Team &s) {
    return (t.ac != s.ac) ? t.ac > s.ac
              : ((t.wa != s.wa) ? t.wa < s.wa
                 : t.id < s.id);
}

int main() {
    int T, P, R;
    while(cin>>T>>P>>R, T|P|R) {
        memset(wa, 0, sizeof(wa));
        vector<Team> team(T, (Team){0,0,0});
        for (int i=0; i<T; ++i) team[i].id = i+1;
        int t, p, tt;
        string m;
        for (int i=0; i<R; ++i) {
            cin>>t>>p>>tt>>m; t--, p--;
            if (m == "CORRECT") {
                team[t].ac++;
                team[t].wa += 1200 * wa[t][p] + tt;
            } else wa[t][p]++;
        }
        sort(team.begin(), team.end());
        for (int i=0; i<T; ++i)
            cout<<team[i].id<<" "<<team[i].ac<<" "<<team[i].wa<<endl;
    }
}

Measured memory_bytes: 1240
#!/usr/bin/env ruby

(n, m) = gets.chomp.split(/ /).map(&:to_i)
lm = 0
rm = 100001
m.times do
  (l, r) = gets.chomp.split(/ /).map(&:to_i)
  lm = lm > l ? lm : l
  rm = rm < r ? rm : r
end
if lm == rm
  puts 1
elsif lm > rm
  puts 0
else
  puts rm - lm + 1
end


Measured memory_bytes: 3964
S=input()
N=len(S)

ans="No"
if S==S[::-1]:
  if S[0:(N-1)//2] == S[:(N-1)//2:-1]:
    if S[(N+3)//2-1:] == S[:(N+3)//2-2:-1]:
      ans="Yes"
print(ans)

#print(S,S[::-1])
#print(S[0:(N-1)//2],S[:(N-1)//2:-1])
#print(S[(N+3)//2-1:],S[:(N+3)//2-2:-1])

Measured memory_bytes: 3060
#include <stdio.h>

int a,b,c;
int x;
int count=0;
main(){
		scanf("%d%d%d",&a,&b,&c);
                x = b-a;
		while(a <= b){
                 if(c%a==0){
		    	count++;
		 }
                 a++;
                }
		printf("%d\n",count);
	return 0;
}

Measured memory_bytes: 596
#include<iostream>
using namespace std;
int main(){
	int n,T;
	cin >> n >> T;
	int c[1000],t[1000];
	for(int i=0;i<n;i++) cin >> c[i] >> t[i];
	int ans=1001;
	for(int i=0;i<n;i++){
		if(t[i]<=T) ans=min(ans,c[i]);
	}
	if(ans==1001) cout << "TLE" << endl;
	else cout << ans << endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<cmath>
#include<queue>
#include<map>
#include<set>
#include<list>
#include<iomanip>
#include<vector>
#include<functional>
#include<algorithm>
#include<cstdio>
#include<unordered_map>
using namespace std;
typedef long long ll;
int main() {
	int a, b, c;
	cin >> a >> b >> c;
	if (a + b == c || a == b + c || a + c == b)
		cout << "Yes" << endl;
	else
		cout << "No" << endl;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
  public static void main (String[] args) {
    Scanner in = new Scanner(System.in);
  
    while (in.hasNext()) {
      int N = in .nextInt();
      StringBuilder baseNeg2 = new StringBuilder();
     
      while (N != 0) {
        if (N % 2 != 0) {
          baseNeg2.insert(0, 1);
          --N;
        } else {
          baseNeg2.insert(0,0);
        }

        N /= -2;
      }
      
      if (baseNeg2.length() == 0) {
        baseNeg2.append(0);
      }

      System.out.println(baseNeg2);
    } 
  }
}

Measured memory_bytes: 23892
#include <iostream>

using namespace std;

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

    long long r = 0, s = 0;
    for (int i = 0; i < m; i++) {
        long long d, c;
        cin >> d >> c;
        r += c;
        s += d * c;
    }

    cout << r - 1 + (s - 1) / 9 << endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<cmath>
#include<string>
#include<vector>
#include<deque>
#include<map>
#include<set>

#define REP(i,a,b) for(int i = (a); i < b; ++i)
#define inf 1e9+10
#define MOD 1000000007

using ll = long long;
using namespace std;

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

	cout << a + pow(a, 2) + pow(a, 3);

	return 0;
}

Measured memory_bytes: 4100
#include<iostream>
using namespace std;
int main(){
  int x,y;
  cin>>x;
  y=1;
  while(1){
    if(x>y){
      y*=2;
    }
    else if(x==y)
      {
        cout<<y<<endl;
        break;
      }
    else{
      cout<<y/2<<endl;
      break;
    }
  }


  
}



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

int n, ma, mb, a[50], b[50], c[50], inf = 1e9 + 7, Ma, Mb, dp[50][444][444], ans = inf;

int main(){
    cin >> n >> ma >> mb;
    for (int i = 0; i < n; i++){
        scanf("%d%d%d", &a[i], &b[i], &c[i]);
        Ma = max(a[i], Ma);
        Mb = max(b[i], Mb);
    }
    for (int i = 0; i <= n; i++){
        for (int j = 0; j <= 400; j++){
            for (int k = 0; k <= 400; k++){
                dp[i][j][k] = inf;
            }
        }
    }

    dp[0][0][0] = 0;
    for (int i = 0; i < n; i++){
        for (int j = 0; j <= 400; j++){
            for (int k = 0; k <= 400; k++){
                if (dp[i][j][k] == inf) continue;
                dp[i + 1][j][k] = min(dp[i + 1][j][k], dp[i][j][k]);
                dp[i + 1][j + a[i]][k + b[i]] = min(dp[i + 1][j + a[i]][k + b[i]], dp[i][j][k] + c[i]);
            }
        }
    }
    for (int i = 1; i <= 400; i++){
        for (int j = 1; j <= 400; j++){
            if (i * mb == j * ma) ans = min(ans, dp[n][i][j]);
        }
    }
    if (ans == inf) ans = -1;
    printf("%d\n", ans);
}


Measured memory_bytes: 32896
#include <iostream>
#include <cmath>
#include <vector>
#include <map>
#include <stack>
#include <queue>
#include <set>
#include <algorithm>
#include <iomanip>
#include <string.h>

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define ALL(a)  (a).begin(),(a).end()

typedef long long lint;

using namespace std;

int main(){
  lint N,M;
  cin>>N>>M;
  vector<pair<lint,lint> > v;
  REP(i,N){
    lint A,B;
    cin>>A>>B;
    v.push_back(make_pair(A,B));
  }
  sort(ALL(v));
  lint ans=0;
  auto itr=v.begin();
  while(M>0){
    int c=min(itr->second,M);
    M-=c;
    ans+=c*itr->first;
    ++itr;
  }
  cout<<ans<<endl;
  return 0;
}


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

int main()
{
    long long n,mindiff=10000,ex=8,cn=0;
    cin>>n;
    long long ccn=n;
    int vers=0;
    while(ccn!=0){
        vers++;
        ccn/=10;
    }
    int i=vers-1;
    int v[vers+5];
    while(n!=0){
        v[i]=n%10;
        n/=10;
        i--;
    }
    int a=0;
    for(int i=0; i<vers-2; i++){
        a=0;
        a+=v[i];
        a*=10;
        a+=v[i+1];
        a*=10;
        a+=v[i+2];
        if(i==0){
            mindiff=(a-753)*(a-753);
            ex=a-753;
        }
        if((a-753)*(a-753)<mindiff){
            ex=a-753;
            mindiff=(a-753)*(a-753);
        }
    }
    cout<<abs(ex);

    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>

int p,n,a,b,i;

int main(){
	a=b=i=0;
	while(scanf("%d,%d",&p,&n)!=EOF){
		a+=p*n;
		b+=n;i++;
	}
	printf("%d\n%d\n",a,(int)(b/(double)i+0.5));
	
	return 0;
}

Measured memory_bytes: 0
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#define y0 yy
#define y1 Yy
#define yn YY
#include <assert.h>
#include <algorithm>
#include <vector>
using namespace std;
const int inf = 0x3f3f3f3f;

int n, t, a[100005], mn = inf, mx, cnt1, cnt2, profit;

int main() {
	scanf("%d %d", &n, &t);
	for (int i = 0; i < n; i++) {
		scanf("%d", a + i);
		if (a[i] < mn) {
			mn = a[i];
			cnt1 = 1;
		} else if (a[i] == mn) cnt1++;
		profit = a[i] - mn;
		if (profit > mx) {
			mx = profit;
			cnt2 = 1;
		} else if (profit == mx) cnt2 += cnt1;
	}
	printf("%d\n", cnt2);
#ifdef LOCAL_MSVC_DEBUG
	system("pause");
#endif
	return 0;
}


Measured memory_bytes: 640
import java.util.*;

class Main{
  public static void main(String[] args){
    Scanner sc=new Scanner(System.in);
    String s=sc.next();
    int k=sc.nextInt();
    PriorityQueue<String> pq=new PriorityQueue<>();
    for(int i=0;i<s.length();i++){
      for(int j=i+1;j<=i+5&&j<=s.length();j++){
        pq.add(s.substring(i,j));
      }
    }
    Set<String> set=new HashSet<>();
    String ans="";
    while(set.size()<k){
      ans=pq.poll();
      set.add(ans);
    }
    System.out.println(ans);
  }
}

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

struct P {
    double x;
    double y;
};

int main() {
    int N;
    cin >> N;
    vector<P> t(N);
    rep(i, N) {
        double x, y;
        cin >> x >> y;
        t[i] = {x, y};
    }

    vector<int> v(N);
    double sums;
    iota(v.begin(), v.end(), 0);
    do {
        double sum = 0.0;
        rep(i, N - 1) {
            int x1   = v[i];
            int x2   = v[i + 1];
            double d = sqrt((t[x1].x - t[x2].x) * (t[x1].x - t[x2].x)
                            + (t[x1].y - t[x2].y) * (t[x1].y - t[x2].y));
            sum += d;
        }
        sums += sum;
    } while (next_permutation(v.begin(), v.end()));

    int kaizyou = 1;
    for (int i = 1; i <= N; i++)
        kaizyou = kaizyou * i;

    cout << fixed << setprecision(9);
    cout << sums / kaizyou << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<sstream>
#include<fstream>
#include<string>
#include<vector>
#include<deque>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<algorithm>
#include<functional>
#include<utility>
#include<bitset>
#include<cmath>
#include<cstdlib>
#include<ctime>
#include<cstdio>

using namespace std;

#define REP(i,n) for(int i=0;i<int(n);i++)
#define foreach(c,itr) for(__typeof((c).begin()) itr=(c).begin();itr!=(c).end();itr++)
typedef long long ll;
typedef pair<int,int> P;

int main(void){
	          int i;

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

	          int N,x;
	          cin >> N >> x;
	          vector<int> a(N);
	          REP(i,N) cin >> a[i];

	          sort(a.begin(),a.end());
	          for(i=1;i<N;i++) a[i]+=a[i-1];

	          bool f=false;
	          for(i=0;i<N;i++){
	        	  if(a[i]>x){
	        		  cout << i << endl;
	        		  f=true;
	        		  return 0;
	        	  }
	          }

	          if(!f){
	        	  if(a[N-1]==x) cout << N << endl;
	        	  else cout << N-1 << endl;
	          }

	          return 0;
}


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

int main()
{
    int Anum, Bnum, Cnum;
    cin >> Anum >> Bnum >> Cnum;
    if (Anum <= Cnum && Bnum >= Cnum)
    {
        cout << "Yes" << endl;
    }
    else
    {
        cout << "No" << endl;
    }
    return 0;
}

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

typedef long long int int64;

#define MAX(a,b) ((a)>(b)?(a):(b))
#define MIN(a,b) ((a)<(b)?(a):(b))
#define ABS(a) ((a)>(0)?(a):-(a))

void run(void){
  int a,b,c;
  scanf("%d%d%d",&a,&b,&c);
  int max=MAX(a,MAX(b,c));
  int min=MIN(a,MIN(b,c));
  int mid=a+b+c-max-min;
  printf("%d\n",max*10+mid+min);
}

int main(void){
  run();
  return 0;
}


Measured memory_bytes: 128
import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main {
    public static void main(String args[]) throws Exception{
        BufferedReader stdR = new BufferedReader(new InputStreamReader(System.in));
        int N = Integer.parseInt(stdR.readLine());
        int[] p = new int[N];
        String[] s = stdR.readLine().split(" ");
        for(int i = 0 ; i < N ; i++) {
            p[i] = Integer.parseInt(s[i]);
        }
        if(isOrder(p)) {
            System.out.println("YES");
        }else {
            boolean isok = false;
            for(int i = 0 ; i < N ; i++) {
                for(int j = i + 1 ; j < N ; j++) {
                    int tmp = p[i];
                    p[i] = p[j];
                    p[j] = tmp;
                    isok = isOrder(p);
                    if(isok) {
                        System.out.println("YES");
                        break;
                    }else {
                        p[j] = p[i];
                        p[i] = tmp;
                    }
                }
                if(isok)break;
            }   
            if(!isok)System.out.println("NO");
        }
        
    }
    
    public static boolean isOrder(int[] a) {
        int res = a[0];
        for(int i = 1 ; i < a.length ; i++) {
            if(res <= a[i]) {
                res = a[i];
            }else {
                return false;
            }
        }
        return true;
    }
}


Measured memory_bytes: 22356
#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1e9 + 7;

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

    long long n, k;
    cin >> n >> k;
    vector<long long> A(n);
    for(long long i = 0; i < n; i++){
        cin >> A[i];
    }

    long long ans = 0;
    for(long long i = 0; i < n; i++){
        for(long long j = i + 1; j < n; j++){
            if(A[i] > A[j]){
                long long hoge = k * (k + 1) / 2;
                ans = (ans + hoge) % MOD;
            }else if(A[i] < A[j]){
                long long hoge = k * (k - 1) / 2;
                ans = (ans + hoge) % MOD;
            }
        }
    }

    cout << ans << endl;

    return 0;
}

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

void change(string s)
{
	int n = s.length();

	int cc = 0;

	for(int i=0;i<n/2;i++)
	{

		if(s[i]== s[n-i-1])
			continue;

		cc+= 1;

		if(s[i]<s[n-i-1])
			s[n-i-1]= s[i] ;
		else
			s[i]= s[n-i-1] ;
	}
	cout<<cc<<endl;
}

int main()
{
string s;
cin>>s;
change((s));
return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <assert.h>
#include <fstream>
#include <iostream>
#include <algorithm>
#include <array>
#include <vector>
#include <queue>
#include <set>
#include <cmath>
#include <map>
//#include <unordered_map>
//#include <unordered_set>
//#include <boost/container/static_vector.hpp>
//#include <boost/unordered_set.hpp>
//#include <boost/unordered_map.hpp>
//#include <unistd.h>

//#include <cv.h>
//#include <highgui.h>
#include <stdlib.h>
#include <string>

const int MAX_N = 100050;
int N, T;
long long A[MAX_N];

int main(int argc, char **argv) {
    std::cin >> N >> T;
    for (int i = 1; i <= N; i++) {
        std::cin >> A[i];
    }
    
    int num;
    int min = A[1];
    int max_d = 0;
    for (int i = 2; i <= N; i++) {
        if (min + max_d < A[i]) {
            num = 1;
            max_d = A[i] - min;
        } else if (min + max_d == A[i]) {
            num++;
        }
        if (A[i] < min) {
            min = A[i];
        }
    }

    std::cout << num << std::endl;

    
    return 0;
}


Measured memory_bytes: 1024
#include <iostream>
#include <cmath>
#include <string>
#include <vector>
#include <algorithm>
#include <set>
#define mp make_pair

using namespace std;

int main()
{
	int h, w, d;
	scanf("%d %d %d", &h, &w, &d);
	pair<int, int> p[90001];
	for (int i = 1; i<=h; ++i)
		for (int k = 1; k <= w; ++k) {
			int a;
			scanf("%d", &a);
			p[a] = mp(i, k);
		}
	int q;
	scanf("%d", &q);
	int j[90001];
	for (int i = 1; i <= d; ++i) {
		j[i] = 0;
	}
	for (int i = d + 1; i <= h*w; ++i) {
		j[i] = j[i-d] + abs(p[i].first - p[i - d].first) + abs(p[i].second - p[i - d].second);
	}
	for (int i = 0; i < q; ++i) {
		int l, r;
		scanf("%d %d", &l, &r);
		long long res = j[r] - j[l];
		printf("%lld\n", res);
	}
	return 0;
}

Measured memory_bytes: 2176
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <string>
#include <cstring>
#include <ctime>


using namespace std;

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

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

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

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define EXISTch(s,c) ((((s).find_first_of(c)) != std::string::npos)? 1 : 0)//cがあれば1 if(1)
#define SORT(c) sort((c).begin(),(c).end())

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

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI = acos(-1.0);
const int INF = (int)1000000007;
const LL MOD = (LL)1000000007;//10^9+7
const LL INF2 = (LL)100000000000000000;//10^18

int main() {

	int n; cin >> n;

	vector<int> a(8,0);

	int over = 0;
	for (int i = 0; i < n; i++) {
		int score; cin >> score;

		if (score < 3200) {
			a[score / 400]=1;
		}
		else {
			over++;
		}
		
	}

	int inner = 0;
	for (int i = 0; i < 8; i++) {
		if (a[i])inner++;
	}
	
	cout << max(1, inner) << " " << inner + over << endl;


	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < int(n); i++)
using namespace std;
using ll = long long;
const int INF = (1<<30)-1;
const long long LINF = (1LL<<62)-1;
const int dx[] = {-1, 0, 1, 0};
const int dy[] = {0, 1, 0, -1};
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

signed main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  vector<vector<int>> to(n);
  rep(i, n-1) {
    int a, b;
    cin >> a >> b;
    --a, --b;
    if (a < b)
      swap(a, b);
    to[a].push_back(b);
  }
  ll ans = 1, prev = 1;
  for (int i = 1; i < n; i++) {
    prev += i+1;
    for (auto e : to[i])
      prev -= e+1;
    ans += prev;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 14236
#include <bits/stdc++.h>
#include <map> // pair
using namespace std;
int main(){
  int A,B,C;
  cin>>A>>B>>C;
  int ans;
  if(A==B)ans=C;
  else if(A==C)ans=B;
  else if(B==C)ans=A;
  cout<<ans<<endl;
  }


Measured memory_bytes: 256
from sys import exit
n,m = map(int,input().split())
gate=[]
rc=[0,n]
for i in range(m):
    mg=list(map(int,input().split()))
    if rc[1]<mg[0] or rc[0]>mg[1]:
        print(0)
        exit()
    rc[0]= rc[0] if rc[0]>mg[0] else mg[0]
    rc[1] = rc[1] if rc[1]<mg[1] else mg[1]
print(rc[1]-rc[0]+1)

        


Measured memory_bytes: 3064
n = int(input())
ones = n % 10 

if ones == 2 or ones == 4 or ones == 5 or ones == 7 or ones == 9:
    print("hon")
elif ones == 0 or ones == 1 or ones == 6 or ones == 8:
    print("pon")
else:
    print("bon")

Measured memory_bytes: 9168
s = input()
mmyy = False
yymm = False



if 0 < int(s[0:2]) <= 12:
    mmyy = True
if 0 < int(s[2:4]) <= 12:
    yymm = True

if mmyy is True and yymm is not True:
    print('MMYY ')
elif yymm is True and mmyy is not True:
    print('YYMM')
elif mmyy is True and yymm is True:
    print('AMBIGUOUS')
else:
    print('NA')

Measured memory_bytes: 38256
#どっちで出すか注意, rstrip注意
#提出前に見返すこと！
def main():
    import sys
    input = sys.stdin.readline
    sys.setrecursionlimit(10**7)
    from collections import Counter, deque
    #from collections import defaultdict
    from itertools import combinations, permutations, accumulate
    #from itertools import product
    from bisect import bisect_left,bisect_right
    import heapq
    from math import floor, ceil
    #from operator import itemgetter

    #inf = 10**17
    #mod = 10**9 + 7

    n,m = map(int, input().split())
    l = -1
    r = 10**20
    for _ in range(m):
        a,b = map(int, input().split())
        l = max(l, a)
        r = min(r, b)
    if l<=r:
        print(r-l+1)
    else:
        print(0)

if __name__ == '__main__':
    main()

Measured memory_bytes: 40556
#include <iostream>

using namespace std;

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

    int ret = 0;
    for (int i = 0; i <= 3000; i++) {
        for (int j = 0; j <= 3000; j++) {
            int remain = d - (a * i + b * j);
            if (remain >= 0 && remain % c == 0)ret++;
        }
    }
    cout << ret << endl;
    return 0;
}

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

int main(){
	int N;
	cin >> N;
	int h[N];
	for(int i = 0; i< N; i++)
		cin >> h[i];
	int cost[N];
	cost[0] = 0;
	cost[1] = abs(h[0]-h[1]);
	for(int i = 2; i < N; i++){
		int a = cost[i-2] + abs(h[i-2]-h[i]);
		int b = cost[i-1] + abs(h[i-1]-h[i]);
		cost[i] = min(a,b);
	}
	cout << cost[N-1] << endl;
	return 0;
}

Measured memory_bytes: 1024
N = gets.to_i
H = gets.split(" ").map(&:to_i)

ans = 0
nishi = []
N.times { |i|
  if nishi.size == 0
    ans += 1
  else
    if nishi.max <= H[i]
      ans += 1
    end
  end
  nishi << H[i]
}

puts ans


Measured memory_bytes: 1788
h,w = map(int,input().split())
s = [input() for _ in range(h)]

dp = [[0] * w for _ in range(h)]
if(s[0][0] == '#'):
    dp[0][0] = 1

for i in range(h):
    for j in range(w):
        if(i == 0)&(j != 0):
            dp[i][j] = dp[i][j-1] + (s[i][j-1] != s[i][j])*1
        elif(i != 0)&(j == 0):
            dp[i][j] = dp[i-1][j] + (s[i-1][j] != s[i][j])*1
        elif(i != 0)&(j != 0):
            dp[i][j] =min(dp[i][j-1] + (s[i][j-1] != s[i][j])*1,
                            dp[i-1][j] + (s[i-1][j] != s[i][j])*1)

ans = (dp[-1][-1] + 1)//2
print(ans)

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

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

    s += 'T';

    bool fx[20010] = {}, fy[20010] = {};
    fx[10000] = fy[10000] = true;
    int ct = 0, cf = 0;
    for (int i = 0; i < s.size(); i++) {
        if (s[i] == 'T') {
            if (!cf) {
                ct++;
                continue;
            }
            vector<int> yy, xx;
            for (int j = 0; j < 20010; j++) {
                if (ct % 2 && fy[j]) {
                    yy.push_back(j);
                }
                else if (!(ct % 2) && fx[j]) {
                    xx.push_back(j);
                }
            }
            for (int j = 0; j < yy.size(); j++) {
                fy[yy[j] + cf] = true;
                fy[yy[j] - cf] = true;
                fy[yy[j]] = false;
            }
            for (int j = 0; j < xx.size(); j++) {
                fx[xx[j] + cf] = true;
                if (ct) fx[xx[j] - cf] = true;
                fx[xx[j]] = false;
            }

            ct++;
            cf = 0;
        }
        else {
            cf++;
        }
    }

    cout << (fy[10000 + y] && fx[10000 + x] ? "Yes" : "No") << endl;

    return 0;
}


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

const double eps = 1e-12;
double x[4], y[4];

void rotate()
{
    double lx = x[3], ly = y[3];
    for ( int i = 2; i >= 0; i-- ) x[i+1] = x[i], y[i+1] = y[i];
    x[0] = lx, y[0] = ly;
}

double cross( double x1, double y1, double x2, double y2 )
{
    return x1 * y2 - y1 * x2;
}

bool check()
{
    double a = cross( x[1] - x[0], y[1] - y[0], x[3] - x[0], y[3] - y[0] );
    double b = cross( x[2] - x[1], y[2] - y[1], x[3] - x[1], y[3] - y[1] );
    double c = cross( x[0] - x[2], y[0] - y[2], x[3] - x[2], y[3] - y[2] );
    return ( a > 0 && b > 0 && c > 0 ) || ( a < 0 && b < 0 && c < 0 );
}

bool solve()
{
    for ( int i = 0; i < 4; i++ )
    {
        if ( check() ) return false;
        rotate();
    }
    return true;
}

int main( void )
{
    string input;
    while ( cin >> input )
    {
        replace( input.begin(), input.end(), ',', ' ' );
        istringstream is(input);

        for ( int i = 0; i < 4; i++ ) is >> x[i] >> y[i];

        cout << ( solve()? "YES" : "NO" ) << endl;
    }

    return 0;
}

Measured memory_bytes: 0