akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <functional>
#include <algorithm>
#include <utility>

using namespace std;

#define N_MAX 101

#define WIN  3
#define DRAW 1
#define LOSE 0

int results[N_MAX][N_MAX] = {0};

int main() {
    int N; cin >> N;
    int no_data = N * (N -1) / 2;
    for (int i = 0; i < no_data; i++) {
        int a, b, a_pt, b_pt;
        int res_a, res_b;
        cin >> a >> b >> a_pt >> b_pt;
        if (a_pt > b_pt) {
            res_a = WIN;
            res_b = LOSE;
        } else if (a_pt == b_pt) {
            res_a = DRAW;
            res_b = DRAW;
        } else {
            res_a = LOSE;
            res_b = WIN;
        }
        results[a][b] = res_a;
        results[b][a] = res_b;
    }

    pair<int, int> total_pt[N+1];
    for (int i = 1; i <= N; i++) {
        total_pt[i].second = i;
        total_pt[i].first = 0;
        for (int j = 1; j <= N; j++) {
            total_pt[i].first += results[i][j];
        }
    }

    int number[N+1];
    sort(total_pt+1, total_pt+N+1, greater<pair<int, int> >());
    int prev_pt = 100000;
    for (int i = 1; i <= N; i++) {
        if (prev_pt == total_pt[i].first) {
            number[total_pt[i].second] = number[total_pt[i-1].second];
        } else {
            number[total_pt[i].second] = i;
        }
        prev_pt = total_pt[i].first;
    }
    for (int i = 1; i <= N; i++) {
        cout << number[i] << endl;
    }
    return 0;
}

Measured memory_bytes: 0
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
using ll = long long;

ll gcd(ll a,ll b){
        if(b>0) return gcd(b,a%b);
        else    return a;
}

int main(){
        ll n,start,num;
        bool flag = true;
        cin >> n >> start;
        vector<ll> x(n),sa(n);
        for(ll i=0;i<n;i++)     cin >> x[i];
        x.push_back(start);
        sort(x.begin(),x.end());
        for(ll i=0;i<n;i++) sa[i] = x[i+1]-x[i];
        if(n==1){
                cout << sa[0] << endl;
                return 0;
        }
        ll ans = gcd(sa[0],sa[1]);
        for(ll i=1;i<n;i++)     ans = gcd(ans,sa[i]);
        cout << ans << endl;
}

Measured memory_bytes: 2560
/*
 * 16-7-31_AGC002_C.cpp
 *
 *  Created on: 2016/07/31
 *      Author: ryoma
 */

#include <iostream>

using namespace std;

typedef long long ll;
ll  N,L;
ll a[100010],sum,ans[100010];

int main(){
	cin >> N >> L;
	for (int i=0;i<N;i++){
		cin >> a[i];
	}
	ll mx=0;
	int mxi=-1;
	for (int i=0;i<N-1;i++){
		if (mx < a[i]+a[i+1]){
			mx=a[i]+a[i+1];
			mxi= i+1;
		}
	}
	if (mx < L){
		cout << "Impossible"<<endl;
		return 0;
	}
	cout << "Possible"<< endl;
	for (int i=1;i<mxi;i++)
		cout << i << endl;
	for (int i=N-1;i>=mxi;i--)
		cout << i << endl;

	return 0;
}




Measured memory_bytes: 1536
A,B,K=map(int,input().split())

for i in range(K):
  if i%2:
    if B%2:
      B -= 1
    A,B = A+B//2,B//2
  else:
    if A%2:
      A -= 1
    A,B = A//2,B+A//2
    
print(A,B)

Measured memory_bytes: 9124
#include <bits/stdc++.h>
using namespace std;
string s;
char ans1;
int h,w,ans2;
int main()
{
	cin>>h>>w;
	for(int i=0;i<h;i++)
		for(int j=0;j<w;j++)
		{
			cin>>s;
			if(s=="snuke")
			{
				ans1=j+'A';
				cout<<ans1;
				ans2=i+1;
				cout<<ans2<<endl;
				return 0;
			}
		}
	
	return 0;
}


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

typedef long long ll;
int a[111];
int K;
int n;
ll dp[111][7];//不同题目状态不同
ll dfs(int pos,int state,bool limit/*数位上界变量*/)//不是每个题都要判断前导零
{
    if(pos < state)return 0;
    //递归边界，既然是按位枚举，最低位是0，那么pos==-1说明这个数我枚举完了
    if(pos==0) return 1;/*这里一般返回1，表示你枚举的这个数是合法的，那么这里就需要你在枚举时必须每一位都要满足题目条件，也就是说当前枚举到pos位，一定要保证前面已经枚举的数位是合法的。不过具体题目不同或者写法不同的话不一定要返回1 */
    if(state == 0) return 1;
    //第二个就是记忆化(在此前可能不同题目还能有一些剪枝)
    if(!limit && dp[pos][state]!=-1) return dp[pos][state];
    /*常规写法都是在没有限制的条件记忆化，这里与下面记录状态是对应，具体为什么是有条件的记忆化后面会讲*/
    int up=limit?a[pos]:9;//根据limit判断枚举的上界up;这个的例子前面用213讲过了
    ll ans=0;
    //开始计数
    for(int i=0;i<=up;i++)//枚举，然后把不同情况的个数加到ans就可以了
    {
        
        ans+=dfs(pos-1,i == 0?state:state-1,limit && i==a[pos]); //最后两个变量传参都是这样写的
        /*这里还算比较灵活，不过做几个题就觉得这里也是套路了
        大概就是说，我当前数位枚举的数是i，然后根据题目的约束条件分类讨论
        去计算不同情况下的个数，还有要根据state变量来保证i的合法性，比如题目
        要求数位上不能有62连续出现,那么就是state就是要保存前一位pre,然后分类，
        前一位如果是6那么这意味就不能是2，这里一定要保存枚举的这个数是合法*/
    }
    //计算完，记录状态
    if(!limit) dp[pos][state]=ans;
    /*这里对应上面的记忆化，在一定条件下时记录，保证一致性，当然如果约束条件不需要考虑lead，这里就是lead就完全不用考虑了*/
    return ans;
}
ll solve()
{
    memset(dp,-1,sizeof dp);
    return dfs(n/*从最高位开始枚举*/,K,true);//刚开始最高位都是有限制并且有前导零的，显然比最高位还要高的一位视为0嘛
}

// Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main(){
    string s;
    cin>>s>>K;
    for(int i=0;i<s.size();++i) {
        a[s.size()-i] = s[i]-'0';
    }
    n = s.size();
    auto ans = solve();
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vll>;
using vc = vector<char>;
using vvc = vector<vc>;
using pll = pair<ll, ll>;
using stkll = vector<pll>;
const ll INF = 1LL << 60;
const ll MOD = 1e9 + 7;
#define rep(i, n) for (ll i = 0; i < (n); i++)
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}
#ifndef ONLINE_JUDGE
    #define debug(x) cerr << #x << ": " << x << endl;
#else
    #define debug(x)
#endif

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

    ll N, M;
    cin >> N >> M;
    vvll jobs(M);
    priority_queue<ll> pq;
    rep(i, N) {
        ll a, b;
        cin >> a >> b;
        if(a > M) continue;
        jobs[M-a].push_back(b);
    }

    ll ans = 0;
    for(ll i = M-1; i >= 0; i--) {
        for(auto b : jobs[i]) pq.emplace(b);
        if(!pq.empty()) {
            ans += pq.top();
            pq.pop();
        }
    }

    cout << ans << endl;
}


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

