akhauriyash/Code-Regression huggingface dataset:
#include "bits/stdc++.h"
using namespace std;

typedef long long ll;
#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)

//* 便利な変数
namespace {
	int dx4[] = { 1, -1, 0, 0 };
	int dy4[] = { 0, 0, 1, -1 };

	int dx8[] = { 1, -1, 0, 0, 1, 1, -1, -1 };
	int dy8[] = { 0, 0, -1, 1, -1, 1, -1, 1 };

	int mDays[] = { 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };

	ll A, B, C, D, E, F, G, H, I, J, K, L, M,
		N, O, P, Q, R, S, T, U, V, W, X, Y, Z;
}
template <typename T>
vector<T> INP(ll n)
{
	vector<T> x;
	REP(i, n) {
		T tmp; cin >> tmp;
		x.push_back(tmp);
	}
	return move(x);
}
//* n文字1行の文字列を入力，一文字ごとの配列を返す
vector<char> SPRIT_STRING(ll n)
{
	string str; cin >> str;
	vector<char> cs(n);
	REP(i, n) cs[i] = str[i];
	return move(cs);
}
//* 文字列中から文字列を検索して別の文字列に置換する
void strReplace(std::string& str, const std::string& from, const std::string& to) {
	std::string::size_type pos = 0;
	while (pos = str.find(from, pos), pos != std::string::npos) {
		str.replace(pos, from.length(), to);
		pos += to.length();
	}
}
//* 素数判定 is_prime<unsigned>(N)
template<typename T, std::enable_if_t<std::is_unsigned<T>::value, std::nullptr_t> = nullptr>
bool is_prime(const T n) {
	if (n < 4) return n == 2 || n == 3;
	if (n % 2 == 0 || n % 3 == 0 || (n % 6 != 1 && n % 6 != 5)) return false;
	for (T i = 5; i * i <= n; i += 6) if (n % i == 0 || n % (i + 2) == 0) return false;
	return true;
}
//* 組み合わせ計算
inline unsigned long long NChooseK(const unsigned long long& n, const unsigned long long& k)
{
	if (n  < k) return 0;
	if (0 == n) return 0;
	if (0 == k) return 1;
	if (n == k) return 1;
	if (1 == k) return n;
	typedef unsigned long long value_type;
	value_type* table = new value_type[static_cast<std::size_t>(n * n)];
	std::fill_n(table, n * n, 0);
	class n_choose_k_impl
	{
	public:

		n_choose_k_impl(value_type* table, const value_type& dimension)
			: table_(table),
			dimension_(dimension)
		{}

		inline value_type& lookup(const value_type& n, const value_type& k)
		{
			return table_[dimension_ * n + k];
		}

		inline value_type compute(const value_type& n, const value_type& k)
		{
			if ((0 == k) || (k == n))
				return 1;
			value_type v1 = lookup(n - 1, k - 1);
			if (0 == v1)
				v1 = lookup(n - 1, k - 1) = compute(n - 1, k - 1);
			value_type v2 = lookup(n - 1, k);
			if (0 == v2)
				v2 = lookup(n - 1, k) = compute(n - 1, k);
			return v1 + v2;
		}

		value_type* table_;
		value_type dimension_;
	};
	value_type result = n_choose_k_impl(table, n).compute(n, k);
	delete[] table;
	return result;
}
//* 座標nx, nyがWidth,Heightの領域内にあるかどうかのチェック
inline bool rangeCheck2D(int nx, int ny, int Width, int Height)
{
	return nx >= 0 and nx < Width and ny >= 0 and ny < Height;
}
//* bit全探索
/*
for (int i = 0; i < 1<<N; i++) {
	REP(j, N)
		if ((1 & i >> j) == 1) {;}
}
*/

namespace abc078c {
	void abc078c()
	{
		cin >> N >> M;
		cout << (ll)pow(2, M) * (1800 * M + 100 * N) << endl;
	}
}

int main()
{
	abc078c::abc078c();
	//abc066c::abc066c();
	//arc058a::arc058a();
	//agc002a::agc002a();
	return 0;
}

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

using namespace std;

#define ALL(x) x.begin(), x.end()
#define RALL(x) x.rbegin(), x.rend()
#define MP make_pair
#define PB push_back
#define X first
#define Y second

typedef long long int lld;
typedef pair<int, int> pii;
typedef pair<lld, lld> pll;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    
    int n = 0;
    cin >> n;
    
    map<int, int> mp;
    bool flag = false;
    int one_cnt = 0;
    size_t tmp = 0;

    auto func = [&](int x) {
        for (int i = 2; i * i <= x; i++) {
            if (x % i == 0) {
                mp[i]++;
                do {
                    x /= i;
                } while (x % i == 0);
            }
        }
        if (x != 1) {
            mp[x]++;
        }
        if (mp.size() == tmp) {
            flag = true;
        }
        tmp = mp.size();
    };

    for (int i = 0; i < n; i++) {
        int x = 0;
        cin >> x;
        if (x == 1) {
            one_cnt++;
        } else {
            func(x);
        }
    }

    for (auto &p : mp) {
        if (p.second == n) {
            cout << "not coprime" << '\n';
            return 0;
        }
    }

    for (auto &p : mp) {
        if (p.second > 1) {
            cout << "setwise coprime" << '\n';
            return 0;
        }
    }

    cout << "pairwise coprime" << '\n';

    


    return 0;
}

// g++ sol.cpp -o sol.out -Wall -Wextra -Wshadow -fsanitize=undefined -std=c++17

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

bool f(int x){
  int keta = 0;
  while(x>0){
    keta++;
    x /= 10; // 110/10=11 11/10=1 1/10=0 これでketaが3となっている
  }
  return keta%2 == 1; //奇数の場合、1なので、真が返り値となる（bool）
}