using namespace std;

using ll = long long;
using vi = vector<int>;
using vll = vector<ll>;
using vvi = vector<vector<int>>;
using vvl = vector<vector<ll>>;

int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  int a, b;
  cin >> a >> b;
  for (int i = 0; i < 20; i++) {
    int c = 1 + (a - 1) * i;
    if (c >= b) {
      cout << i << endl;
      return 0;
    }
  }
  return 0;
}


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

int main() {
  int n, m;
  cin >> n >> m;
  vector<int> res(n);
  for (int i = 0; i < m; i++) {
    int a, b;
    cin >> a >> b;
    res[a-1]++;
    res[b-1]++;
  }

  for (int i = 0; i < n; i++) {
    cout << res[i] << endl;
  }
  return 0;
}

Measured memory_bytes: 256
import java.util.*;
class Main
{
    public static void main (String[] args)
    {
        Scanner sc = new Scanner(System.in);
        String s = sc.next();
        int a = s.charAt(0) - '0', b = s.charAt(1) - '0',
            c = s.charAt(2) - '0', d = s.charAt(3) - '0';
            char p = '+', q = '+', r = '+';

            if(a+b+c+d==7)       p = q = r = '+';
            else if(a+b+c-d==7){ p = q = '+'; r = '-';}
            else if(a+b-c+d==7){ p = r = '+'; q = '-';}
            else if(a+b-c-d==7){ p = '+'; q = r = '-';}
            else if(a-b+c+d==7){ p = '-'; q = r = '+';}
            else if(a-b+c-d==7){ p = r = '-'; q = '+';}
            else if(a-b-c+d==7){ p = q = '-'; r = '+';}
            else                 p = q = r = '-';
            System.out.println(a + "" + p + "" + b + "" + q + "" + c + "" + r + "" + d + "=7");
    }
}

Measured memory_bytes: 22612
N,K=gets.chomp.split.map(&:to_i)
a=0.0
N.times do |i|
  c=0
  j=i+1
  while K>j do
    j=j*2
    c+=1
  end
  a+=(1.0/N)*((1/2.0)**c)
end
puts a

Measured memory_bytes: 1788
#include <iostream>
#include<string>
#include<cmath>
#include<algorithm>
#include<cctype>
#include<queue>
#include<deque>
#include<regex>
#include<stack>
#include<stdio.h>
#include<vector>
#include<set>
#include<map>
#include<iomanip>

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

typedef int long long ll;
using namespace std;
typedef pair<int, int> P;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
const ll MOD = 1e9 + 7;
static const int MAX = 100;
static const int INF = (1 << 23);

template<class T>
T gcd(T a, T b) { return b ? gcd(b, a % b) : a; }

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

ll fact(ll n){
    if(n==0)return 1;
    else return n*fact(n-1)%MOD;
}
ll calc(ll n,ll k){
    if(k==0)return 1;
    ll m=n*n%MOD;
    if(k%2)return n*calc(m,k/2)%MOD;
    else return calc(m,k/2)%MOD;
}
ll comb(ll n,ll k){
    ll ret=fact(n);
    ret=ret*calc(fact(k),MOD-2)%MOD;
    ret=ret*calc(fact(n-k),MOD-2)%MOD;
    return ret;
}

int main() {
    ll n;
    cin>>n;
    ll p;cin>>p;
    ll odd = 0;
    ll eve = 0;
    vector<ll> a(n);
    rep(i,n){
        cin>>a[i];
        if(a[i]%2)odd++;
        else eve++;
    }

    ll c = pow(2ll,eve);

    ll ans = 0;
    ll st = (p%2?1:0);
    while(st<=odd){
        ans += c*comb(odd,st);
        st+=2;
    }
    cout<<ans<<endl;







    return 0;
}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main() {
	int A, B, C;
	cin >> A >> B >> C;
	if ((A < C&&C < B) || (B < C&&C < A)) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}
	
	return 0;
}

Measured memory_bytes: 256
import scala.io.Source.stdin

object Main {
  def hand(i:Int,j:Int,k:Int,l:Int,m:Int):String = {
    if( (j,k,l) == (i,i,i) || (k,l,m) == (j,j,j) ) "four card"
    else if( (j,l,m) == (i,k,k) || (j,k,m) == (i,i,l) ) "full house"
    else if( (j,k) == (i,i) || (k,l) == (j,j) || (l,m) == (k,k) ) "three card"
    else if( (j,l) == (i,k) || (j,m) == (i,l) || (k,m) == (j,l) ) "two pair"
    else if( i== j || j == k || k == l || l == m ) "one pair"
    else if( (i,j,k,l,m) == (i,i+1,i+2,i+3,i+4) || (i,j,k,l,m) == (1,10,11,12,13) ) "straight"
    else "null"
  }

  def main(args:Array[String]) = {
    stdin.getLines.foreach { s=>
      val l = s.split(",").map(_.toInt).sorted
      println(hand(l(0),l(1),l(2),l(3),l(4)))
    }
  }
}

Measured memory_bytes: 43932
#include<bits/stdc++.h>
using namespace std;
using ll = long long int;
#define int ll
vector<int> dp;

int solve(vector<int>& arr, int curr){
	int n = arr.size();
	if(curr == 0){
		return 0;
		}
	if(curr == 1){
		return abs(arr[1]-arr[0]);
		}
	if(dp[curr] != INT_MAX){
		return dp[curr];
		}
	int s1 = solve(arr, curr-1)+abs(arr[curr]-arr[curr-1]);
	int s2 = solve(arr, curr-2)+abs(arr[curr]-arr[curr-2]);
	dp[curr] = min(s1, s2);
	return dp[curr];
}

int32_t main(){
	int n;
	cin >> n;
	vector<int> arr(n, 0);
	for(int i = 0 ; i < n ; i ++)cin >> arr[i];
	dp.assign(n, INT_MAX);
	cout << solve(arr, n-1) << endl;
}


Measured memory_bytes: 6528
#include<bits/stdc++.h>
#pragma GCC optimize("Ofast")
using namespace std;
typedef long long ll;
typedef pair<ll, ll> PLL;
typedef vector<int> VI;
typedef vector<char> VC;
typedef vector<double> VD;
typedef vector<string> VS;
typedef vector<ll> VLL;
typedef vector<PLL> VP;
const static int INF = 1000000000;
const static int MOD = 1000000007;
const int dx[4]={1, 0, -1, 0};
const int dy[4]={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; }
#define rep(i,n) for (ll i=0; i<(ll)(n); i++)
#define repd(i,n) for (ll i=n-1; i>=0; i--)
#define rept(i,m,n) for(ll i=m; i<n; i++)
#define stl_rep(itr, x) for (auto itr = x.begin(); itr != x.end(); ++itr)
#define all(x) (x).begin(), (x).end()
#define F first
#define S second
#define PF push_front
#define PB push_back
#define SORT(V) sort((V).begin(), (V).end())
#define RVERSE(V) reverse((V).begin(), (V).end())
#define paired make_pair
#define PRINT(V) for(auto v : (V)) cout << v << " "
//charを整数に
int ctoi(char c) { if (c >= '0' && c <= '9') { return c - '0'; } return 0; }
// 累積和 for (int i = 0; i < N; ++i) s[i+1] = s[i] + a[i]; 
void cum_sum(int N,vector<double> a, vector<double> &s){ for(int i=0; i<N; i++){ s[i+1]=s[i]+a[i];}}
//ユークリッドの控除法
ll gcd(ll a,ll b){
    if(b == 0) return a;
    return gcd(b,a%b);
}
//最小公倍数
ll lcm(ll a,ll b){
    ll g = gcd(a,b);
    return a / g * b; // Be careful not to overflow
}
//素数判定
bool is_prime(long long n) {
    if (n <= 1) return false;
    for (long long p = 2; p * p <= n; ++p) {
        if (n % p == 0) return false;
    }
    return true;
}
int getdigit(ll num){
    unsigned digit=0;
    while(num!=0){
        num /= 10;
        digit++;
    }
    return digit;
}
//空白文字も入力 getline(cin, S);
//桁数指定 setprecision

int main()
{
    ios::sync_with_stdio(0); 
    cin.tie(0); 
    cout.tie(0);
    ll N;
    string ans="";
    cin >> N;
    while(N){
        N--;
        ans+=(char)('a'+(N%26));
        N/=26;
    }
    reverse(all(ans));
    cout << ans << endl;
}

Measured memory_bytes: 3604
//	-*- mode: C++ -*-
//	Selection Sort
//		Write a program of the Selection Sort algorithm which sorts a sequence A in ascending order. The algorithm should be based on the following pseudocode:
//
//		SelectionSort(A)
//		1 for i = 0 to A.length-1
//		2     mini = i
//		3     for j = i to A.length-1
//		4         if A[j] < A[mini]
//		5             mini = j
//		6     swap A[i] and A[mini]
//		Note that, indices for array elements are based on 0-origin.
//
//		Your program should also print the number of swap operations defined in line 6 of the pseudocode in the case where i ≠ mini.
//
//	Input
//		The first line of the input includes an integer N, the number of elements in the sequence.
//
//		In the second line, N elements of the sequence are given separated by space characters.
//
//	Output
//		The output consists of 2 lines.
//
//		In the first line, please print the sorted sequence. Two contiguous elements of the sequence should be separated by a space character.
//
//		In the second line, please print the number of swap operations.
//
//	Constraints
//		1 ≤ N ≤ 100
//
//	Sample Input 1
//		6
//		5 6 4 2 1 3
//	Sample Output 1
//		1 2 3 4 5 6
//		4
//
//	Sample Input 2
//		6
//		5 2 4 6 1 3
//	Sample Output 2
//		1 2 3 4 5 6
//		3

#include <iostream>
#include <vector>

unsigned int SelectionSort(std::vector<int>&	A)
{
	unsigned int swapCount	{0};

	for(unsigned int i = 0; i < A.size(); i++){
		auto	mini	= i;

		for(unsigned int j = i; j < A.size(); j++){
			if(A[j] < A[mini]){
				mini	= j;
			}
		}

		if(i != mini){
			auto	tmp	= A[i];
			A[i]		= A[mini];
			A[mini]		= tmp;
			swapCount++;
		}
	}

	return swapCount;
}

int	main(int	argc,
		 char*	argv[])
{
	unsigned int		N	{0};
	std::vector<int>	A	{};

	std::cin >> N;

	for(unsigned int i = 0; i < N; i++){
		int	element	{0};
		std::cin >> element;
		A.push_back(element);
	}

	unsigned int swapCount	= SelectionSort(A);

	unsigned int count	{0};

	for(auto element : A){
		std::cout << element;
		count++;
		if(count < N){
			std::cout << ' ';
		}
		else{
			std::cout << '\n';
		}
	}

	std::cout << swapCount << '\n';
    return 0;
}



Measured memory_bytes: 3160
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <queue>
#include <algorithm>
#include <utility>
#include <cmath>
using namespace std;
using ll=long long;
using P=pair<int,int>;
#define rep(i,a,b) for(ll i=a;i<ll(b);i++)
#define repr(i,a,b) for(ll i=a;i>=ll(b);i--)
#define endl '\n'
#define ALL(x) x.begin(),x.end()
#define ALLR(x) x.rbegin(),x.rend()
#define INF 1e9
#define DEBUG(x) cout<<"debug: "<<x<<endl
template<class T> inline bool chmin(T& a,T b){if(a>b){a=b;return 1;}return 0;}
template<class T> inline bool chmax(T& a,T b){if(a<b){a=b;return 1;}return 0;}

int n, m, ans;
int main(){
    cin >> n >> m;
    if(n > 1) ans += (n*(n-1))/2;
    if(m > 1) ans += (m*(m-1))/2;
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3144
#include <iostream>
#include <string>
#include <cstdlib>
#include <cstdio>
#include <queue>
#include <stack>
#include <list>
#include <utility>
#include <vector>
#include <set>
#include <algorithm>
#include <cmath>
#include <climits>
#include <map>
#include <unordered_map>
#include <string.h>
#include<iomanip>
#include <iterator>
#include <locale>

#define all(a) a.begin(),a.end()
#define VV(T) vector<vector< T > >
#define rep(i,N) for(int i = 0; i <N; i++)
#define repsg(i,s,g) for(int i = s; i <g; i++)
#define name(x) #x
using namespace std;


const int INF = 10000000;
const long long INFL = (1LL<<40);
const int MOD = pow(10,9)+7;
int dy[]={0, 0, 1, -1, 0};
int dx[]={1, -1, 0, 0, 0};

typedef long long ll,LL;
typedef vector<int> vint;
typedef vector<vector<int> > vvint;
typedef vector<long long> vll, vLL;
typedef vector<vector<long long> > vvll, vvLL;
typedef pair<int,int> pii;
typedef pair<LL, LL> pLL;


// vector入力
template<typename T>
istream& operator >> (istream& is, vector<T>& vec){
    for(T& x: vec) is >> x;
    return is;
}
// vector出力
template<typename T>
ostream& operator << (ostream& os, vector<T>& vec){
    for(int i=0; i<vec.size(); i++){
        os << vec[i] << ( i+1 == vec.size() ? "" : " " );
    }
    return os;
}

template< typename T >
struct edge{
    int src, to;T cost;
    edge(int to,T cost) :src(-1),to(to),cost(cost){}
    edge(int src, int to, T cost) :src(src),to(to),cost(cost){}edge
    &operator=(const int &x){
        to =x;
        return *this;
    }
    operator int() const{ return to;}
};

int getDigit(int num){
    return log10(abs(num))+1;
}
int main() {
    int a,b;cin>>a>>b;
    int c = b + a*pow(10,getDigit(b));

    if((int)sqrt(c)*(int)sqrt(c)==c)cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
    
    return 0;
}







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

using namespace std;

double p[302][302][302];	//p[a][b][c] = prob to get to a,b,c
double ev[302][302][302];	//ev[a][b][c] = expected numbers of move to get to a,b,c

int main() {
	int n; cin >> n;
	vector<int> count(4);
	for (int i = 0; i < n; i++) {
		int cur; cin >> cur;
		count[cur]++;
	}

	p[count[1]][count[2]][count[3]] = 1;
	//We start from the end since our start state is with big numbers
	//Better to start with c since c never increases whereas a and b do increase in the next state
	//When eating from a 3-plate or 2-plate
	for (int c = n; c >= 0; c--) {
		for (int b = n; b >= 0; b--) {
			for (int a = n; a >= 0; a--) {
				if (a + b + c > n) { continue; }
				if (a == 0 && b == 0 && c == 0) { continue; }

				double pWaste = (double) (n - (a + b + c)) / n;	
				//eWaste = pWaste + pWaste^2 + ... = 1/(1-pWaste)-1
				double evWaste = 1 / (1 - pWaste) - 1.0;
				ev[a][b][c] += (evWaste + 1) * p[a][b][c];

				//We get the probabilities assuming we don't waste the move
				if (a) {
					double curP = (double)a / (a + b + c);
					p[a - 1][b][c] += p[a][b][c] * curP;
					ev[a - 1][b][c] += ev[a][b][c] * curP;
				}
				if (b) {
					double curP = (double)b / (a + b + c);
					p[a+1][b-1][c] += p[a][b][c] * curP;
					ev[a+1][b-1][c] += ev[a][b][c] * curP;
				}
				if (c) {
					double curP = (double)c / (a + b + c);
					p[a][b+1][c-1] += p[a][b][c] * curP;
					ev[a][b+1][c-1] += ev[a][b][c] * curP;
				}
			}
		}
	}

	cout << setprecision(9) << fixed << ev[0][0][0] << endl;
}

Measured memory_bytes: 430336
#include<bits/stdc++.h>
#define range(i,a,b) for(int i = (a); i < (b); i++)
#define rep(i,b) for(int i = 0; i < (b); i++)
#define all(a) (a).begin(), (a).end()
#define show(x)  cerr << #x << " = " << (x) << endl;

#define int long long

const int LOG = 20;
const int MAX_N = 100005;

const int INF = 1e8;
using namespace std;

int t[LOG][MAX_N];

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

	int n;
	cin >> n;

	vector<int> x(n);
	rep(i,n) cin >> x[i];

	rep(i,LOG) rep(j,MAX_N) t[i][j] = INF;

	int l, q;
	cin >> l >> q;

	//rep(i,n){ cerr << x[i] << ' '; } cerr << endl;

	rep(i,n){
		int right = n, left = 0;
		rep(j,LOG){
			int mid = (right + left ) / 2;
			if(x[mid] <= x[i] + l) left = mid;
			else right = mid;
		}

		t[0][i] = left;
	}

	rep(i,LOG - 1){
		rep(j,MAX_N){
			if(t[i][j] == INF) continue;
			t[i + 1][j] = t[i][ t[i][j] ];
		}
	}

	rep(i,q){
		int a, b;
		cin >> a >> b;
		a--; b--;
		if(a > b) swap(a,b);

		long long ans = 0;
		for(int i = LOG - 1; i >= 0; i--){
			if(t[i][a] < b){
				a = t[i][a];
				ans += (1LL << i);
			}
		}
		cout << ans + 1 << endl;
	}
}