int main(){
  int n;
  cin >> n;
  int ans = 0;
  for(int i =1; i<=n; i++){
    if(f(i)){ //f(i)は偶数奇数を判定する関数（iが奇数の場合、ansをインクリメント）
      ans++;
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define SORT(x) sort(x.begin(),x.end())
#define INF 1000000000
#define mod 1000000007
int main(){
    int n,k;long long ans=-INF;
    cin>>n>>k;
    int a[n];
    for(int i=0;i<n;i++)
    cin>>a[i];
    for(int i=-1;i<n;i++){
        for(int j=i+1;j<=n;j++){
            int rem=k-(i+1+n-j);
            if(rem<0)    continue;

            vector<long long> vec;
            for(int x=0;x<=i;x++)   vec.push_back(a[x]);
            for(int x=j;x<n;x++)    vec.push_back(a[x]);
            SORT(vec);
            long long sum=0;
            for(int k=0;k<vec.size();k++)   sum+=vec[k];
            for(int l=0;l<vec.size();l++){
                if(rem==0||vec[l]>0)    continue;
                sum-=vec[l];
                rem--;
            }
            ans=max(ans,sum);
        }
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
#define ll long long int
#define rep(i,n) for( int i = 0; i < n; i++ )
#define rrep(i,n) for( int i = n; i >= 0; i-- )
#define REP(i,s,t) for( int i = s; i <= t; i++ )
#define RREP(i,s,t) for( int i = s; i >= t; i-- )
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define INF 2000000000
#define mod 1000000007
#define INF2 1000000000000000000


int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
	string S; cin >> S;
	cout << S[0] << S.length() - 2 << S[S.length() - 1] << endl;

    return 0;
}


Measured memory_bytes: 256
# 組み合わせ①
# nCk % MOD
# n固定でないとき
# 前処理O(MAX)、計算O(1)

MOD = 10 ** 9 + 7
MAX = 200010
fac = [0] * MAX
finv = [0] * MAX
inv = [0] * MAX
def COMinit():
    fac[0] = fac[1] = 1
    finv[0] = finv[1] = 1
    inv[1] = 1
    for i in range(2, MAX):
        fac[i] = fac[i-1] * i % MOD
        inv[i] = MOD - inv[MOD%i] * (MOD//i) % MOD
        finv[i] = finv[i-1] * inv[i] % MOD
def COM(n, k):
    if n < k: return 0
    if n < 0 or k < 0: return 0
    return fac[n] * (finv[k] * finv[n-k] % MOD) % MOD
COMinit()

n, k = map(int, input().split())

ans = 0
for i in range(min(n, k+1)):
    a = n - i
    b = n
    ans = (ans + COM(n, i) * COM(b - 1, a - 1) % MOD) % MOD
print(ans)
    

Measured memory_bytes: 44144
// #define _GLIBCXX_DEBUG
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
using ll = long long; using pii = pair<int, int>; using vi = vector<int>; using vvi = vector<vi>; using vl = vector<ll>; using vvl = vector<vl>; using vb = vector<bool>; using vvb = vector<vb>;
#define rep0(TMS) for (int CNT = 0; CNT < (int)(TMS); CNT++)
#define rep(CNT, GOAL) for (int CNT = 0; CNT < (int)(GOAL); CNT++)
#define rep2(CNT, START, GOAL) for (int CNT = (int)(START); CNT < (int)(GOAL); CNT++)
#define rep3(CNT, START, GOAL) for (int CNT = (int)(START); CNT > (int)(GOAL); CNT--)
#define all(CONT) begin(CONT), end(CONT)
template <typename T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return true; } return false; }
template <typename T> bool chmin(T &a, const T &b) { if (a > b) { a = b; return true; } return false; }
void prec(const int &DIG) { cout << fixed << setprecision(DIG); cerr << fixed << setprecision(DIG); }
template <typename T> void CERR(const T &ELEM) { cerr << ELEM; }
#define dbl(OBJ) cerr << #OBJ << ": "; CERR(OBJ); cerr << "\n"
template <typename T, typename ...Ts> void CERR(const T &FIRST, const Ts &...REST) { CERR(FIRST); cerr << ", "; CERR(REST...); }
#define dbs(...) cerr << "(" << #__VA_ARGS__ << "): ("; CERR(__VA_ARGS__); cerr << ")\n"
#define itrep(ITR, CONT) for (auto ITR = begin(CONT); ITR != end(CONT); ITR++)
template <typename T> void CERR(const vector<T> &VEC) { cerr << "{ "; itrep(ITR, VEC) { CERR(*ITR); cerr << ", "; } cerr << "}"; }
#define YN(FLG) cout << (FLG ? "YES" : "NO") << "\n"
#define Yn(FLG) cout << (FLG ? "Yes" : "No") << "\n"
#define yn(FLG) cout << (FLG ? "yes" : "no") << "\n"
// const ll INF = LONG_LONG_MAX;
const int INF = INT_MAX;
// const ll MOD = 1000000007; // 998244353;

// #include <atcoder/all>
// using namespace atcoder;

int main() {
	int N; cin >> N;
	vi A(N); rep(i, N) cin >> A[i];
	sort(all(A), greater<int>());
	ll ans = 0;
	if (N % 2 == 0) {
		rep(i, N / 2) ans += 2 * A[i];
		ans -= A[0];
	} else if (N % 2 == 1) {
		rep(i, (N - 1) / 2) ans += 2 * A[i];
		ans -= A[0];
		ans += A[N / 2];
	}
	cout << ans << endl;
}

Measured memory_bytes: 4032
W,a,b=map(int,input().split())
if a<b:
  if a+W<b:
    print(b-(a+W))
  else:
    print(0)
elif a==b:
  print(0)
else:
  if b+W<a:
    print(a-(b+W))
  else:
    print(0)

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

int main(){
    int n;
    multiset<ll> s, status, tmp;
    //sは与えられる集合、statusはシミュレーションの状態、tmpはstatusのコピー先
    
    //入力部
    cin >> n;
    int j;
    for(int i = 0; i < (1 << n); i++){
        cin >> j;
        s.insert(j);
    }

    status.insert(*(s.rbegin()));
    s.erase(*(s.rbegin()));
    for(int i = 0; i < n; i++){
        tmp = status; //状態を保存しておき、tmpを変化させていく、statusは参照するだけ
        for(auto e : status){ //現在の状態の最小の値から見ていく
            auto itr = s.lower_bound(e); //現在見ている値の中で最も左にあるものを参照
            if(itr == s.begin()){ //その位置が最左端ならシミュレーション失敗
                cout << "No" << endl;
                return 0;
            }
            tmp.insert(*prev(itr)); //見ている値よりも小さい物を取る
            s.erase(prev(itr));
        }
        status = tmp; //状態を更新する
    }

    //シミュレーションに成功したらYes
    cout << "Yes" << endl;
    return 0;
}

Measured memory_bytes: 24832
#include <bits/stdc++.h>
using namespace std;
using Graph = vector<vector<int>>;
#define ll long long
#define _GLIBCXX_DEBUG
const ll MOD = 1000000007;
const int MAX = 510000;

int main() {
  string S;
  cin >> S;
  if (S=="AKIHABARA") cout << "YES"<< endl;
  else if (S=="KIHABARA"||S=="AKIHBARA"||S=="AKIHABRA"||S=="AKIHABAR") cout << "YES" << endl;
  else if (S=="KIHBARA"||S=="KIHABRA"||S=="KIHABAR"||S=="AKIHBRA"||S=="AKIHBAR"||S=="AKIHABR") cout << "YES" << endl;
  else if (S=="AKIHBR"||S=="KIHABR"||S=="KIHBAR"||S=="KIHBRA") cout << "YES" << endl;
  else if (S=="KIHBR") cout << "YES" << endl;
  else cout << "NO" << endl;
}

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

struct node{
  struct node *p;
  struct node *l;
  struct node *r;
  int key;
};

typedef struct node *Node;

Node Root = NULL;

void insert(int k){

  Node y = NULL;
  Node x = Root;
  Node new;

  new = malloc(sizeof(struct node));
  new->key = k;
  new->l = NULL;
  new->r = NULL;

  while(x != NULL){
    y = x;
    if(new->key < x->key) x = x->l;
    else x = x->r;
  }

  new->p = y;
  if(y == NULL) Root = new;
  else if(new->key < y->key) y->l = new;
  else y->r = new;
}

void inorder(Node v){
  if(v->l != NULL){
    inorder(v->l);
  }
  printf(" %d",v->key);
  if(v->r != NULL){
    inorder(v->r);
  }
}
void preorder(Node v){
  printf(" %d",v->key);
  if(v->l != NULL){
    preorder(v->l);
  }
  if(v->r != NULL){
    preorder(v->r);
  }
}

int main(void){
  int n,i,x;
  char in[10];
  scanf("%d",&n);

  for(i=0;i<n;i++){
    scanf("%s",in);
    if (in[0] == 'i'){
      scanf("%d",&x);
      insert(x);
    }else if(in[0] == 'p'){
      inorder(Root);
      printf("\n");
      preorder(Root);
      printf("\n");
    }

  }
  return 0;
}

Measured memory_bytes: 24040
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.text.DecimalFormat;
import java.util.ArrayList;


class Main {
	public static void main(String[] args) throws IOException {
		DecimalFormat df1 = new DecimalFormat("0.000000");
		BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
		String s = new String(in.readLine());
		String[] ss = s.split(" ");
		double a = Double.parseDouble(ss[0]);
		System.out.print(df1.format((double)a*(double)a*Math.PI)+ " ");
		System.out.println(df1.format(2*(double)a*Math.PI));
	}

}

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

using namespace std;

bool isPalindrome(string s)
{
    bool isPalindrome = true;
    for (int i = 0; i < s.size(); i++)
    {
        if (s[i] != s[s.size() - 1 - i])
            isPalindrome = false;
    }
    return isPalindrome;
}

int main()
{
    string s;
    cin >> s;
    bool isStrong = false;
    isStrong = isPalindrome(s);
    if(isStrong)
        isStrong = isPalindrome(s.substr(0, (s.size() - 1) / 2));
    int startPoint = (s.size()+3)/2 - 1;
    if(isStrong)
        isStrong = isPalindrome(s.substr(startPoint, s.size() - startPoint + 1));
    if(isStrong)
        cout << "Yes" << endl;
    else
    {
        cout << "No" << endl;
    }
    
    return 0;
}

/*#include <bits/stdc++.h>
 
using namespace std;
 
int main() {
	return 0;
}

using namespace std;
 
int main() {
	return 0;
}

using namespace std;
 
int main() {
	return 0;
}

using namespace std;
 
int main() {
	return 0;
}*/

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

namespace ConsoleApp2
{
    public class Program
    {
        public static void Main(string[] args)
        {
            int N = int.Parse(Console.ReadLine());
            string[] strHs = Console.ReadLine().Split(' ');

            int maxNum = 0;
            int count = 0;

            int index = 0;
            int currentH = int.Parse(strHs[0]);
            while (index<N-1)
            {
                int nextH = int.Parse(strHs[index+1]);
                if (currentH >= nextH) count++;
                else
                {
                    maxNum = Math.Max(count, maxNum);
                    count = 0;
                }
                currentH = nextH;
                index++;
            }
            maxNum = Math.Max(count, maxNum);


            Console.WriteLine(maxNum);
            Console.ReadLine();
        }
    }


}


Measured memory_bytes: 22620
#include <bits/stdc++.h>
#include<stdio.h>
#include <iostream>

using namespace std;

int main()
{
  int n,i;
  cin>>n;
  float ar[n+1];
  long double sum;
  for(i=1;i<(n+1);i++)
  cin>>ar[i];
  sort(ar+1,ar+n+1);
  sum=ar[1];
  for(i=2;i<n+1;i++)
  {
      sum=(sum+ar[i])/2;
  }
  cout<<sum;
  
    
    

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <vector>
using namespace std;
const int maxn = 105;
typedef long long ll;

int main() {
#ifdef DEBUG
  freopen("in.cpp","r",stdin);
#endif
  ll n;
  cin>>n;
  n++;
  vector<int>op;
  while(n>1){
    if(n&1){
      n--;
      op.push_back(1);
    } else {
      op.push_back(0);
      n>>=1;
    }
  }
  int cur = 0;
  vector<int>ans;
  for(int i=op.size()-1;i>=0;i--) {
    ++cur;
    if(op[i])ans.insert(ans.begin(),cur);
    else ans.push_back(cur);
  }
  for (int i=1;i<=cur;i++) ans.push_back(i);
  cout<<ans.size()<<endl;
  for(int i = 0; i < ans.size();i++){
    cout<<ans[i];
    if(i+1<ans.size())cout<<' ';
    else cout<<endl;
  }
  return 0;
}


Measured memory_bytes: 256
N, D = list(map(int, input().split()))
X = [list(map(int, input().split())) for _ in range(N)]

def nasu(x, y):
  t = 0
  for i in range(D):
    t += (X[x][i] - X[y][i]) ** 2
  t **= (1 / 2)
  if t == int(t):
    return 1
  else:
    return 0


ans = 0
for i in range(N - 1):
  for j in range(i + 1, N):
    ans += nasu(i, j)

print(ans)

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
int main()
{
long long int n,x=1,y,sum=0,a;
cin>>a;
while(a)
{
    if(a==1)
    {
        sum=sum+(x);
        break;
    }
    else
    {
        a=a/2;
          sum=sum+x;
        x=x*2;

    }
}
cout<<sum;
    return 0;

}

Measured memory_bytes: 256
import java.util.ArrayList;
import java.util.Collections;
import java.util.Scanner;
 


public class Main {
	private static Scanner sc = new Scanner(System.in);
	//result = Math.pow(num1, num3)
	//StringBuffer str = new StringBuffer(hoge1);
	//String hoge2 = str.reverse().toString();
	//map.containsKey(A)

	//Map<String, Integer> map = new HashMap<String, Integer>(n);
	/*for ( キーのデータ型 key : マップの名前.keySet() ) {
		データのデータ型 data = マップの名前.get( key );
		
		// keyやdataを使った処理;
	}*/
	//int i = Integer.parseInt(s);
	//Queue<String> qq=new ArrayDeque<>(); //add,poll,peek
	//Deque<String> qq=new ArrayDeque<>();//push,pop,peek
	//ArrayList<String> cc = new ArrayList<>(n);
	//Collections.sort(list);
	//Array.sort(list);   cc.contains(tmp)
	//Arrays.asList(c).contains("a")
	//list.set(1,"walk");//1 1 2 3 5
	//static long mod =1000000007;
	//static 	ArrayList<Integer> cc = new ArrayList<>(100);
	
	
	
	public static void main(String[] args) {
		//int N=sc.nextInt();for(int i=0;i<N;i++) {}
		//M 77 || //A 65 || //R 82 || //C 67 || //H 72 || 
		int A=sc.nextInt();
		int B=sc.nextInt()	;
		
		if(A>=13)p(B);
		else if(A>=6)p(B/2);
		else p(0);
		
	
		
		
	}



	
	
	
	

	


	
	static void p(String ans) {System.out.println(ans);};
	static void p(int ans) {System.out.println(ans);};
	static void p() {System.out.println();};
	static void p(long ans) {System.out.println(ans);};
	static void p(double ans) {System.out.println(ans);};
	
}
	


Measured memory_bytes: 21716
#include <iostream>
#include <algorithm>
using namespace std;
// 最大公約数を求める関数
long gcd(int x, int y)
{
	long r;
	// ユーグリッドの互除法
	while ((r = x % y) != 0) // yで割り切れるまでループ
	{
		x = y;
		y = r;
	}
	return y;
}
long lcm(long x, long y)
{
	return (x * y / gcd(x, y));
}


int main(void) {
	long N, M;
	char S[100001];
	char T[100001];
	cin >> N >> M;
	for (int i = 0; i < N; i++) {
		cin >> S[i];
	}
	for (int i = 0; i < M; i++) {
		cin >> T[i];
	}
	if (S[0] != T[0]) {
		cout << -1 << endl;
		return 0;
	}
	long L = lcm(N, M);
	long NN = L / N;
	long MM = L / M;
	long LL = lcm(NN, MM);
	for (long i = 1; i <= L/LL; i++) {
		if (i * LL /NN < N && i * LL / MM < M) {
			if (S[i*LL / NN] != T[i*LL / MM]) {
				cout << -1 << endl;
				return 0;
			}
		}
	}
	cout << L <<endl;
	return 0;
}

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

int main(){
    int N;
    while(cin>>N,N){
        int money[6]={500,100,50,10,5,1},ans=0;
        N=1000-N;
        for(int i=0;i<6;i++){
            while(N-money[i]>=0) N-=money[i],ans++;
        }
        printf("%d\n",ans);
    }
    return 0;
}

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

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

    int a, b, c, d, e, k;
    cin >> a >> b >> c >> d >> e >> k;

    if (max({a, b, c, d, e}) - min({a, b, c, d, e}) > k) {
        cout << ":(" << endl;
    } else {
        cout << "Yay!" << endl;
    }

    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

// https://atcoder.jp/contests/abc158/tasks/abc158_a
public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ

		Scanner sc = new Scanner(System.in);
		String S = sc.next();
		sc.close();

		S = S.replace("A", "");
		int ans = S.length();

		if(ans==3||ans==0) {
			System.out.println("No");
		}else {
			System.out.println("Yes");
		}



	}
}


Measured memory_bytes: 21588
#include <iostream>
#include <vector>
#include <algorithm>
#include <utility>
#include <queue>
#include <string>
#include <set>
#include <bitset>
#include <unordered_map>
#include <cmath>

using namespace std;
using ll = long long;
using Pii = pair<int, int>;
using Pll = pair<ll, ll>;
template <class T>
using Vvec = vector<vector<T> >;

int main()
{
    ll N, A, B;
    cin >> N >> A >> B;
    ll d = abs(A - B);
    if(d%2==0){
        cout << d/2 << endl;
    }
    else{
        cout << min(A, N-B+1) + (d-1)/2 << endl; 
    }
}

Measured memory_bytes: 256
//
//  main.cpp
//  lab1
//
//  Created by 王黎杉 on 2020/5/29.
//  Copyright © 2020 王黎杉. All rights reserved.
//

#include <algorithm>
#include <vector>
#include <iostream>
using namespace std;

vector<pair<int,int>> classroom;

bool cmp(pair<int,int> &a,pair<int, int> &b)
{
    return a.second < b.second;
}

int main()
{
    ios::sync_with_stdio(false);
    
    int n = 0,a = 0;
    
    cin>>n;
    
    for( int i = 1 ; i <= n ; i++ )
    {
        cin>>a;
        classroom.push_back(make_pair(i,a));
    }
    
    sort(classroom.begin(), classroom.end(), cmp);
    
    for( int i = 0 ; i < n ; i++ )
    {
        cout<<classroom[i].first<<" ";
    }
    
    
    return 0;
}


Measured memory_bytes: 1780
int main(){
  int R[200000], n, i, max, min;

  scanf("%d", &n);
  
  for(i = 0;i < n;i++) scanf("%d", &R[i]);

  max = -9999999999999;
  min = R[0];

  for(i = 1;i < n;i++){
    if(max < R[i] - min) max = R[i] - min;
    if(min > R[i]) min = R[i];
  }

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

  return 0;
}

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

int main() {
  string s;
  string answer;
  cin >> s;
  answer = "No";
  
  if (s == "abc") {answer = "Yes";}
  if (s == "acb") {answer = "Yes";}
  if (s == "bac") {answer = "Yes";}
  if (s == "bca") {answer = "Yes";}
  if (s == "cab") {answer = "Yes";}
  if (s == "cba") {answer = "Yes";}
  
  cout << answer << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int n;
vector<int> a;
char s[1111111];
int sum;

int main() {
	scanf("%s", s);
	n = strlen(s);
	for (int i = n - 1; i >= 0; --i)
		a.push_back(s[i] - '0');
	int p = 0;
	for (int i = 0; i < (int)a.size(); ++i) {
		a[i] = a[i] * 9 + p;
		p = a[i] / 10; a[i] %= 10;
	}
	if (p) a.push_back(p);
	for (int i = 0; i < (int)a.size(); ++i) sum += a[i];
	for (int i = 1; ; ++i) {
		for (int j = 0; j < 9; ++j) {
			++sum; ++a[0];
			for (int i = 0; ; ++i)
				if (a[i] == 10) {
					sum -= 10; a[i] = 0;
					if (i + 1 == (int)a.size()) a.push_back(0);
					++a[i + 1]; ++sum;
				} else break;
		}
		if (sum <= i * 9) {
			printf("%d", i); return 0;
		}
	}
}


Measured memory_bytes: 2932
#include<cstdio>
int a[2000],b[2000];
long long c[2000],d[1001];
long long const infty=1e17;
int main(){
    int n,m;
    scanf("%d%d",&n,&m);
    for(int i=0;i<m;i++)scanf("%d%d%lld",&a[i],&b[i],&c[i]);
    d[1]=0;
    for(int i=2;i<=n;i++)d[i]=-infty;
    for(int i=1;i<n;i++){
        for(int j=0;j<m;j++){
            if(d[b[j]]<d[a[j]]+c[j])d[b[j]]=d[a[j]]+c[j];
        }
    }
    long long ans=d[n];
    for(int i=1;i<=n;i++){
        for(int j=0;j<m;j++){
            if(d[b[j]]<d[a[j]]+c[j])d[b[j]]=d[a[j]]+c[j];
        }
    }
    if(ans==d[n])printf("%lld",ans);
    else printf("inf");
    return 0;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((int)(x).size)
#define MOD 1000000007
const long long mod = 1e9+7;
typedef vector<long long> Vl;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<Vl> VVl;
typedef pair<int, int> PII;
typedef long long ll;

int main(){
    int a=0,b=0,c=0,d,n=0,x;
    string s,s1,s2;
    cin >> a >>b;   
    if(a<=8) {
        if(b<=8)
            cout << "Yay!" << endl;
        else cout << ":(" << endl;
    }
    else cout << ":(" << endl;
    return 0;
} 

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

const int N = 1e5 + 10;
vector<int> g[N];

int dist[N][2];

void dfs(int s, int p, int type){
   dist[s][type] = dist[p][type] + 1;
   for(auto i: g[s]){
      if(i != p){
         dfs(i, s, type);
      }
   }
}

int main(){

   int n, u, v;
   cin >> n >> u >> v;

   for (int i = 0; i < n-1; ++i)
   {
      int x, y;
      cin >> x >> y;
      g[x].push_back(y);
      g[y].push_back(x);
   }

   dfs(u, 0, 0);
   dfs(v, 0, 1);

   int ans = 0;
   for (int i = 1; i <= n; ++i)
   {
      if(dist[i][0] < dist[i][1])
         ans = max(ans, dist[i][1] - 2);
   }

   cout<<ans;
   return 0;
}

Measured memory_bytes: 10368
#include <iostream>
#include <climits>
#include <cmath>

using namespace std;

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

    int A[N];
    for (int i=0; i<N; ++i)
    {
        cin >> A[i];
    }

    long long s = 0;
    for (int i=0; i<N; ++i)
    {
        s += A[i];
    }

    double a = ((double)s)/N;

    int ci = 0;
    double cn = 101;
    for (int i=0; i<N; ++i)
    {
        double d = std::abs(A[i]-a);
        if (d < cn)
        {
            ci = i;
            cn = d;
        }
    }

    cout << ci << endl;
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>
#include<math.h>
#include<map>
#include<algorithm>
#include<set>
#include <stdexcept>
#define rep(i,N) for(int i=0;i<(N);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
using namespace std;
const long long MOD = 1e9 + 7;
const long long INF = 1e12;
const int dx[]={1,0,-1,0,1,-1,-1,1};
const int dy[]={0,1,0,-1,1,1,-1,-1};
int ceil(int a,int b){
    return (a+b-1)/b;
}
int main(void){
    string s;
    cin>>s;
    int n=2;
    while(1){
        rep(i,(s.size()-n)/2){
            if(s[i]!=s[i+(s.size()-n)/2]){
              n+=2;
              continue;
            } 
            if(i==(s.size()-n)/2-1) {
                cout<<s.size()-n<<endl;
                return 0;
            }    
        }
    }
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <algorithm>
#include <iostream>
#include <string>
#include <vector>
#include <functional>
#include <map>
#include <iomanip>
#include <math.h> 
#include <stack>
#include <queue>
#include <bitset>
#include <cstdlib>
#include <tuple>
#include <cctype>

using namespace std;

int main() {
	int i, j, k;
	string s, t;

	cin >> s >> t;

	string st="aa";
	st = s;

	for (i = 0; i < s.length(); i++) {
		
		//st[0] = s[s.length() - 1];
		char ch = st[s.length() - 1];
		st.pop_back();
		st = ch + st;


		if (st == t) {
			cout << "Yes" << endl;
			getchar();
			getchar();
			return 0;
		}

		//cout << st << endl;
		//s = st;
	}


	cout << "No" << endl;







	getchar();
	getchar();
	return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
    public static void main(String[] args){

        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int[] arr = new int[N];
        for(int i=0;i<N;i++){
            arr[i] = sc.nextInt();
        }
        int[] dp = new int[N];
        dp[0] = 0;dp[1] = Math.abs(arr[0]-arr[1]);

        for(int i=2 ;i< N;i++ ){
            dp[i] = Math.min(
                    dp[i-1] + Math.abs(arr[i]-arr[i-1]),
                    dp[i-2] + Math.abs(arr[i]-arr[i-2]));
        }
        System.out.println(dp[N-1]);

    }
}


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

int main() {
  int a, b, x;

  cin >> a >> b;
  
  x = a * b % 2;
  if(x == 1){
    cout << "Odd" << endl;
  }
  if(x == 0){
    cout << "Even" << endl;
  }
}
    

 






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

#define rep(i, N) for (int i = 0; i < (int)N; i++)
using namespace std;
typedef long long ll;
const ll LLINF = 9223372036854775807;
const int INF = pow(2,29);
const int MOD = 1000000007;

int main() {
  int Q; cin >> Q;
  priority_queue<ll> l; l.push(-1*LLINF);
  priority_queue<ll, vector<ll>, greater<ll>> r; r.push(LLINF);

  ll pos = 0, result = 0;

  rep(i, Q) {
    int type; cin >> type;
    if (type==1) {
      ll a, b; cin >> a >> b;
      result += b;
      if (l.top()>a) {
        ll x = l.top();
        result += x-a;
        l.pop(); r.push(x);
        l.push(a); l.push(a);
      }
      else if (r.top()<a) {
        ll x = r.top();
        result += a-x;
        r.pop(); l.push(x);
        r.push(a); r.push(a);
      }
      else {
        l.push(a); r.push(a);
      }
      pos = l.top();
      // cout << l.top() << " " << r.top() << endl;
    } else {
      cout << pos << " " << result << endl;
    }
  }
  return 0;
}


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

using namespace std;

#define SZ(x) (int)(x.size())
#define REP(i, n) for(int i=0;i<(n);++i)
#define FOR(i, a, b) for(int i=(a);i<(b);++i)
#define RREP(i, n) for(int i=(int)(n);i>=0;--i)
#define RFOR(i, a, b) for(int i=(int)(a);i>=(int)(b);--i)
#define ALL(a) (a).begin(),(a).end()
#define DUMP(x) cerr<<#x<<" = "<<(x)<<endl
#define DEBUG(x) cerr<<#x<<" = "<<(x)<<" (L"<<__LINE__<<")"<< endl;

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using P = pair<int, int>;

const double eps = 1e-8;
const ll MOD = 1000000007;
const int INF = INT_MAX / 2;
const ll LINF = LLONG_MAX / 2;

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

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

template<typename T1, typename T2>
ostream& operator<<(ostream &os, const pair<T1, T2> p) {
  os << p.first << ":" << p.second;
  return os;
}

template<class T>
ostream &operator<<(ostream &os, const vector<T> &v) {
  REP(i, SZ(v)) {
    if(i) os << " ";
    os << v[i];
  }
  return os;
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(10);

  int n; cin >> n;
  vll a(n);
  REP(i, n) cin >> a[i];

  ll x = 0;
  FOR(i, 2, n) x ^= a[i];
  ll su = a[0] + a[1];


  if((x ^ a[0] ^ a[1]) == 0) {
    cout << 0 << endl;
    return 0;
  }

  if(su < x) {
    cout << -1 << endl;
    return 0;
  }

  if(((su - x) & 1) != 0) {
    cout << -1 << endl;
    return 0;
  }

  ll d = (su - x) >> 1;

  if((d & x) != 0) {
    cout << -1 << endl;
    return 0;
  }

  if(d > a[0]) {
    cout << -1 << endl;
    return 0;
  }


  ll now = d;
  RREP(i, 63) {
    ll tmp = (1ll<<i) & x;
    if(tmp == 0) continue;
    if((now | tmp) <= a[0]) {
      now |= tmp;
    }
  }

  if(now == 0) {
    cout << -1 << endl;
    return 0;
  }

  cout << a[0] - now << endl;
}








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

const int MOD=1000000007;
const int INF=0x3f3f3f3f;
const ll INFL=0x3f3f3f3f3f3f3f3f;

string s;
vector<ll>ans;
void dfs(){
	ans.push_back(stoll(s));
	if(s.size()>=10){
		return;
	}
	int x=s.back()-'0';
	for(int d=max(0,x-1);d<=min(9,x+1);d++){
		s+=d+'0';
		dfs();
		s.pop_back();
	}
}

int main(){
	int K;cin>>K;
	for(int i=1;i<=9;i++){
		s="";
		s+='0'+i;
		dfs();
	}
	sort(ans.begin(),ans.end());
	assert(ans.size()>=100000);
	cout<<ans[K-1]<<endl;
}

Measured memory_bytes: 2420
#include <algorithm>
#include <iostream>
#include <limits>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
int n = 0;
vector<vector<pair<int, int>>> g;
vector<int> pre;
vector<int> ll;
vector<bool> res;
int tt = 0;
void input() {
    cin >> n;
    int N = n;
    g = vector<vector<pair<int, int>>>(n, vector<pair<int, int>>());
    while (N > 1) {
        int a = 0, b = 0, w = 0;
        cin >> a >> b >> w;
        g[a].push_back({b, w});
        g[b].push_back({a, w});
        N--;
    }
}
pair<int, int> bfs(int src) {
    queue<pair<int, int>> q;
    q.push({src, 0});
    int res = src, D = 0;
    vector<bool> vi(n, false);
    vi[src] = true;
    while (!q.empty()) {
        auto curr = q.front();
        q.pop();
        if (curr.second > D) {
            D = curr.second;
            res = curr.first;
        }
        for (auto nig : g[curr.first]) {
            if (!vi[nig.first]) {
                vi[nig.first] = true;

                q.push({nig.first, nig.second + curr.second});
            }
        }
    }
    return {res, D};
}
void compute() {
    auto first = bfs(0);
    auto dist = bfs(first.first);
    cout << dist.second << endl;
}

int main() {
    input();
    compute();
    return 0;
}


Measured memory_bytes: 9532
#include <cstdio>
#include <algorithm>
int main() {
    int a, b, c, d;
    scanf("%d %d %d %d", &a, &b, &c, &d);
    if(a > c) std::swap(a,c), std::swap(b, d);
    int len;
    if(d > b) len = (b - c > 0) ? (b-c) : 0;
    else len = d - c;
    printf("%d", len);
    return 0;
}


Measured memory_bytes: 128
#include <iostream>
#include <cstdio>
#include <fstream>
#include <algorithm>
#include <iterator>
#include <math.h>
#include <cmath>
#include <stdlib.h>
#include <vector>
#include <queue>
#include <stack>
#include <set>
#include <regex>
#include <stdexcept>
#include <unordered_set>
#include <string>
#include <map>
#include <iomanip>
#include <sstream>
#include <cassert>
#include <time.h>
#include <numeric>
#include <complex>
  
using namespace std;
using ull = unsigned long long;
using ll = long long;
using ld = long double;
using D = double;
using ii = pair<int, int>;
using vi = vector<int>;
using vii = vector<ii>;
  
#define pb push_back
#define mp make_pair
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(), x.rend()
#define fill(x, y) memset(x, y, sizeof(x))
#define makeunique(x) sort(all(x)), (x).resize(unique(all(x)) - (x).begin())
#define rep(i, x)  for(int i = 0; i < (x); i++)
#define rrep(i, x) for(int i = (x - 1); i >= 0; i--)
#define y1 y1_1234413
#define j1 j1_235
#define y0 y0_235
#define j0 j0_256
#define fi first
#define se second
#define itn int
#define re return
#define prev PREV
#define next NEXT
  
#define sz(x) ((int)x.size())
  
const int inf = 2e9;
const ld st = 0.000001;
const ld pi = acos((ld)-1);
const int MAXN = 1e5;
#define FILENAME ""
const double eps = 1e-6;
const int maxn = 1001;


int main()
{
    ios::sync_with_stdio(0);
    cin.tie(NULL);
    //freopen("unionday.in", "r", stdin);
    //freopen("unionday.out", "w", stdout);
    ll n, m, k, d;
    cin >> n >> m >> k >> d;
    vector <ll> a, b, c;
    for (int i = 0; i < n; i++) {
    	ll x;
    	cin >> x;
    	a.pb(x);
    }
    for (int j = 0; j < m; j++) {
    	ll x;
    	cin >> x;
    	b.pb(x);
    }
    for (int i =  0; i < k; i++) {
    	ll x;
    	cin >> x;
    	c.pb(x);
    }
    sort(a.rbegin(), a.rend());
    sort(b.rbegin(), b.rend());
    sort(c.rbegin(), c.rend());
    vector <ll> ans;
    for (int i = 0; i < n; i++) {
    	for (int j = 0; j < m; j++) {
    		for (int k1 = 0; k1 < k; k1++) {
    			if ((i + 1)*(j + 1)*(k1 + 1) <= d) ans.pb(a[i] + b[j] + c[k1]);
    		}
    	}
    }
    sort(ans.rbegin(), ans.rend());
    for (int i = 0; i < d; i++) {
    	cout << ans[i] << endl;
    }
    return 0;
}

Measured memory_bytes: 1540
// AOJ 0121
#include<map>
#include<queue>
#include<string>
#include<cstdio>
#define rep( i, a ) for( int i = 0; i != (a); ++i )

const int d[4] = { -4, 1, 4, -1 };
std::map<std::string, int> m;

void bfs()
{
	std::queue<std::string> que;
	que.push( "01234567" );

	while( !que.empty() )
	{
		std::string s = que.front(); que.pop();
		int pos = s.find( '0' );

		rep( i, 4 )
		{
			std::string ns = s;
			int npos = pos + d[i];
				
			if( npos >= 0 && npos < 8 && !( pos == 3 && i == 1 ) && !( pos == 4 && i == 3 ) )
			{
				std::swap( ns[pos], ns[npos] );
					
				if( !m.count( ns ) )
				{
					que.push( ns );
					m[ns] = m[s] + 1;
				}
			}
		}
	}

	return;
}

int main()
{
	m["01234567"] = 0;
	bfs();

	while( true )
	{
		std::string s;
		rep( i, 8 )
		{
			int a;
			if( scanf( "%d", &a ) == EOF )
				return 0;
			s += a + '0';
		}

		printf( "%d\n", m[s] );
	}

	return 0;
}

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

int f(int x,vector<int> &memo){
  if(memo.at(x)!=-1) return memo.at(x);
  int b{};
  int y = x;
  while(y){
    if(1&y) b++;
    y>>=1;
  }
  if(x%b==0){
    memo.at(x) = 1;
    return memo.at(x);
  }
  else {
    memo.at(x) = f(x%b,memo)+1;
    return memo.at(x);
  }
}
int main(){
  
  int n; cin>>n;
  string s; cin>>s;
  
  int m{};
  vector<int> memo(n+1,-1);
  int a{}, b{};
  vector<int> c(n);
  vector<int> d(n);
  for(int i=0; i<n; i++){
    if(s.at(i)=='1') {
      m++;
    }
  }
  if(m==1){
    if(s.back()=='1'){
      for(int i=0; i<n-1; i++){
        cout << 2 << endl;
      }
      cout << 0 << endl;
    }
    else{
      for(int i=0; i<n-1; i++){
        if(s.at(i)=='1'){
          cout << 0 << endl;
        }
        else{
          cout << 1 << endl;
        }
      }
      cout << 2 << endl;
    }
    return 0;
  }
  if(m==0){
    for(int i=0; i<n; i++){
      cout << 1 << endl;
    }
    return 0;
  }
  c.at(0) = 1; d.at(0) = 1;
  for(int i=1; i<n; i++){
    c.at(i) = c.at(i-1)*2%(m+1);
  }
  for(int i=1; i<n; i++){
    d.at(i) = d.at(i-1)*2%(m-1);
  }
  
  reverse(s.begin(),s.end());
  for(int i=0; i<n; i++){
    if(s.at(i)=='1') {
      a += c.at(i);
      a %= (m+1);
    }
  }
  for(int i=0; i<n; i++){
    if(s.at(i)=='1') {
      b += d.at(i);
      b %= (m-1);
    }
  }
  vector<int> ans(n);
  for(int i=0; i<n; i++){
    if(s.at(i)=='1'){
      if(m>1){
        int e = (b-d.at(i)+m-1)%(m-1);
        if( e%(m-1)==0 ) ans.at(i)=1;
        else ans.at(i) = f(e%(m-1),memo)+1;
      }
      else ans.at(i)=0;
    }
    else{
      int e = (a+c.at(i))%(m+1);
      if( e%(m+1)==0 ) ans.at(i)=1;
      else ans.at(i) = f( e%(m+1),memo)+1;
    }
  }
  reverse(ans.begin(),ans.end());
  for(auto i:ans) cout << i << endl;
  
}


Measured memory_bytes: 6824
#include <stdio.h>

int main(){
    int N, i, sum = 0, min = 999999;
    int left[300000] = {0}, right[300000] = {0};
    char people[300000];

    scanf("%d%s", &N, people);
    //printf("people %s\n", people);
    for(i = 0; i < N; i++){
        if(i > 0){
            if(people[i - 1] == 'W'){
                sum++;
            }
            left[i] = sum;;
        }
        //printf("left %d %d\n", i, left[i]);
    }
    sum = 0;
    for(i = N - 1; i >= 0; i--){
        if(i < N - 1){
            if(people[i + 1] == 'E'){
                sum++;
            }
            right[i] = sum;
        }
        //printf("right %d %d\n", i, right[i]);
    }
    for(i = 0; i < N; i++){
        if(min >= left[i] + right[i]){
            min = left[i] + right[i];
        }
    }
    printf("%d\n", min);

    return 0;
}


Measured memory_bytes: 2816
_input = [i for i in open(0).read().split('\n') if i]
l, r = [int(i) for i in _input[0].split()]
i_start = l
j_start = l + 1
i_end = min(r-1, i_start+(2019-1))
j_end = min(r, j_start+(2019-1))

min_val = 2018
for i in range(i_start, i_end+1):
    for j in range(j_start, j_end+1):
        if i >= j:
            continue
        min_val = min(min_val, (i * j) % 2019)
print(min_val)


Measured memory_bytes: 3064
#include<cstdio>
#include<algorithm>
#include<vector>
using namespace std;
typedef long long ll;
const int MAXN = 1e6 + 5;

struct Edge
{
	int next,to;
}e[MAXN];
int head[MAXN],etot=0;
inline void add(int u,int v)
{
	e[++etot]=(Edge){ head[u],v};
	head[u] = etot;
}

int pre[MAXN], w[MAXN];

ll ans = 0;
ll sum_w[MAXN];
void dfs(int u)
{
	sum_w[u] = w[u];
	
	vector<ll> son;
	for(int i=head[u]; i; i=e[i].next)
	{
		int v=e[i].to;
		dfs(v);
		
		sum_w[u] += sum_w[v];
		son.push_back(sum_w[v]);
	}
	
	sort(son.begin(),son.end());
	for(int i=0; i<(int)son.size(); ++i)
		ans += ((int)son.size()-i-1) * son[i];
}

int main(void)
{
	int n;
	scanf("%d",&n);
	for(int i=1; i<=n; ++i)
	{
		scanf("%d%d",&w[i],&pre[i]);
		++pre[i];
		if(pre[i]) add(pre[i], i);
	}
	
	for(int i=1; i<=n; ++i) if(!pre[i])
		dfs(i);

	printf("%lld\n",ans);
	return 0;
}


Measured memory_bytes: 92424
#include<stdio.h>
#include<stdlib.h>
int main(void){
int x,n;
  scanf("%d%d",&x,&n);
  int p[n];
  for(int i=0;i<n;i++){
	scanf("%d",&p[i]);
  }
  if(n==0)printf("%d",x);
  else{
    int list[103];
  for(int i=0;i<103;i++){
	list[i]=i-1;
  }
    for(int i=0;i<n;i++){
	list[p[i]+1]=-3;
    }
    int min=200,minidx[100];
    for(int i=0;i<103;i++){
      if(list[i]==-3)continue;
	if(abs(list[i]-x)<min){
      min=abs(list[i]-x);
    }
    }
    for(int i=0;i<103;i++){
	if(list[i]==-3)continue;
      if(abs(list[i]-x)==min){printf("%d",list[i]);
                              return 0;
                             }
    }
  }
    return 0;
  }

Measured memory_bytes: 1732
import java.util.*;

public class Main {

    public static void main(String args[]) {

        // 入力
        Scanner sc = new Scanner(System.in);
        int n = Integer.parseInt(sc.next());
        int[] a1 = new int[n];
        int[] a2 = new int[n];
        for (int i = 0; i < n; i++) {
            a1[i] = Integer.parseInt(sc.next());
        }
        for (int i = 0; i < n; i++) {
            a2[i] = Integer.parseInt(sc.next());
        }

        // 主処理
        int result = 0;
        for (int i = 0; i < n; i++) {
            int sum1 = 0;
            int sum2 = 0;
            for (int j = 0; j <= i; j++) {
                sum1 += a1[j];
            }
            for (int j = i; j < n; j++) {
                sum2 += a2[j];
            }
            int sum = sum1 + sum2;
            result = Math.max(result, sum);
        }

        // 出力
        System.out.println(result);
        sc.close();
    }
}


Measured memory_bytes: 23252
#include <strings.h>
#include <stdio.h>

int min(int a, int b)
{
    return (a > b ? b : a);
}
 
int max(int a, int b)
{
    return (b > a ? b : a);
}
 
int main(void) {
    int i, j, k, h, w;
    int m[501][501];
    int area, hmin;
    char map[500][501];
    int cnt[500][500];

    while (scanf("%d %d", &h, &w), h + w) {
	area = 0;
#if 0
	getchar();
	bzero(m, sizeof(m));
	for (i = 0; i < h; i++) {
	    for (j = 0; j < w; j++) {
		char c;
		scanf("%c", &c);
		if (c == '*') c = 0;
		else {
		    if (i == 0) c = 1;
		    else c = m[i-1][j]+1;
		}
		m[i][j] = c;
	    }
	    getchar();
	}
#endif
#if 1
        for (i = 0; i < h; i++){
            scanf("%s", map[i]);
        }
         
        for (i = 0; i < h; i++){
            for (j = 0; j < w; j++){
                if (i == 0){
                    cnt[i][j] = map[i][j] == '*' ? 0 : 1;
                }
                else {
                    if (map[i][j] == '.'){
                        cnt[i][j] = cnt[i - 1][j] + 1;
                    }
                    else {
                        cnt[i][j] = 0;
                    }
                }
            }
        }
#endif
/*
	for (i = 0; i < h; i++) {
	    for (j = 0; j < w; j++) {
		printf("%d", m[i][j]);
	    }
	    putchar('\n');
	}
*/
#if 1
	for (i = 0; i < h; i++) {
	    for (j = 0; j < w; j++) {
		hmin = 10000000;
		for (k = j; k < w; k++) {
		    if (cnt[i][k] < hmin) hmin = cnt[i][k];
		    if (area < hmin * (k-j+1)) area = hmin * (k-j+1);
		}
	    }
	}
#else
        for (i = 0; i < h; i++){
            for (j = 0; j < w; j++){
                hmin = 10000000;
                for (k = j; k < w; k++){
                    hmin = min(cnt[i][k], hmin);
                    area = max(area, (k - j + 1) * hmin);
                }
            }
        }
#endif
	printf("%d\n", area);
    }
    return 0;
}

Measured memory_bytes: 1824
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.IOException;

public class Main {
  public static void main(String[] args) throws IOException {
    BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
    String o = in.readLine();
    String e = in.readLine();
    for(int i=0; i<o.length()-1; i++) {
      System.out.print(o.substring(i,i+1));
      System.out.print(e.substring(i,i+1));
    }
    System.out.print(o.substring(o.length()-1,o.length()));
    if(o.length()-e.length()!=1)
      System.out.print(e.substring(o.length()-1,o.length()));
  }
}

Measured memory_bytes: 32360
import sys
input = sys.stdin.readline

N = int(input())
B = list(map(int,input().split()))

A=[0]*N
A[0]=B[0]
A[N-1]=B[-1]

for i in range(1,N-1):
    A[i]=min(B[i-1],B[i])

print(sum(A))

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

int main() {
    string s;
    cin >> s;
    s = ' ' + s;
    for (int i = 1; i < s.size(); i++) {
        if (i % 2 != 0)
            cout << s[i];
    }
    cout << endl;
}

Measured memory_bytes: 512
import math

N, M = [int(i) for i in input().rstrip().split(' ')]
_r = math.factorial(2)
patternN = 0
patternM = 0

if N > 1:
    # even(偶数)
    _N = math.factorial(N)
    even = math.factorial(N-2)
    patternN = int(_N / even / _r)

if M > 1:
    # odd(奇数)
    _M = math.factorial(M)
    odd = math.factorial(M-2)
    patternM = int(_M / odd / _r)

print(patternN + patternM)


Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
#define LL long int
#define ULL unsigned long int


int main(){
    string s;
    cin >> s;
    if(s.size() == 6 && s[2] == s[3] && s[4] == s[5]){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
char a[1001][1001];
int wi[8]={1,1,0,-1,-1,-1,0,1};
int wj[8]={0,-1,-1,-1,0,1,1,1},n=0,m=0;
int main(){
    cin>>n>>m;
    for(int i=1;i<=n;i++)for(int j=1;j<=m;j++)cin>>a[i][j];
    for(int i=1;i<=n;i++){
        for(int j=1;j<=m;j++){
            if(a[i][j]=='#')cout<<'#';
            else{
                int num=0;
                for(int m=0;m<8;m++){
                    if(a[i][j]!='.')continue;
                    if(a[i+wi[m]][j+wj[m]]=='#')num++;
                }
                cout<<num;
            }
        }
        cout<<endl;
    }
    return 0;
}

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

int N;
int M, A[10];

int m[10];

vector< pair<int, int> > V, W;

int check[10];

int KETA(int K, int y) {
	while (y > 0) { K /= 6; y--; }
	return K % 6;
}

int COUNT(int INIT, int max_sum) {

	int H = W.size();
	int X[10];

	int ret = 0;

	for (int i = INIT; i < pow(6,6); i++) {
		int sum = 0;
		int n = 0;
		int sign= 0;
		for (int m = 1; m < (int)H; m++) { X[m] = KETA(i, m);  sum += X[m]; }
		if (sign == 1) {
			continue;
		}
		for (int j = 1; j < (int)H; j++) {
			n += W[j].first * X[j];
		}
		if (n > N) { continue; }
		if (((N - n) % W[0].first) == 0) {
			
			sum += (N - n) / W[0].first;
			if (sum >= max_sum) {
				max_sum = sum;  return i; 
			                    }
		}
	}
	return 10000000;
}

int main(void) {

	cin >> N >> M;

	for (int i = 1; i <= M; i++) {
		cin >> A[i];
	}

	m[1] = 2;
	m[2] = 5;
	m[3] = 5;
	m[4] = 4;
	m[5] = 5;
	m[6] = 6;
	m[7] = 3;
	m[8] = 7;
	m[9] = 6;

	for (int i = 1; i <= M; i++) {
		pair<int, int> P;
		P.first = m[A[i]];
		P.second = A[i];
		V.push_back(P);
	}

	sort(V.rbegin(), V.rend());

	for (int i = 0; i < (int)V.size(); i++) {
		if (check[V[i].first] == 0) { W.push_back(V[i]); check[V[i].first] = 1; }
	}

	sort(W.begin(), W.end());

	/*for (int i = 0; i < (int)W.size(); i++){
		cout << W[i].first << " " << W[i].second << endl;
}*/

	

	

	vector<int> U;
	U.resize(10);
	int tmp = 0;
	vector<int> ANS, TMP_ANS;
	string ans="11", tmp_ans;

	int R = 0; int max_sum = 1;
	while (R < pow(7,7)) {
		//cout << "R= " << R << endl;
		R = COUNT(R+1, max_sum);
		if (R >= pow(7,7)) { break; }
		tmp = 0; max_sum = 0;
		for (int i = 1; i < (int)W.size(); i++) {
			U[i] = KETA(R, i); tmp += KETA(R, i)*W[i].first; max_sum += KETA(R, i);
		}
		U[0] = (N - tmp) / W[0].first;
		max_sum += U[0];

		TMP_ANS.clear();

		for (int i = 0; i < (int)W.size(); i++) {
			for (int j = 0; j < (int)U[i]; j++) {
				TMP_ANS.push_back(W[i].second);
			}
		}

		sort(TMP_ANS.rbegin(), TMP_ANS.rend());

		/*for (int i = 0; i < (int)TMP_ANS.size(); i++) {
			cout << TMP_ANS[i];
		}cout << endl;
		*/
		/*tmp_ans = "";
		for (int i = 0; i < (int)ANS.size(); i++) {
			tmp_ans += (char) ANS[i];
		}*/
		//cout << "tmp_ans= " << tmp_ans << endl;
		if (TMP_ANS >ANS) { ANS = TMP_ANS; }
	}
	
	for (int i = 0; i < (int)ANS.size(); i++) {
		cout << ANS[i];
	}cout << endl;
	
	//system("pause");
	return 0;
}

Measured memory_bytes: 256