Measured memory_bytes: 17280
N,M,K = map(int,input().split())
A = list(map(int,input().split()))
B = list(map(int,input().split()))
na = len(A)
nb = len(B)
total_A = [0]
total_B = [0]
for i in range(1,na+1):
  ta = total_A[i-1] + A[i-1]
  total_A.append(ta)
for i in range(1,nb+1):
  tb = total_B[i-1] + B[i-1]
  total_B.append(tb)
ans = 0
b_start = 0
a = 0
total = 0
nna = na + 1
nnb = nb + 1
for i in range(nna):
  a = total_A[i]
  for j in range(b_start,nnb):
    b = total_B[nnb-1-j]
    if a+b <= K:
      b_start = j
      total = i + (nnb-1-j)
      ans = max(ans,total)
      break
print(ans)

Measured memory_bytes: 49040
N = gets.to_i
F = Array.new(N) { gets.split.map(&:to_i) }
P = Array.new(N) { gets.split.map(&:to_i) }

max = -Float::INFINITY
[0, 1].repeated_permutation(10).each do |seq|
  next if seq.all? { |x| x == 0 }
  
  sum = 0
  N.times do |i|
    cnt = 0
    10.times do |j|
      if F[i][j] == 1 and seq[j] == 1
        cnt += 1 
      end
    end
    sum += P[i][cnt]
  end
  max = [max, sum].max
end
puts max

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

using namespace std;
#define all(a)a.begin(),a.end()
using ll=long long;
const int INF = 1<<30;
const ll INFll =1LL<<62;
const int mod =(1e9)+7;
using P = pair<ll,ll>;

struct edge{
    ll to,cost;
    edge(ll to,ll cost):to(to),cost(cost){}
};
vector<vector<edge>>g;
vector<ll>d;
void dfs(ll v,ll now,ll p=-1){
    d[v]=now;
    for(auto &u:g[v]){
        if(p==u.to)continue;
        dfs(u.to,now+u.cost,v);
    }
}

int main(){
    ll n;cin >>n;
    d.resize(n);
    g.resize(n);
    for (int i = 0; i < n-1; ++i) {
        ll a,b,c;cin >>a>>b>>c;
        a--,b--;
        g[a].push_back({b,c});
        g[b].push_back({a,c});
    }
    ll q,k;cin >>q>>k;
    k--;
    dfs(k,0);
    for (int i = 0; i < q; ++i) {
        ll x,y;cin >>x>>y;
        x--;y--;
        cout <<d[x]+d[y]<<endl;
    }
    return 0;
}

Measured memory_bytes: 14336
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <cmath>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <complex>
#include <unordered_map>
#include <unordered_set>
#include <random>
#include <cassert>
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;

int main()
{
	int n, k; cin>>n>>k;
	int a[100]; for(int i=0; i<n; i++) cin>>a[i];
	bool dp[100001];
	dp[0]=0;
	for(int i=1; i<=k; i++){
		dp[i]=0;
		for(int j=0; j<n; j++){
			if(i>=a[j] && !dp[i-a[j]]){
				dp[i]=1;
				break;
			}
		}
	}
	if(dp[k]) cout<<"First"<<endl;
	else cout<<"Second"<<endl;
	return 0;
}

Measured memory_bytes: 384
#include <iostream>
#include <vector>
#include <limits.h>
#include <algorithm>
#include <string>
#include <math.h>
#include <limits.h>
#include <queue>
#include <map>
#include <set>
#include <iomanip>
#include <bitset>
#include <cassert>
#include <random>
#include <functional>
#include <stack>
#include <iomanip>
using namespace std;

//空vectorを要素数NのsegTreeとしてzで初期化
template<class T>
void segTree_init(vector<T>& vec, int N, T z) {
	int RN = 1;
	while (RN < N)RN *= 2;
	vec.resize(2 * RN, z);
}

//vecをsegTreeとしてn番目をxに
template<class T>
void segTree_set(vector<T>& vec, int n, T x, function<T(T, T)> f, int k = -1) {
	int RN = (vec.size() + 1) / 2;
	if (k == -1) {
		k = n + RN;
		vec[k] = x;
		segTree_set(vec, n, x, f, k / 2);
	}
	else if (k != 0) {
		vec[k] = f(vec[2 * k], vec[2 * k + 1]);
		segTree_set(vec, n, x, f, k / 2);
	}
}

//vecがsegTreeの時の、n番目の要素
template<class T>
T segTree_at(vector<T>& vec, int n) {
	int RN = (vec.size()) / 2;
	return vec[RN + n];
}

//get [a,b]
template<class T>
T segTree_get(vector<T>& vec, int a, int b, function<T(T, T)> f, T e, int k = 1, int l = 0, int r = -1) {
	if (r == -1)r = vec.size() / 2 - 1;
	if (b < l || r < a)return e;
	else if (a <= l && r <= b)return vec[k];
	else return f(
		segTree_get(vec, a, b, f, e, 2 * k, l, (l + r) / 2),
		segTree_get(vec, a, b, f, e, 2 * k + 1, (l + r) / 2 + 1, r)
	);
}

int N;
typedef pair<int, int> pii;
vector<int> A;
vector<long long> DP;
vector<pii> H;   //高さ、添え字
std::function<long long(long long,long long)> lambda = [](long long a, long long b) {
	return max(a, b);
};

int main() {
	cin >> N;
	H.resize(N);
	A.resize(N);
	for (int n = 0; n < N; n++) {
		cin >> H[n].first;
		H[n].second = n;
	}
	for (int n = 0; n < N; n++)cin >> A[n];
	segTree_init(DP, N, (long long)0);
	sort(H.begin(), H.end(), [](pii a, pii b) {
		return a.first < b.first;
	});
	for (int n = 0; n < N; n++) {
		long long curmax = segTree_get(DP,0,H[n].second,lambda,(long long)0);
		segTree_set(DP, H[n].second, curmax+A[H[n].second], lambda);
	}
	cout << segTree_get(DP, 0, N - 1, lambda, (long long)0) << endl;
	return 0;
}

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

#define LL long long
typedef pair<int, int> pii;

template< typename T > inline void read(T &x)
{
    static char _c;
    static bool _f;

    x = 0;
    _f = 0;
    _c = getchar();

    while(_c < '0' || '9' < _c) {if(_c == '-') _f = true; _c = getchar();}
    while('0' <= _c && _c <= '9') {x = (x << 1) + (x << 3) + (_c & 15); _c = getchar();}
    if(_f) x = -x;
}

template < typename T > inline void Min(T &x, T y) {if(y < x) x = y;}
template < typename T > inline void Max(T &x, T y) {if(x < y) x = y;}


#define lowbit(x) ((x) & -(x))
#define lson l,mid,id<<1
#define rson mid+1,r,id<<1|1
#define ls id<<1
#define rs id<<1|1
#define MID(l,r) ((l)+(((r)-(l))>>1))
#define fi first
#define se second
#define mk make_pair
#define pb push_back

const int INF = 0x3f3f3f3f;
const int MOD = (int) 1e9 + 7;
//const int MOD = (int) 998244353;
const int maxn = (int) 2e5 + 20;
const int maxm = (int) 1e6 + 20;
const double pi = (double) acos(-1.0);
const double eps = (double) 1e-8;

inline int sig(double x) {return x < -eps ? -1 : eps < x;}
LL fp(LL a, LL n, LL m = MOD) {LL res = 1; for(; n; n >>= 1, a = a * a % m) if(n & 1) res = res * a % m; return res;}

int n;
pair<LL, LL> p[maxn];
queue< pair<LL, LL> > Q;
LL d, a;

void work()
{
    cin >>n;
    cin >>d >>a;
    for(int i = 0; i < n; i++)
        cin >>p[i].fi >>p[i].se;

    sort(p, p + n);

    LL now = 0;
    LL ans = 0;
    for(int i = 0; i < n; i++)
    {
        LL x = p[i].fi, h = p[i].se;
        while(Q.size() && Q.front().fi < x)
        {
            now -= Q.front().se;
            Q.pop();
        }

        if(now >= h) continue;

        LL tmp = h - now;
        LL t = (tmp + a - 1) / a;
        now += a * t;
        ans += t;
        Q.push(mk(x + d * 2, a * t));
    }
    cout <<ans <<endl;
}


int main()
{
#ifdef yukihana0416
freopen("in.txt", "r", stdin);
//freopen("out.txt", "w", stdout);
#endif // yukihana0416
//    get_prime();
    int tc = 1;
//    read(tc);
    for(int ca = 1; ca <= tc; ca++)
    {
//        printf("Case #%d: ", ca);
        work();
    }
    return 0;
}


Measured memory_bytes: 4992
#!/usr/bin/env python3
import sys
INF = float("inf")


def yes():
    print("Yes")  # type: str


def no():
    print("No")  # type: str


def solve(A: int, B: int, C: int):
    if len(set([A, B, C])) == 2:
        yes()
    else:
        no()
    return


def main():

    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    A = int(next(tokens))  # type: int
    B = int(next(tokens))  # type: int
    C = int(next(tokens))  # type: int
    solve(A, B, C)


if __name__ == '__main__':
    main()


Measured memory_bytes: 3064
n=int(input())

def number_of_divisor(n):
    ans=[0]*(n+1)
    for i in range(1,n+1):
        for j in range(i,n+1,i):
            ans[j]+=1
    return ans

divisor=number_of_divisor(n)
ans=0
for i in range(1,n+1):
    ans+=i*divisor[i]

print(ans)

Measured memory_bytes: 151660
#include<iostream>
#include<cmath>
using namespace std;
int main()
{
	int a,b,d,e,f,g,h,i=0,j,k,l,m,n;
	char c[101][101];
	cin>>a>>b;
	for(e=1;e<=a;e++)
	for(f=1;f<=b;f++)
	{
		cin>>c[e][f];
	}
	for(g=1;g<=a;g++)
	{
		for(h=1;h<=b;h++)
		{
			if(c[g][h]=='#')
			{
				cout<<"#";
			}
			else
			{
				if(c[g-1][h-1]=='#')
				i++;
				if(c[g-1][h]=='#')
				i++;
				if(c[g-1][h+1]=='#')
				i++;
				if(c[g][h-1]=='#')
				i++;
				if(c[g][h+1]=='#')
				i++;
				if(c[g+1][h-1]=='#')
				i++;
				if(c[g+1][h]=='#')
				i++;
				if(c[g+1][h+1]=='#')
				i++;
				cout<<i;
				i=0;
			}
		}
		cout<<endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
//型に気を付けよう
//a=61
#define rep(i,n) for(int i=0;i<n;i++)
typedef long long  ll;
typedef long double  ld;
typedef pair<int,int> pairii;
const double pi=3.1415926535;
const ll  mod=1000000007;
//桁数指定　cout << fixed << setprecision(2)
int main() {
  string s,t;
  cin>>s>>t;
  string ans="Yes";
  if(t.size()!=s.size()+1){
    cout<<"No"<<endl;
return 0;}
  rep(i,s.size()){
    if(s[i]!=t[i]){
      ans="No";cerr<<i;break;
    }
  }
  cout<<ans;
}

Measured memory_bytes: 3600
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Scanner;

/**
 * Created by khrom on 2017/06/11.
 */
public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in).useDelimiter("\\s");
        List<Integer> numList = new ArrayList<>();
        for (int i = 0; i < 3; i++) numList.add(scanner.nextInt());
        Collections.sort(numList);
        StringBuilder strb = new StringBuilder();
        numList.forEach(s -> strb.append(s + " "));
        strb.delete(strb.length() - 1, strb.length());
        System.out.println(strb.toString());
    }
}

Measured memory_bytes: 31412
#include<stdio.h>
#include<math.h>

struct Point {double x, y; };

void koch(int n, Point a, Point b) {
    if (n==0) return;
    Point s, t, u;
    double th = M_PI * 60.0 / 180.0;

    s.x = (2.0 * a.x + 1.0 * b.x) / 3.0;
    s.y = (2.0 * a.y + 1.0 * b.y) / 3.0;
    t.x = (1.0 * a.x + 2.0 * b.x) / 3.0;
    t.y = (1.0 * a.y + 2.0 * b.y) / 3.0;
    u.x = (t.x - s.x) * cos(th) - (t.y - s.y) * sin(th) + s.x;
    u.y = (t.x - s.x) * sin(th) + (t.y - s.y) * cos(th) + s.y;

    koch(n-1, a, s);
    printf("%.8f %.8f\n", s.x, s.y);
    koch(n- 1, s, u);
    printf("%.8f %.8f\n", u.x, u.y);
    koch(n-1, u, t);
    printf("%.8f %.8f\n", t.x, t.y);
    koch(n-1, t, b);
}

int main() {
    Point a, b;
    int n;

    scanf("%d", &n);

    a.x = 0;
    a.y = 0;
    b.x = 100;
    b.y = 0;

    printf("%.8f %.8f\n", a.x, a.y);
    koch(n, a, b);
    printf("%.8f %.8f\n", b.x, b.y);

    return 0;

} 



Measured memory_bytes: 2720
input = readlines()
n = input.shift.chomp.to_i
list = input.shift.chomp.split("\s").map{|x| x.to_i}

cnt = 0
list.each_with_index do |l1, i1|
  list.each_with_index do |l2, i2|
    next if i2 <= i1
    list.each_with_index do |l3, i3|
      next if i3 <= i2
      tmp = [l1, l2, l3].sort
      cnt += 1 if tmp[0] + tmp[1] > tmp[2] && tmp.uniq.length == 3
    end
  end
end

puts cnt


Measured memory_bytes: 14416
import java.util.Scanner;
public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();
        int c = sc.nextInt();
        if(a == b){
            System.out.println(c);
        }
        else if(a == c){
            System.out.println(b);
        }
        else if(b == c){
            System.out.println(a);
        }

    }
}


Measured memory_bytes: 23892
#include <bits/stdc++.h>
#define int long long
using namespace std;
int a,b,l,r,L,R;
signed main()
{
	scanf("%lld%lld",&a,&b);
	if (a==b)
	{
		printf("1\n");
		return 0;
	}
	int wh,num=0;
	for (int i=63;i>=0;i--)
	{
		if (((a>>i)&1ll)!=((b>>i)&1ll))
		{
			wh=i;
			break;
		}
		else if ((a>>i)&1ll) num|=(1<<i);
	}
	r=b;
	for (int i=0;i<=wh;i++) r|=(1ll<<i);
	l=a|(1ll<<wh);
	L=a;R=b;
	for (int i=wh-1;i>=0;i--)
	{
		if ((b>>i)&1ll)
		{
			for (int j=0;j<=i;j++) R|=(1ll<<j);
			break;
		}
	}
	// printf("%lld %lld %lld %lld\n",l,r,L,R);
	if (R>=l) printf("%lld\n",r-L+1);
	else printf("%lld\n",R-L+1+r-l+1);
}

Measured memory_bytes: 3704
#include<bits/stdc++.h>
using namespace std;
char s[12345];
int main(){
	cin>>s;
	int len=strlen(s);
	long long ans=0;
	for(int t=0;t<(1<<len-1);t++){
		long long num=s[0]-'0';
		for(int i=0;i<len-1;i++){
			if(t&1<<i){
				ans+=num;
				num=0;
			}
			num=num*10+s[i+1]-'0';
		}
		ans+=num;
	}
	cout<<ans;
	return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int main(void){
    int i,m=0,f=0,r=0,cnt=0;
    char *grade[50];
    while (!(m==-1 && f==-1 && r==-1)){
        scanf("%d %d %d",&m,&f,&r);
        if (m==-1 || f==-1) grade[cnt]="F";
        else if (m+f>=80) grade[cnt]="A";
        else if (m+f>=65 && m+f<80) grade[cnt]="B";
        else if (m+f>=50 && m+f<65) grade[cnt]="C";
        else if (m+f>=30 && m+f<50 && r<50) grade[cnt]="D";
        else if (m+f>=30 && m+f<50 && r>=50) grade[cnt]="C";
        else grade[cnt]="F";
        cnt++;
    }
    for(i=0;i<cnt-1;i++) printf("%s\n", grade[i]);
    return 0;
}


Measured memory_bytes: 2036
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define mp make_pair
#define pb push_back
#define ff first
#define ss second
#define ip pair<ll,ll>
// const ll INF = 1000000000000000000;
// const ll MOD = 1000000007;

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

	int n;
	cin>>n;
	ll h[n],a[n];
	for(int i=0;i<n;i++)
		cin>>h[i];
	for(int i=0;i<n;i++)
		cin>>a[i];
	set<ip> s;
	set<ip>::iterator it;
	s.insert({0,0});
	ll ans = 0;
	for(int i=0;i<n;i++){
		it = s.lower_bound({h[i],0});
		--it;
		ll val = (*it).second + a[i];
		ans = max(ans, val);
		++it;
		vector<ip> v;
		while(it != s.end() && (*it).second <= val){
			v.pb(*it);
			it++;
		}

		for(ip x: v)
			s.erase(x);

		s.insert({h[i],val});
	}

	cout<<ans<<endl;
}


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

int main(){
	int n;
	while(1){
		int count=0;
		cin>>n;
		if(n==0)break;
		while(n!=1){
			if(n%2==0){
				n/=2;
				count++;
			}else{
				n=n*3+1;
				count++;
			}
		}
		cout<<count<<endl;
	}
	return 0;
}

Measured memory_bytes: 1160
#include <bits/stdc++.h>
#define MOD 1000000007LL
using namespace std;
typedef long long ll;
typedef pair<int,int> P;

int n,m;
vector<int> G[9];
int ans=0;
int bit=0;

void dfs(int v){
	bit+=1<<v;
	if(bit+1==1<<n){
		ans++;
	}
	for(int i=0;i<G[v].size();i++){
		if(!(bit>>G[v][i] & 1)){
			dfs(G[v][i]);
		}
	}
	bit-=1<<v;
}

int main(void){
	scanf("%d%d",&n,&m);
	for(int i=0;i<m;i++){
		int a,b;
		scanf("%d%d",&a,&b);
		a--;
		b--;
		G[a].push_back(b);
		G[b].push_back(a);
	}
	dfs(0);
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 384
package main

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

type bufReader struct {
	r   *bufio.Reader
	buf []byte
	i   int
}

var reader = &bufReader{
	bufio.NewReader(os.Stdin),
	make([]byte, 0),
	0,
}

func (r *bufReader) readLine() {
	if r.i < len(r.buf) {
		return
	}
	r.buf = make([]byte, 0)
	r.i = 0
	for {
		line, isPrefix, err := r.r.ReadLine()
		if err != nil {
			panic(err)
		}
		r.buf = append(r.buf, line...)
		if !isPrefix {
			break
		}
	}
}

func (r *bufReader) next() string {
	r.readLine()
	from := r.i
	for ; r.i < len(r.buf); r.i++ {
		if r.buf[r.i] == ' ' {
			break
		}
	}
	s := string(r.buf[from:r.i])
	r.i++
	return s
}

func (r *bufReader) nextLine() string {
	r.readLine()
	s := string(r.buf[r.i:])
	r.i = len(r.buf)
	return s
}

var writer = bufio.NewWriter(os.Stdout)

func next() string {
	return reader.next()
}

func nextInt64() int64 {
	i, err := strconv.ParseInt(reader.next(), 10, 64)
	if err != nil {
		panic(err)
	}
	return i
}

func nextInt() int {
	return int(nextInt64())
}

func nextLine() string {
	return reader.nextLine()
}

func out(a ...interface{}) {
	fmt.Fprintln(writer, a...)
}

func max64(x, y int64) int64 {
	if x > y {
		return x
	}
	return y
}

func max(x, y int) int {
	return int(max64(int64(x), int64(y)))
}

func min64(x, y int64) int64 {
	if x < y {
		return x
	}
	return y
}

func min(x, y int) int {
	return int(min64(int64(x), int64(y)))
}

func abs64(x int64) int64 {
	if x < 0 {
		return -x
	}
	return x
}

func abs(x int) int {
	return int(abs64(int64(x)))
}

func joinInt64s(a []int64, sep string) string {
	b := make([]string, len(a))
	for i, v := range a {
		b[i] = strconv.FormatInt(v, 10)
	}
	return strings.Join(b, sep)
}

func joinInts(a []int, sep string) string {
	b := make([]string, len(a))
	for i, v := range a {
		b[i] = strconv.Itoa(v)
	}
	return strings.Join(b, sep)
}

func divUp64(x, y int64) int64 {
	return (x + y - 1) / y
}

func divUp(x, y int) int {
	return int(divUp64(int64(x), int64(y)))
}

func gcd64(x, y int64) int64 {
	if x < y {
		x, y = y, x
	}
	for y != 0 {
		x, y = y, x%y
	}
	return x
}

func gcd(x, y int) int {
	return int(gcd64(int64(x), int64(y)))
}

func lcm64(x, y int64) int64 {
	return x * y / gcd64(x, y)
}

func lcm(x, y int) int {
	return int(lcm64(int64(x), int64(y)))
}

func pow64(x, y int64) int64 {
	return int64(math.Pow(float64(x), float64(y)))
}

func pow(x, y int) int {
	return int(pow64(int64(x), int64(y)))
}

func main() {
	solve()
	writer.Flush()
}

func solve() {
	r, g, b := nextInt(), nextInt(), nextInt()
	n := r*100 + g*10 + b
	if n%4 == 0 {
		out("YES")
	} else {
		out("NO")
	}
}


Measured memory_bytes: 640
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <utility>
#include <cmath>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <tuple>
#include <numeric>
#include <functional>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef pair<ll, ll> P;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define exrep(i, a, b) for(ll i = a; i <= b; i++)
#define out(x) cout << x << endl
#define exout(x) printf("%.10f\n", x)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define pb push_back
#define re0 return 0
const ll mod = 1000000007;
const ll INF = 1e16;
const double pi = acos(-1);

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

    vl v(n);
    rep(i, n) {
        ll p;
        cin >> p;
        v[p-1] = i;
    }

    ll now = 0;
    ll ma = 0;
    ll t = -1;
    rep(i, n) {
        if(t < v[i]) {
            now++;
        }
        else {
            chmax(ma, now);
            now = 1;
        }
        t = v[i];
    }
    chmax(ma, now);

    out(n - ma);
    re0;
}

Measured memory_bytes: 1792
#include <cstdio>
#include <algorithm>

using namespace std;

int main()
{
	int a[5];
	
	for (int i = 0; i < 5; i++){
		scanf("%d", &a[i]);
	}
	
	sort(a, a + 5);
	reverse(a, a + 5);
	
	for (int i = 0; i < 5; i++){
		printf("%d", a[i]);
		if (i < 4){
			printf(" ");
		}
	}
	printf("\n");
	
	return (0);
}

Measured memory_bytes: 1044
#include<bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#define INF 1000000010
#define EPS 1e-9
#define fst first
#define scd second

#define debug(x) cout<<x<<endl;
#define repi(i,x,n) for(int i=x;i<n;i++)
#define rep(i,n) repi(i,0,n)
#define lp(i,n) repi(i,0,n)
#define repn(i,n) for(int i=n;i>=0;i--)
#define int long long
#define endl "\n"


signed main(){
  cin.tie(0);	
  ios::sync_with_stdio(false);
  cout<<fixed<<setprecision(3);
  while(1){
    int n;
    cin>>n;
    if(n==0) break;
    double p[n][4],cost[101][101];
    rep(i,n) cin>>p[i][0]>>p[i][1]>>p[i][2]>>p[i][3];
    rep(i,n){
      rep(j,n){
	if(i==j) cost[i][j]=INF;
	else{
	  cost[i][j]=max((double)0,sqrt(pow(p[i][0]-p[j][0],2)+pow(p[i][1]-p[j][1],2)+pow(p[i][2]-p[j][2],2))-p[i][3]-p[j][3]);
	}
      }
    }
    double mincost[101];
    bool flag[101]={0};
    rep(i,n) mincost[i]=INF;
    mincost[0]=0;
    double ans=0;
    while(1){
      int v=-1;
      rep(i,n){
	if(!flag[i] && (v==-1 || mincost[i]<mincost[v])) v=i;
      }
      if(v==-1) break;
      flag[v]=true;
      ans+=mincost[v];
      rep(i,n){
	mincost[i]=min(mincost[i],cost[v][i]);
      }
    }
    cout<<ans<<endl;
  }
	 

  return 0;
}



Measured memory_bytes: 3328
#include <iostream>
#include <utility>
#include <vector>
int main(){
  using namespace std;
  int N, r[3];
  cin >> N >> r[0]>>r[1]>>r[2];
  
  vector<string> in(N);
  vector<char> out(N);
  for(int i=0; i<N; i++){
    cin >> in[i];
  }
  int c = r[0] + r[1]+r[2];
  
  if(c==0){
    cout<<"No\n";
    return 0;
  }
  else if(c==1){
  	for(int i=0;i<N;i++){
      if(r[in[i][0]-'A']==0 && r[in[i][1]-'A']==0){
        cout<<"No\n";
        return 0;
      }
      out[i]=(r[in[i][0]-'A']==0 ? in[i][0] : in[i][1]);
      swap(r[in[i][0]-'A'], r[in[i][1]-'A']);
    }
  }
  else{
    for(int i=0;i<N;i++){
      int b1 = in[i][0]-'A';
      int b2 = in[i][1]-'A';
      if(r[b1]==0 && r[b2]==0){
        cout<<"No\n";
        return 0;
      }
      auto common=[&](int c1, int c2){
      	return b1==c1||b1==c2?b1:b2;
      };
      int p = r[b1]<r[b2]?b1:
      		r[b1]>r[b2]?b2:
      		i==N-1?b1:
      		common(in[i+1][0]-'A', in[i+1][1]-'A');
      
      cerr << r[0]<< " " << r[1] << " " << r[2] << " " << b1<<b2<<p<<"\n";
      out[i]=p+'A';
      r[p]++;
      r[p==b1?b2:b1]--;
    }
  }
  cout<<"Yes\n";
  for(int i=0;i<N;i++){
    cout<<out[i]<<"\n";
  }
  return 0; 
  
}  
  
  
  
  

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

int main(){
  int n,pair=0; cin>>n;
  vector<bool> flag(100001,false);
  for(int i=0;i<n;i++){
    int a; cin>>a;
    if(flag[a]) pair++;
    else flag[a]=true;
  }
  n-=pair;
  if(n%2==0) n--;
  cout<<n<<endl;
}

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

int main() {
  
  int a, b;
  cin >> a >> b;
  
  if(a > b){
    for(int i = 0; i < a; i++){
      cout << b;
    }
  }
  else{
    for(int i = 0; i < b; i++){
      cout << a;
    }
  }  
 
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep0(i,n) for(ll (i) = 0; (i) < (n); ++(i))
#define rrep0(i,n) for(ll (i) = (n) - 1; (i) >= 0; --(i))
#define rep1(i,n) for(ll (i) = 1; (i) <= (n); ++(i))
#define rrep1(i,n) for(ll (i) = (n); (i) >= 1; --(i))
#define nfor(i,a,b) for(ll (i) = (a); (i) < (b); ++(i))
#define rfor(i,a,b) for(ll (i) = (a); (i) > (b); --(i))
#define ll long long
#define mod (1000000007)
#define YES cout << "YES" << endl;
#define Yes cout << "Yes" << endl;
#define yes cout << "yes" << endl;
#define NO cout << "NO" << endl;
#define No cout << "No" << endl;
#define no cout << "no" << endl;
#define all(x) (x).begin(),(x).end()

ll gcd(ll a,ll b){
    if(b == 0) return a;
    return gcd(b,a%b);
}

ll lcm(ll a,ll b){
    ll g = gcd(a,b);
    return a / g * b;
}

ll factorial(ll n){
    ll t = 1;
    rep1(i, n)t *= i;
    return t;
}

ll combinations(ll n, ll k) {
    ll r = 1;
    for (ll d = 1; d <= k; ++d) {
        r *= n--;
        r /= d;
    }
    return r;
}

int main()
{
    string s;
    ll ans = 0,cnt;
    cin >> s;
    rep0(i, (1 << (s.size() - 1))){
        cnt = 0;
        rep0(j, s.size()){
            cnt += s[j] - 48;
            if((i >> j) & 1){
                cnt *= 10;
            }else{
                ans += cnt;
                cnt = 0;
            }
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
use std::io::*;
use std::str::FromStr;
   
fn read<T: FromStr>() -> T {
	let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

fn main() {
	let r: u32 = read();

	println!("{}", r*r);
}

Measured memory_bytes: 4352
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
#define rep(i,N) for(int i = 0; i < (N); i++)
#define erep(i,N) for(int i = N; i >= 0; i--)
#define PI 3.1415926535

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

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

char upper(char c){
    if('a' <= c && c <= 'z'){
        c = c - ('a' - 'A');
    }
    return c;
}

char lower(char c){
    if('A' <= c && c <= 'Z'){
        c = c + ('a' - 'A');
    }
    return c;
}

const ll INF = 1000000000000000000;

//input
int N;
vector<int> A(200050);

//processing
vector<int> B(200050);


//dpTable
int dp[100050];

int main(){
    cin >> N;
    for (int i = 0; i < N; i++){
        cin >> A.at(i);
        B.at(i) = A.at(i);
    }
    sort(B.begin(),B.end());
    reverse(B.begin(),B.end());
    ll A1 = B.at(0),A2 = B.at(1);
    for (int i = 0; i < N; i++){
        if (A.at(i) == A1){
            cout << A2 << endl;
        }
        else {
            cout << A1 << endl;
        }
    }
    return 0;
}

Measured memory_bytes: 3200
#include<bits/stdc++.h>
using namespace std;
const int N=200010,p=1e9+7;
int n,base;
int a[N],b[N];
int dp[4010][4010];
int fac[40010],inv[40010];
int mpow(int a,int n){
    int ret=1;
    while(n){
        if(n&1)ret=1ll*ret*a%p;
        a=1ll*a*a%p;
        n/=2;
	}
	return ret;
}
int C(int n,int m){
    return 1ll*fac[n]*inv[m]%p*inv[n-m]%p;
}
int main(){
//	freopen("1.in","r",stdin);
	
    cin>>n;
    for(int i=1;i<=n;++i){
        scanf("%d%d",a+i,b+i);
        base=max(base,max(a[i],b[i]));
	}
	base++;
	for(int i=1;i<=n;++i){
	    dp[base-a[i]][base-b[i]]++;
	}
	int nn=base*2-1;
	for(int i=1;i<=nn;++i){
	    for(int j=1;j<=nn;++j){
	        dp[i][j]=(dp[i][j]+dp[i-1][j]+dp[i][j-1])%p;
		}
	}
//	for(int i=1;i<=nn;++i){
//	    for(int j=1;j<=nn;++j){
//	        cout<<dp[i][j]<<' ';
//		}
//		puts("");
//	}
    fac[0]=1;
    for(int i=1;i<=40000;++i){
        fac[i]=(1ll*fac[i-1]*i)%p;
	    inv[i]=mpow(fac[i],p-2);
	}
	int ans=0;
	for(int i=1;i<=n;++i){
	    ans=ans+dp[base+a[i]][base+b[i]];
	    ans%=p;
	    ans-=C(2*a[i]+2*b[i],2*a[i]);
	    ans%=p;ans+=p;ans%=p;
	}
	ans=1ll*ans*inv[2]%p;
	cout<<ans<<endl;
}

Measured memory_bytes: 64896
#include <bits/stdc++.h>
#define rep(i,a) for(int i=0;i<int(a);++i)
#define REP(i,a,b) for(int i=int(a);i<int(b);++i)
#define pb push_back
#define mp make_pair
#define F first
#define S second
using ll = long long;
using itn = int;
using namespace std;
using Graph = vector<vector<int>>;
static const long double GRATIO=(long double)(1+sqrt(5))/2;
ll GCD(ll a, ll b){
    return b ? GCD(b, a%b) : a;
}
ll LCM(ll a, ll b){
    return a/GCD(a,b)*b;
}
int main(){
    ll A,B;
    cin>>A>>B;
    ll a = GCD(A,B);
    ll r=2,ans=1;
    while(a>=r*r){
        if(a%r==0){
            a/=r;
            if(a%r) ans++;
        }else{
            r++;
        }
    }
    if(a>1) ans++;
    cout<<ans<<endl;
}


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

int main(){
  char s[200005];  scanf("%s", s);
  int start = 0, end = 1;
  int length = strlen(s);
  int count = 0;
  while(end <= length){
//    for(int i=start; i<end; i++)  printf("%c", s[i]);  puts("");
    count++;
    int news = end, newe = end + 1;
    while(1){
      if(end-start != newe-news){
	start = news,  end = newe;
	break;
      }else{
	int flag = 0;
	for(int i=0; i<(end-start); i++)
	  if(s[start+i] != s[news+i]){
	    flag = 1;
	    break;
	  }
	if(flag){
	  start = news,  end = newe;
	  break;
	}else{
	  newe++;
	}
      }
    }
  }
  printf("%d\n", count);
  return 0;
}


Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
char a[101];
int main(){
	int n,s=0;
	cin>>n;
	cin>>a;
	for(int i=2;i<=n;i++){
		if(a[i-2]=='A'&&a[i-1]=='B'&a[i]=='C')
			s++;
	}
	cout<<s;
	return 0;
}

Measured memory_bytes: 256