akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>

#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 INF 1e9
#define ALL(v) v.begin(), v.end()

using namespace std;

typedef long long ll;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    ll k,a,b;
    cin>>k>>a>>b;

    if (a < b-2) {
        ll bis = 1;
        ll m = 0;
        REP(i, k) {
            if (m >= 1) {
                --m;
                bis += b;
                continue;
            }
            if (bis >= a && k-i >= 2) {
                bis -= a;
                ++m;
                continue;
            }
            ++bis;
        }
        cout << bis << "\n";
    } else {
        cout << k+1 << "\n";
    }
    return 0;
}

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

void Main() {
    // input
    int N, M;
    cin >> N >> M;

    // process


    // output
    if (M == N) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }

}

int main() {
    std::cout << std::fixed << std::setprecision(15);
    Main();
    return 0;
}


Measured memory_bytes: 3612
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define pf push_front
#define fi first
#define se second
#define si size()
#define bk back()
#define popb pop_back()
#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
#define endl "\n"
#define lb lower_bound
#define ub upper_bound
#define emp empty()
#define beg begin()
#define en end()
#define ump unordered_map
#define forl(i,a,n) for(int i=a;i<n;i++)
#define rfor(i,n,a) for(int i=n;i>=a;i--)
#define fore(i,a,n) for(int i=a;i<=n;i++)
#define len length()

//use (__int128)to extend ll range
double doINF = 1.0/0.0 ;
ostream_iterator <int> outp(cout," ");
inline ll modadd(ll n,ll m,ll mod){
    ll sum = ((n+m)%mod+mod)%mod;
    return sum;
} 
inline ll modsub(ll n,ll m, ll mod){
    ll diff = ((n-m+mod)%mod+mod)%mod;
    return diff;
}
inline ll modpro(ll n,ll m,ll mod){
    ll pro = ((n*m)%mod+mod)%mod;
    return pro;
}
inline ll pow(int x,int y){
    ll res = 1;
    while (y > 0) {
        if (y & 1)
            res = res * x;
        y = y >> 1;
        x = x * x;
    }
    return res;
}
inline ll powmod(ll x,ll y,ll mod){
    ll res = 1;
    while (y > 0) {
        if (y & 1)
            res = modpro(res , x,mod);
        y = y >> 1;
        x = modpro(x , x,mod);
    }
    return res;
}
ll min(ll a, ll b){
   if(a>b){
       return b;
   }
   return a;
}

ll max(ll a, ll b){
   if(a>b){
       return a;
   }else return b;
}
 
bool pairdec(const pair<int,int> &a,  
               const pair<int,int> &b) 
{ 		if(a.fi!=b.fi)
       	return (a.fi> b.fi);
		else return a.se>b.se;  
} 
ll power(ll x, ll y, ll mod) 
{ 
    ll res = 1; 
    x = x%mod; 
    while (y > 0) { 
        if (y & 1) 
            res = (res * x) % mod; 
  
        y = y >> 1;
        x = (x * x) % mod; 
    } 
    return res; 
} 
ll modInverse(ll a, ll mod) 
{ 
    return  powmod(a, mod - 2, mod); 
} 
ll modFact(ll n, ll mod) 
{ 
    if (n >=mod) 
        return 0; 
  
    ll result = 1; 
    for (ll i = 1; i <= n; i++) 
        result = (result * i) %mod; 
  
    return result; 
} 
//cout<<setprecision(9)<<fixed<<sum<<endl; --- precision for double numbers
//copy(v.beg,v.en,outp);
//-----comparision for pairs------
 
bool comp(const pair<int,int>pia,const pair<int,int>pib)
{
	if(pia.fi==pib.fi) return pia.se>pib.se;
	else return pia.fi>pib.fi;
}
int main()
{
  
    ll a,b,c;
    cin>>a>>b>>c;
    swap(a,b);
    swap(a,c);
    cout<<a<<" "<<b<<" "<<c<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define  f(i,n)       for(int i=0; i<n; i++)
#define  ff(i,j,n)    for(int i=int(j);i<=int(n);++i)
#define  sf(i)        scanf("%d",&i)
#define  pf(i)        printf("%d",i)
#define  pb(x)        push_back(x);
#define  in(x)        int x; cin>>x;
#define  w(t)         int t; cin>>t; while(t--)
#define  d(x)         cout<<x<<"\n"
#define  endl         "\n"
#define  fopen        freopen("in.txt", "r" , stdin),freopen("out.txt", "w" , stdout)
#define  fastio       ios::sync_with_stdio(0),cin.tie(0)
#define  PI           acos(-1.0)
#define  all(v)       v.begin(),v.end()
#define  mem(a,value) memset(a,value,sizeof(a))
#define  vi           vector<int>

typedef long long     ll;

const int mod = 1000000007;
using namespace std;

int main() {
    in(n);

    int flag = 0 ;

    while(n) {
        int k = n %10;
        n/=10;
        if(k == 7)
            flag =1;
    }

    cout<<(flag?"Yes":"No")<<endl;
}





Measured memory_bytes: 3588
#include <algorithm>
#include <cmath>
#include <iostream>
#include <iomanip>

using namespace std;

const double PI = acos(-1.0);

int main() {
	int n;
	cin >> n;
	int amin = 1000000, amax = -1000000;
	long sum = 0;
	for (int i = 0; i < n; i++) {
		int a;
		cin >> a;
		amin = min(amin, a);
		amax = max(amax, a);
		sum += a;
	}
	cout << amin << " " << amax << " " << sum << endl;
	return 0;
}



Measured memory_bytes: 3092
#include <bits/stdc++.h>
#define REP(i, m, n) for(int (i) = (m); (i) < (n); ++i)
#define rep(i, n) REP(i, 0, n)
#define all(x) (x).begin(), (x).end()
using namespace std;
using Graph = vector<vector<int>>;
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; }
typedef long long ll;
typedef pair<int, int> P;
typedef pair<ll, ll> PL;
const int MOD = 1e9+7;
const int INF = 1<<30;
const ll LINF = 1LL<<60;

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

    double x;
    cin >> x;

    double a = 100.0;
    int i = 0;
    while(a < x) {
        a *= 1.01;
        a = floor(a);
        i++;
    }

    cout << i << endl;
    

    return 0;
}

Measured memory_bytes: 3740
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		String str = String.valueOf(n);
		int len = str.length();
		
		List<String> list = new ArrayList<String>();
		dfs(list,"",len);
		int count = 0;
		for(int i=0; i<list.size(); i++) {
			if(Integer.parseInt(list.get(i))<=n) {
				count++;
			}
		}
		System.out.println(count);
	}

	private static void dfs(List<String> list, String res, int len) {
		if(res.length() == len+1) {
			return;
		}else {
			if(res.contains("7")&&res.contains("5")&&res.contains("3")) {
				list.add(res);
			}
			dfs(list, res + "7", len);
			dfs(list, res + "5", len);
			dfs(list, res + "3", len);
		}
	}
}


Measured memory_bytes: 36024
#include <stdio.h>
#include <cmath>
#include <algorithm>
#include <cfloat>
#include <stack>
#include <queue>
#include <vector>
#include <string>
#include <iostream>
#include <set>
#include <map>
#include <time.h>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;

#define NUM 2147483647


class RMQ{
public:
	RMQ(int height,int first_N){
		rmq_H = height;
		N = 1;
		while(N < first_N)N *= 2;
		table = new int*[height];
		for(int row = 0; row < height; row++){
			table[row] = new int[2*N-1];
			for(int col = 0; col < 2*N-1; col++){
				table[row][col] = NUM;
			}
		}
	}

	void update(int row,int loc,int value){
		loc += N-1;

		table[row][loc] = value;

		if(N == 1)return;

		int parent = (loc-1)/2;

		while(true){
			table[row][parent] = min(table[row][2*parent+1],table[row][2*parent+2]);

			if(parent == 0)break;
			else{
				parent = (parent-1)/2;
			}
		}
	}

	int getN(){
		return N;
	}

	int query(int row,int search_left,int search_right,int node_id,int node_left,int node_right){

		if(search_right < node_left || search_left > node_right)return NUM;

		if(search_left <= node_left && search_right >= node_right){
			return table[row][node_id];
		}

		int left_min = query(row,search_left,search_right,2*node_id+1,node_left,(node_left+node_right)/2);
		int right_min = query(row,search_left,search_right,2*node_id+2,(node_left+node_right)/2+1,node_right);

		return min(left_min,right_min);
	}

	int** table;
	int N,rmq_H;
};


int H,W,Q;

void func(){

	int** input = new int*[H];
	for(int row = 0; row < H; row++){
		input[row] = new int[W];
	}

	for(int row = 0; row < H; row++){
		for(int col = 0; col < W; col++)scanf("%d",&input[row][col]);
	}

	if(W >= H){
		RMQ YOKO(H,W);
		for(int row = 0; row < H; row++){
			for(int col = 0; col < W; col++){
				YOKO.update(row,col,input[row][col]);
			}
		}

		int row1,col1,row2,col2;
		int ans;

		for(int loop = 0; loop < Q; loop++){
			scanf("%d %d %d %d",&row1,&col1,&row2,&col2);

			ans = NUM;

			for(int row = row1; row <= row2; row++){
				ans = min(ans,YOKO.query(row,col1,col2,0,0,YOKO.getN()-1));
			}
			printf("%d\n",ans);
		}
	}else{

		RMQ TATE(W,H);
		for(int col = 0; col < W; col++){
			for(int row = 0; row < H; row++){
				TATE.update(col,row,input[row][col]);
			}
		}

		int row1,col1,row2,col2;
		int ans;

		for(int loop = 0; loop < Q; loop++){
			scanf("%d %d %d %d",&row1,&col1,&row2,&col2);

			ans = NUM;

			for(int col = col1; col <= col2; col++){
				ans = min(ans,TATE.query(col,row1,row2,0,0,TATE.getN()-1));
			}
			printf("%d\n",ans);
		}
	}
}


int main(){

	while(true){
		scanf("%d %d %d",&H,&W,&Q);
		if(H == 0 && W == 0 && Q == 0)break;

		func();
	}

	return 0;
}

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

int main(){
    int n;
    string s;
    cin >>n;
    cin >> s;

    string t = s.substr(0, n/2);

    if (s == t+t){
        cout << "Yes" << endl;
    }
    else {
        cout << "No" << endl;
    }
    
    return 0;
}

Measured memory_bytes: 3640
N = int(input())
data = []
for _ in range(N):
	A = int(input())
	items = []
	for __ in range(A):
		x, y = map(int, input().split())
		items.append((x - 1, y))
	data.append(items)
 
best = 0
 
def check(i):
    for j in range(N):
        if ((i >> j) & 1) == 1:           
            for x, y in data[j]:
                if y !=((i >> x) & 1):return False						
    return True
 
for i in range(2**N):
    count=0
    for j in range(N):count += ((i >> j) & 1)
    if count>best:
        if check(i):best = count
	
print(best)

Measured memory_bytes: 3064
#include<iostream>
using namespace std;
typedef long int li;
#define df 0
#define MAX 10000000
#define rep(i,n) for(int i=0;i<(n);i++)


int main(){
  int n; cin >>n;
  li s=0, sq=0;
  rep(i,n){
    int d; cin >>d;
    s+=d; sq+=d*d;
  }
  printf("%d",(s*s-sq)/2);
}

/// confirm df==0 ///


Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
const int MAX_N = 105;
const int dir[4][2] = {{-1, 0}, {0, 1}, {1, 0}, {0, -1}};
char map[MAX_N][MAX_N];
bool visited[MAX_N][MAX_N];
int W, H, num;

void dfs(int x, int y) {
	visited[x][y] = true;
	for (int i = 0; i < 4; i++) {
		int to_x = x + dir[i][0], to_y = y + dir[i][1];
		if (0 <= to_x && to_x < H && 0 <= to_y && to_y < W
				&& ! visited[to_x][to_y]
				&& map[x][y] == map[to_x][to_y]
		   ) dfs(to_x, to_y);
	}
}

int main() {
	while (scanf("%d%d", &H, &W) == 2 && H) {
		for (int i = 0; i < H; i++)
			scanf("%s", map[i]);
		num = 0;
		memset(visited, false, sizeof(visited));
		for (int i = 0; i < H; i++)
			for (int j = 0; j < W; j++)
				if (! visited[i][j]) {
					num++;
					dfs(i, j);
				}
		printf("%d\n", num);
	}
	return 0;
}

Measured memory_bytes: 1680
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		String s = in.next();
		boolean ans = true;
		for(int i=0;i<s.length();i++) {
			if(i%2==0 && s.charAt(i)=='L') {
				ans = false;
				break;
			}else if(i%2==1 && s.charAt(i)=='R') {
				ans = false;
				break;
			}
		}
		System.out.println(ans?"Yes":"No");
		in.close();

	}

}


Measured memory_bytes: 21716
#include <bits/stdc++.h>
using namespace std;
#define REP(i,a) for(int i = 0; i < (a); i++)
typedef long long ll;
typedef pair<int, int> P;
const int INF = 1e9;
const int MOD = 1e9 + 7;

int main(){
	long double n,k;
	cin >> n >> k;
	int j = 0;
	while(pow(2, j) < k) j++;
	int m = j;
	int i;
	int l = 1,child = 0;
	for(i = 1; i <= n; i++){
		if(i >= k) break;
		if(i * pow(2, j - 1) >= k){
			j--;
			l *= 2;
		}
		child += l;
	}
	if(i != n + 1)cout << setprecision(15)<< child / (n * pow(2, m)) + (1 / n) * (n - k + 1) << endl;
	else cout << setprecision(15) << child / (n * pow(2, m)) << endl; 
}

Measured memory_bytes: 256
<?php

fscanf(STDIN, "%d", $n);

$v_arr = [];

$u_arr = [];
for ($i = 0; $i < $n; ++$i) {
    $u_arr[$i] = array_fill(0, $n, 0);
}

for ($i = 0; $i < $n; ++$i) {
    $inputs = explode(' ', trim(fgets(STDIN)));
    $v_arr[] = $inputs[0];

    for ($j = 0; $j < $inputs[1]; ++$j) {
        $u_arr[$i][$inputs[$j + 2] - 1] = 1;
    }
}

foreach ($u_arr as $u) {
    echo implode(' ', $u), PHP_EOL;
}



Measured memory_bytes: 10172
#include <stdio.h>
#include <stdlib.h>
#define N 255
 
int Parent(int i){
  return i/2;
}
 
int Left(int i){
  return 2*i;
}
 
int Right(int i){
  return 2*i+1;
}
 
int check(int n,int i){
  if(n>=Right(i)) return 1;//右側もある
  else if(n>=Left(i) && n<Right(i)) return 2;//右側がない
  else if(n<Left(i)) return 3;//左側すらない（ラスハイ）
}
 
main(){
  int n,i;
  int A[N];
 
  scanf("%d",&n);
 
  for(i=1;i<=n;i++){
	 scanf("%d",&A[i]);
 }

  for(i=1;i<=n;i++){
    if(i==1){
      if(check(n,i)==1) printf("node %d: key = %d, left key = %d, right key = %d, \n",i,A[i],A[Left(i)],A[Right(i)]);
      else if(check(n,i)==2) printf("node %d: key = %d, left key = %d, \n",i,A[i],A[Left(i)]);
      else if(check(n,i)==3) printf("node %d: key = %d, \n",i,A[i]);
    }
    else{
      if(check(n,i)==1) printf("node %d: key = %d, parent key = %d, left key = %d, right key = %d, \n",i,A[i],A[Parent(i)],A[Left(i)],A[Right(i)]);
      else if(check(n,i)==2) printf("node %d: key = %d, parent key = %d, left key = %d, \n",i,A[i],A[Parent(i)],A[Left(i)]);
      else if(check(n,i)==3)printf("node %d: key = %d, parent key = %d, \n",i,A[i],A[Parent(i)]);
    }
  }
 
  return 0;
}

Measured memory_bytes: 596
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#include <iomanip>
#include <math.h>
#include <string.h>
#include <cstdio>
#include <tuple>
#include <numeric>
#include <time.h>
#include <chrono>
#ifdef _MSC_VER
#  include <intrin.h>
#  define __builtin_popcount __popcnt
#endif
#define FOR(i,a,b) for(ll i=a;i<b;i++)
#define REP(i,a,b) for(ll i=a;i>b;i--)
#define CST(x) cout<<fixed<<setprecision(x)//小数点以下の桁数指定
#define ct(a) cout<<a<<endl
#define rep(i,n) for(int i=0;i<(n);i++)
#define repl(i,l,r) for(int i=(1);i<(r);i++)
#define per(i, n) for(int i = ((n)-1); i >= 0; i--)
static const double pi = 3.141592653589793;
using namespace std;
typedef long long ll;
const ll MOD = 998244353;
const ll INF = (1LL << 31) - 1;
const ll mod = 1e9 + 7;


ll A,B,C,K;



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

	cin >> A >> B >> C>>K;

	while (B <= A) {
		K--;
		B *= 2;
	}
	while (C <= B) {
		K--;
		C *= 2;
	}

	if (K >= 0)cout << "Yes" << endl;
	else cout << "No" << endl;



	return 0;
}

Measured memory_bytes: 3648
#include <bits/stdc++.h>
#define ll long long
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define pii pair<int,int>
#define pll pair<ll,ll>
#define pcc pair<char,char>
#define vi vector <int>
#define vl vector <ll>
#define sd(x) scanf("%d",&x)
#define slld(x) scanf("%lld",&x)
#define pd(x) printf("%d",x)
#define plld(x) printf("%lld",x)
#define pds(x) printf("%d ",x)
#define pllds(x) printf("%lld ",x)
#define pdn(x) printf("%d\n",x)
#define plldn(x) printf("%lld\n",x)
#define INF 2e9
#define INFLL 4e18
using namespace std;
ll powmod(ll base,ll exponent,ll mod){ // with mod < 1e9
	ll ans=1;
	while(exponent){
		if(exponent&1)ans=(ans*base)%mod;
		base=(base*base)%mod;
		exponent/=2;
	}
	return ans;
}
ll gcd(ll a, ll b){
	if(b==0) return a;
	else return gcd(b,a%b);
}
const int upperlimit = 1e6+1;
const int mod = 1e9+7;

int main() {
      string s;
      cin >> s;
      if(s == "ARC"){
        cout << "ABC";
      }
      else
        cout << "ARC";
	return 0;
}


Measured memory_bytes: 3632
# -*- coding: utf-8 -*-
""" インプットの時間比較 """
from sys import stdin
import numpy as np
# import sys
# sys.setrecursionlimit(10**4)

def _li(): return list(map(int, stdin.readline().split()))
def _li_(): return list(map(lambda x: int(x)-1, stdin.readline().split()))
def _lf(): return list(map(float, stdin.readline().split()))
def _ls(): return stdin.readline().split()
def _i(): return int(stdin.readline())
def _f(): return float(stdin.readline())
def _s(): return stdin.readline()[:-1]
d_in = lambda: int(stdin.readline())  # N = d_in()
ds_in = lambda: list(map(int, stdin.readline().split()))  # List = ds_in()


# N = _i()
# D_list = np.array([_i() for _ in range(N)])
N = d_in()
D_list = np.array([d_in() for _ in range(N)])


idx = np.argsort(D_list)
sorted_D = D_list[idx]
mapping = []
for j in idx:
    mapping.append(j+1)

# 解説を参考に実装
# Dのスコアが大きい方から小さい方へ伸びる有向エッジとみなす
# valueはノードから出ている有向エッジを切った場合の部分木の大きさ
nodes = [1] * N
ans = []
cost = [[0, 1] for _ in range(N)]
# 葉っぱから見て，[エッジにたどり着くまでのコスト, 自分も含めた子ノードの数]
for i in range(N-1, 0, -1):
    d = sorted_D[i]
    sub = nodes[i]
    target = d + 2*sub - N
    cand = np.searchsorted(sorted_D[:i], target)
    if (sorted_D[cand] != target) or (cand == i):
        print(-1)
        exit()
    else:
        ans.append((mapping[i], mapping[cand]))
        nodes[cand] += nodes[i]
        cost[cand][0] += (cost[i][0] + cost[i][1])
        cost[cand][1] += cost[i][1]

# 1番目のノードについてチェック
if cost[0][0] != sorted_D[0]:
    print(-1)
    exit()
else:
    for a in ans:
        print(a[0], a[1])


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

int main() {
  string S,T;
  int ans;
  cin >> S >> T;
  for(int i=0;i<3;i++){
    if(S.at(i)==T.at(i)){
      ans++;
    }
  }
  cout << ans << endl;
}


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

const int N = 2e5+100;
int a[N];
int n,k;

int main() {
    ios::sync_with_stdio(0);
    cin>>n>>k;
    for(int i=0;i<n;i++) cin>>a[i];
    sort(a,a+n);
    reverse(a,a+n);
    for(int i=0;i<min(n,k);i++) {
        a[i] = 0;
    }
    ll ans = 0;
    for(int i=0;i<n;i++) {
        ans += a[i];
    }
    cout<<ans<<endl;
    return 0;
}




Measured memory_bytes: 1024
#include<iostream>
using namespace std;
int main() {
  int H,W; cin >> H >> W;
  for(int i=0;i<W+2;i++) cout << '#';
  cout << endl;
  for(int i=0;i<H;i++){
    cout << '#';
    for(int j=0;j<W;j++){
      char c; cin >> c;
      cout << c;}
    cout << '#' << endl;
  }
  for(int i=0;i<W+2;i++) cout << '#';
  cout << endl;
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int,int>;
#define rep(i,n) for(int i=0; i<n; i++)
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end()) //sortしてから使う
#define INF 2147483647
#define LLINF 9223372036854775807LL

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

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

#define N 100001
#define INF 1001

class Edge {
    public:
        int v, w;
        Edge(int v, int w): v(v), w(w) {}
};

vector<Edge> A[N];
int color[N], d[N];

void bfs(int root) {
    queue<int> Q;
    Q.push(root);
    color[root] = 1;
    d[root] = 0;
    while(!Q.empty()) {
        int node = Q.front();
        Q.pop();
        for (vector<Edge>::iterator it = A[node].begin(); it != A[node].end(); it++) {
            Edge added = *it;
            if (color[added.v] == 0) {
                color[added.v] = 1;
                d[added.v] = d[node] + added.w;
                Q.push(added.v);
            }
        }
    }
}

void init(int n) {
    for (int i = 0; i < n; i++) {
        color[i] = 0;
        d[i] = INF;
    }
}

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

    init(n);

    int s, t, w;
    for (int i = 0; i < n - 1; i++) {
        cin >> s >> t >> w;
        Edge se = Edge(t, w);
        A[s].push_back(se);
        Edge te = Edge(s, w);
        A[t].push_back(te);
    }

    bfs(0);

    int target = -1;
    int maxValue = -1;
    for (int i = 0; i < n; i++) {
        if (d[i] > maxValue) {
            maxValue = d[i];
            target = i;
        }
    }

    init(n);
    bfs(target);

    int diameter = -1;
    for (int i = 0; i < n; i++) {
        diameter = max(diameter, d[i]);
    }

    cout << diameter << endl;

    return 0;
}



Measured memory_bytes: 10196
void main()
{
    long n, c;
    rdVals(n, c);

    long limit = 2 * 10 ^^ 5 + 1;
    long[][] lists = new long[][](c, limit);
    foreach (i; 0 .. n)
    {
        long s, t, d;
        rdVals(s, t, d);
        s = 2 * s - 1, t = 2 * t, --d;
        ++lists[d][s], --lists[d][t];
    }

    long[] record = new long[limit];
    long result;
    foreach (i; 0 .. c)
    {
        foreach (j; 1 .. limit)
        {
            lists[i][j] += lists[i][j-1];
            if (lists[i][j])
            {
                ++record[j];
                result = max(result, record[j]);
            }
        }
    }

    result.writeln;
}

enum long mod = 10^^9 + 7;
enum long inf = 1L << 60;

T rdElem(T = long)()
if (!is(T == struct))
{
    return readln.chomp.to!T;
}

alias rdStr = rdElem!string;
alias rdDchar = rdElem!(dchar[]);

T rdElem(T)()
if (is(T == struct))
{
    T result;
    string[] input = rdRow!string;
    assert(T.tupleof.length == input.length);
    foreach (i, ref x; result.tupleof)
    {
        x = input[i].to!(typeof(x));
    }
    return result;
}

T[] rdRow(T = long)()
{
    return readln.split.to!(T[]);
}

T[] rdCol(T = long)(long col)
{
    return iota(col).map!(x => rdElem!T).array;
}

T[][] rdMat(T = long)(long col)
{
    return iota(col).map!(x => rdRow!T).array;
}

void rdVals(T...)(ref T data)
{
    string[] input = rdRow!string;
    assert(data.length == input.length);
    foreach (i, ref x; data)
    {
        x = input[i].to!(typeof(x));
    }
}

void wrMat(T = long)(T[][] mat)
{
    foreach (row; mat)
    {
        foreach (j, compo; row)
        {
            compo.write;
            if (j == row.length - 1) writeln;
            else " ".write;
        }
    }
}

import std.stdio;
import std.string;
import std.array;
import std.conv;
import std.algorithm;
import std.range;
import std.math;
import std.numeric;
import std.traits;
import std.container;
import std.functional;
import std.typecons;
import std.ascii;
import std.uni;

Measured memory_bytes: 53628
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
n,k = map(int,readline().split())
lst1 = list(map(int,readline().split()))

"""
lst1に関しての全ての1の出現回数を求め、
lst1の半分より(1の出現回数が多いなら)多いならkのその桁を0に、
少ないならkのその桁を1にすることによってfは最大化される。

ただし、kには制約があるので、上位桁を優先として、制約内に収まる答えを探す。
"""
k = bin(k)
k = k[2:]
lst2 = [0]*40

for i in lst1:
    for j in range(40):
        if i >> j & 1:
            lst2[j] += 1 #1が入っているなら1足す。
lst2.reverse()
lst2 = lst2[40-len(k):]
th = n//2 #1の数がこれを下回る(th>X)場合、その桁を1にしたほうが良い

free = 0 #自由に下位桁を決められるようになったら1にする
res = 0
for i in range(len(k)):
    if not free:
        if k[i] == "1":
            if lst2[i] <= th:
                res += 1 << len(k)-1-i
            else:
                free = 1
    else:
        if lst2[i] < th:
                res += 1 << len(k)-1-i


ans = 0
for i in lst1:
    ans += i^res
print(ans)

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

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n, k;
	cin >> n >> k;
	vector<int> a(n);
	vector<int> dp(n, INT_MAX);
	for (int i = 0; i < n; i++)
	{
		cin >> a[i];
	}
	dp[0] = 0;
	//dp[1] = abs(a[1] - a[0]);
	for (int i =1; i < n; i++)
	{
		for (int j = i - 1; j >= max(0, i - k); j--)
		{
			dp[i] = min(dp[i ] , dp[j] + abs(a[j] - a[i]));
		}
		
	}
	cout << dp[n - 1];
	return 0;
}

Measured memory_bytes: 1024
#include<iostream>
#include<string>
#include<cstdio>
#include<cmath>
#include<algorithm>
#include<functional>
using namespace std;

int main(void){

  int n;
  cin>>n;
  int a[2][100];
  int max;


  for(int i=0;i<2;i++){
    for(int j=0;j<n;j++){
        cin>>a[i][j];
    }
  }
  max=0;
  int sum=0;

  for(int i=0;i<n;i++){
    sum=0;
      for(int j=0;j<n;j++){
        if(i>j)sum+=a[0][j];
        else if(i==j) sum+=a[0][j]+a[1][j];
        else sum+=a[1][j];
       // cout<<sum<<" ";
      }
     // cout<<endl;
      if(max<sum)max=sum;
  }
  cout<<max<<endl;
}

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

int main() {
  int n;
  cin>>n;
  vector<int> h(n);
  for (int i=0;i<n;i++){
    cin>>h.at(i);
  }
  
  int hotel;
  
  for (int i = 0; i < n; i++) {
    int j=0;
    bool view=1;
    
    while(view==1 and j<i){
      if(h.at(j)>h.at(i)){
        view=0;
      }
      j++;
    }
    
    hotel+=view;
  }
  
  cout<<hotel;

}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  string S;
  cin >> S;
  int64_t K;
  cin >> K;
  string T = S + S;
  bool beg_end = false;
  bool same = false;
  char x = S.at(0);
  if(S.at(0) == S.at(S.size()-1)){
    beg_end = true;
  }
  int64_t y = 0;
  for(int64_t i=0; i<S.size(); i++){
    if(S.at(i) != x){
      break;
    }
    else{
      y++;
    }
    if(i == S.size() - 1){
      same = true;
    }
  }
  int64_t cnt = 0;
  int64_t ans = 0;
  
  vector<int64_t> moji(0);
  
  if(beg_end){
    for(int64_t i=0; i<T.size()-1; i++){
      if(T.at(i) == T.at(i+1)){
        cnt++;
      }
      else{
        moji.push_back(cnt+1);
        cnt = 0;
        if(i >= S.size()){
          break;
        }
      }
    }
  }
  else{
    for(int64_t i=0; i<S.size(); i++){
      if(T.at(i) == T.at(i+1)){
        cnt++;
        if(i == S.size() -1){
          moji.push_back(cnt+1);
          break;
        }
      }
      else{
        moji.push_back(cnt+1);
        cnt = 0;
      }
    }
  }
  
  if(same){
    ans = S.size() * K /2;
  }
  else if(beg_end){
    int64_t sum = 0;
    int64_t moji_x = moji.at(moji.size()-1);
    for(int i=0; i<moji.size(); i++){
      sum += moji.at(i)/2;
    }
    ans = sum*K - (moji_x)/2;
    if(y > 1){
      ans -= moji.at(0)/2 * (K-1);
    }
    int64_t z = moji_x - y;
    ans += z/2;
  }
  else{
    int64_t sum = 0;
    for(int64_t i=0; i<moji.size(); i++){
      sum += moji.at(i)/2;
    }
    ans = sum*K;
  }
  
  cout << ans << endl;
}   

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define mp make_pair
#define PII pair<int,int>
#define fi first
#define se second
#define pb push_back
#define ll long long
#define ull unsigned long long
#define ui unsigned int
#define sci(x) scanf("%d",&x)
#define scs(s) scanf("%s",s)
#define scc(c) scanf("%c",c)
#define scd(d) scanf("%lf",&d)
#define scld(ld) scanf("%Lf",&ld)
using namespace std;

//********************************************
//Error tracking
#define show(args...) { vector<string> _v = split(#args, ','); err(_v.begin(), args); }

vector<string> split(const string& s, char c) {
    vector<string> v;
    stringstream ss(s);
    string x;
    while (getline(ss, x, c))
        v.emplace_back(x);
    return move(v);
}

void err(vector<string>::iterator it) {}
template<typename T, typename... Args>
void err(vector<string>::iterator it, T a, Args... args) {
    cerr << it -> substr((*it)[0] == ' ', it -> length()) << " = " << a << '\n';
    err(++it, args...);
}
//********************************************

const int NMAX = 100005;

int n,dp[NMAX];
char s[NMAX];

int main()
{
    int i,j;

  //  freopen("input","r",stdin);
 //   freopen("output","w",stdout);
    cin.sync_with_stdio(false);

    cin >> (s + 1);
    n = strlen(s + 1);

    dp[0] = 1;
    for (i = 1; i <= n; i++)
    {
        string x;

        int aux = max(1, i - 4);

        if (i >= 5)
        {
            x = "";
            for (j = i - 4; j <= i; j++) x += s[j];
            if (dp[i - 5] && (x == "erase" || x == "dream")) dp[i] = 1;
        }

        if (i >= 6)
        {
            x = "";
            for (j = i - 5; j <= i; j++) x += s[j];
            if (dp[i - 6] && x == "eraser") dp[i] = 1;
        }

        if (i >= 7)
        {
            x = "";
            for (j = i - 6; j <= i; j++) x += s[j];
            if (dp[i - 7] && x == "dreamer") dp[i] = 1;
        } 
    }

    if (dp[n]) cout << "YES\n";
    else cout << "NO\n";
    return 0;   
}

Measured memory_bytes: 768
import sys,queue,math,copy,itertools,bisect,collections,heapq

def main():
    MOD = 2**61-1
    SI = lambda : sys.stdin.readline().rstrip()

    s = SI()
    t = SI()
    lens = len(s)
    lent = len(t)

    def cx(x):
        return ord(x) - ord('a') + 1

    hsh = 0
    for x in t:
        hsh = (hsh * 26 + cx(x)) % MOD

    n = (lens+lent) * 2 + 1
    dp = [0] * n

    h = 0
    ans = 0
    for i in range(n):
        if i >= lent:
            h -= cx(s[(i - lent)%lens]) * pow(26,lent-1,MOD)
        h = (h * 26 + cx(s[i % lens])) % MOD
        if h == hsh:
            if i < lent:
                dp[i] = 1
            else:
                dp[i] = dp[i-lent] + 1
            ans = max(ans,dp[i])

    if n - ans * lent < lent * 2:
        print(-1)
    else:
        print(ans)

if __name__ == '__main__':
    main()

Measured memory_bytes: 92580
import java.util.*;

public class Main {
  public static void main(String[] args) {
    @SuppressWarnings("resource")
    Scanner sc = new Scanner(System.in);
    char[] s = sc.next().toCharArray();

    StringBuilder sb = new StringBuilder();
    for (int i = 0; i < s.length; i+=2) {
      sb.append(s[i]);
    }
    System.out.println(sb.toString());
  }
}


Measured memory_bytes: 23508
using System;
using System.Windows;
using System.Collections.Generic;
using System.Linq;
using System.Numerics;

class Program
{
    static void Main(string[] args)
    {
      //入力を受け取る
      var N = long.Parse(Console.ReadLine());
      long sqrt = (long) Math.Floor(Math.Sqrt(N));
      long a = 1;
      long b = N;
      for(long i = sqrt;i > 0;i--){
        if(N%i == 0){
          a = i;
          b = N/i;
          break;
        }
      }
      Console.WriteLine(a+b-2);
    }
  
  static Dictionary<long,long> Factorization(long n){
    var sqrt = Math.Floor(Math.Sqrt(n));
    var result = new Dictionary<long,long>();
    
    for(long i = 2; i < sqrt ; i++){
      if(n%i == 0){
        var r = 0;
        while(n%i == 0){
          r++;
          n = n/i;
        }
        result.Add(i,r);
      }
    }
    if(n > sqrt){
      result.Add(n,1);
    }
    return result;
  }

}


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

using namespace std;
typedef long long LL;


int main()
{
        LL n;
        cin >> n;
        LL a[n];
        for(int i = 0 ; i < n ; i++)
        {
                cin >> a[i];
        }
        LL sum = 0;
        for(int i = 0 ; i < n ; i++)
        {
                for(int j = i +1 ; j < n ; j++)
                {
                        sum += a[i]*a[j];
                }
        }
        cout << sum << endl;
        return 0;
}

Measured memory_bytes: 256
# AOJ 1125: Get Many Persimmon Trees
# Python3 2018.7.14 bal4u

s = [[0 for x in range(105)] for y in range(105)]
while True:
	N = int(input())
	if N == 0: break
	a = [[0 for x in range(105)] for y in range(105)]
	W, H = map(int, input().split())
	for i in range(N):
		x, y = map(int, input().split())
		a[y][x] = 1
	for y in range(1, H+1):
		for x in range(1, W+1):	s[y][x] = s[y][x-1] + a[y][x]
	S, T = map(int, input().split())
	ans = 0
	for y in range(H-T+1):
		for x in range(W-S+1):
			k = 0
			for i in range(1, T+1):	k += s[y+i][x+S]-s[y+i][x];
			ans = max(ans, k)
	print(ans)


Measured memory_bytes: 5880
#include "iostream"
#include "climits"
#include "list"
#include "queue"
#include "stack"
#include "set"
#include "functional"
#include "algorithm"
#include "string"
#include "map"
#include "unordered_map"
#include "unordered_set"
#include "iomanip"
#include "cmath"
#include "random"
#include "bitset"
#include "cstdio"
#include "numeric"
#include "cassert"

using namespace std;

const long long int MOD = 1000000007;
//const int MOD = 1000000007;
//const int MOD = 998244353;
//const long long int MOD = 998244353;

long long int N, M, K, H, W, L, R;
//int N, M, K, H, W, L, R;

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	
	cin >> N >> M;
	if (N <= 5)M = 0;
	if (N <= 12)M /= 2;
	cout << M << endl;
}


Measured memory_bytes: 256
import sys
import math
import itertools

a, b, h, m = map(int, input().split())
ans = 0
hour = (h/12)*360+(m/60)*30
minutes = (m / 60)*360
deg = max(hour,minutes)-min(hour,minutes)
if (deg > 180):
    deg = 360 - deg
print(math.sqrt(a ** 2 + b ** 2 - (2 * a * b * math.cos(math.radians(deg)))))

Measured memory_bytes: 9528
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
main()
{
	int n, N, i, j, sum = 0, max;
	
	scanf("%d", &n);
	for(i = 0; i < n; i++)
	{
		scanf("%d", &N);
		sum += N; 
		if(max < N)
			max = N;
	}
	printf("%d\n", sum - max / 2);

	return 0;
}

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

//const int MOD=998244353;

vector<int> v;



int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    
    int n,m;
    cin>>n>>m;
    
    vector<int> ct(m+1);
    for(int i=0; i<n; i++){
        int x;
        cin>>x;
        for(int j=0; j<x; j++){
            int y;
            cin>>y;
            ct[y]++;
        }
    }
    cout<<count(ct.begin(),ct.end(),n);
    
    
    
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int a[1000000],n;
bool same(int *a,int n)
{
    for(int i=1;i<n;i++)
    {
        if(a[i]!=a[0]) return false;
    }
    return true;
}
bool dekhao(int *a,int n,int total,int mn,int mx)
{
    int col[total],now=n;
    memset(col,0,sizeof col);
    for(int i=0;i<total;i++)
    {
        if(a[i]==mn)
        {
            col[i]++;
            now--;
        }
        else
        {
            int baki=total-i-1;
             baki=baki*2;
            col[i]=now-baki;
            now-=col[i];
            if(col[i]<=0) return false;
        }
    }
    int prev=0,cs=0;
    for(int i=0;i<total;i++)
    {
        cs+=col[i];
        for(int j=prev;j<cs;j++)
        {
            if(a[j]!=(total-1)+(col[i]>1))
                return false;
        }
        prev=cs;

    }
    return (now==0)&&true;
}


main()
{

    cin>>n;
    for(int i=0;i<n;i++)
    {
        cin>>a[i];
    }
    sort(a,a+n);
    int mn=a[0],mx=a[n-1];
    if(mx-mn>1)
    {
        cout<<"No";return 0;
    }

    if(!same(a,n))
    {
        cout<<((dekhao(a,n,mx,mn,mx))?"Yes":"No");
        return 0;
    }
    else
    {
        if(n==mn+1)
        {
            cout<<"Yes";return 0;
        }
        else if(n<=mn)
        {
            cout<<"No";
            return 0;
        }
        else if(n>=2*mn)
        {
            cout<<"Yes";return 0;
        }
        else
        {
            cout<<"No";
            return 0;
        }
    }

}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define PB push_back
#define MP make_pair
#define F first
#define S second
#define SZ(x) ((int)(x).size())
#define ALL(x) (x).begin(),(x).end()
#ifdef _DEBUG_
	#define debug(...) printf(__VA_ARGS__)
#else
	#define debug(...) (void)0
#endif
using namespace std;
typedef long long ll;
typedef pair<int,int> PII;
typedef vector<int> VI;

const int MAXNM = 1e5 + 10;

VI e[MAXNM];
VI pA, pB;
bool vis[MAXNM];

void DFS(int x, VI &vec) {
	vis[x] = true;
	vec.PB(x);
	for(int u : e[x]) {
		if(vis[u]) continue;
		DFS(u, vec);
		break;
	}
}

int main() {
	int N, M;
	scanf("%d%d", &N, &M);
	for(int i = 0; i < M; i++) {
		int a, b;
		scanf("%d%d", &a, &b);
		e[a].PB(b);
		e[b].PB(a);
	}
	DFS(1, pA);
	DFS(1, pB);
	printf("%d\n", SZ(pA) + SZ(pB) - 1);
	for(int i = SZ(pB) - 1; i >= 1; i--)
		printf("%d ", pB[i]);
	debug("~");
	for(int i = 0; i < SZ(pA); i++)
		printf("%d%c", pA[i], " \n"[i == SZ(pA) - 1]);
	return 0;
}


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

int main() { 
    string S; cin >> S;
    int N = S.length();
    int one = 0;
    int zero = 0;
    for (int i=0; i<N; i++) {
        if (S[i] == '1') one++;
        else if (S[i] == '0') zero++;
    }

    cout << min(one, zero) * 2 << endl;
    
    return 0;
}

Measured memory_bytes: 1144
//QWsin
#include<cmath>
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;

typedef long long ll;

string ans;

inline int query(ll x){
	cout<<"? "<<x<<endl;
	cin>>ans;return ans=="Y";	
}

inline int solve1()
{
	ll fac=1;
	for(int i=1;i<=10;++i,fac*=10)
		if(!query(fac)) return i-1;
	return -1;
}

inline void spj()
{
	int fac=9;
	
	for(int i=1;i<=10;++i,fac=fac*10+9)
		if(query(fac)) {cout<<"! "<<(long long)pow(10,i-1)<<endl;return ;}
}

int main()
{
	int len=solve1();
	if(len==-1) return spj(),0;
	
	ll num=0;
	for(int i=len;i>1;--i)
	{
		int l= (i==len)?1:0,r=9,ans=-1;
		
		while(l<=r)
		{
			int mid=(l+r)>>1;
			if(query(num+mid*pow(10,i-2))) l=mid+1,ans=mid;
			else r=mid-1;
		}
		
		num+=ans*pow(10,i-2);
	}
	
	num*=100;
	int l=len==1?1:0,r=9,ans=-1;
	while(l<=r)
	{
		int mid=(l+r)>>1;
		if(query(num+mid*10)) r=mid-1,ans=mid;
		else l=mid+1;	
	}
	num+=ans*10;
	cout<<"! "<<num/10<<endl;
	return 0;
}


Measured memory_bytes: 648
#include<stdio.h>
int main(void)
{
	int h,a,b,x,y,ans,cnt,i;
	scanf("%d %d %d",&h,&a,&b);
	for(i=a;i<=b;i++){
		ans=h%i;
		if(ans==0){
			cnt++;
		}
	}
	printf("%d\n",cnt);
	return 0;
}


Measured memory_bytes: 2716
#include<bits/stdc++.h>
using namespace std;
int main(void)
{
	int a,b,n,t;
	cin>>a>>b;
	if(a+b==15) putchar('+');
	else if(a*b==15) putchar('*');
	else putchar('x');
	putchar('\n');
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
 
 
#pragma GCC target ("avx2")
#pragma GCC optimization ("O3") 
#pragma GCC optimization ("unroll-loops")
 
// #include <ext/pb_ds/detail/standard_policies.hpp>
using namespace std;
using namespace __gnu_pbds;
// const ll RANDOM = chrono::high_resolution_clock::now().time_since_epoch().count();
// gp_hash_table<int, int> table;
 
#define ll  long long
#define vii vector< ll >
#define pb push_back
#define pii pair<ll,ll>
#define ppi pair<pii,ll>
#define all(x) x.begin(),x.end()
#define S second
#define F first
#define ins insert
#define ld long double
#define lp(l,r) for(i=l;i<=r;++i)
 
#define lpj(l,r) for(j=l;j<=r;++j)
#define lpr(l,r) for(i=r;i>=l;--i)
#define lprj(l,r) for(j=r;j>=l;--j)
 
#define swap(a,b){ auto _t=a;a=b,b=_t;}
#define flush() cout.flush()
#define popcount __builtin_popcount
#define die() return 0;
#define sz() size() 


 
 
#define TRACE
 
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
    cerr << name << " : " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
    const char* comma = strchr(names + 1, ',');cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
#else
#define trace(...)
#endif
 
#define MD          1000000007
#define M           1000011
#define N           14
#define fftmod      998244353
#define EPS         (double)1e-10
 
long long  md=MD;
ll inf=1e18;
 
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); 
 
 
inline ll exp(ll a,ll b){if(a==0&&b==0)return 1ll;if(a==0)return 0ll;ll r=1LL;while(b>0){if(b&1){r=(r%md)*(a%md);r=(r+md)%md;}b/=2;a=(a%md)*(a%md);a=(a+md)%md;}return (r+md)%md;}
ll gcd(ll a,ll b){if(b==0)return a;if(a==0)return b;return gcd(b,a%b);}
inline ll poww(ll a,ll b){ll r=1LL;while(b>0){if(b&1)r=r*a;b/=2;a=a*a;}return (ll)r;}
 
using cd=complex<double>;
const double PI=acos(-1);
 
inline ll rand(ll l,ll r){
    return l+rng()%(r-l+1);
}



int main(){
 
     
    ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
 
   // ifstream fin("input.txt");ofstream fout("outut.txt");
    ll t,i,j,m,n,s,z,k,p;string s1,s2;ll q;ll x,y;
    cin>>n>>t;
    vii v(n);
    vii mx(n);
    lp(0,n-1)cin>>v[i];
    mx[n-1]=v[n-1];
    for(i=n-2;i>=0;--i){
      mx[i]=max(v[i],mx[i+1]);
    }
    p=0;
    ll ma=0;
    for(i=0;i+1<n;++i){
      ma=max(ma,mx[i+1]-v[i]);
    }
    for(i=0;i+1<n;++i){
      if(ma==mx[i+1]-v[i])++p;
    }cout<<p<<"\n";











}



Measured memory_bytes: 1792
using System;
using System.Linq;

namespace atcoder
{
    class Program
    {
        static void Main(string[] args)
        {
            A.Dodecagon();
        }
    }

    class A
    {
        public static void Dodecagon()
        {
            int r = Input.getInt();
            int d = 3 * r * r ;
            Output.writeInt(d);   
        }


    }
  
    class Input
    {
        public static int getInt()
        {
            int i = int.Parse(Console.ReadLine());
            return i;
        }

        public static string getString()
        {
            string s = Console.ReadLine();
            return s;
        }
        public static int[] getIntArray()
        {
            string[] s = Console.ReadLine().Split(' ');
            int[] num = s.Select(x=>int.Parse(x)).ToArray();
            return num;
        }
    }

    class Output
    {
        public static void writeInt(int i)
        {
            Console.WriteLine(i);
        }
    }
}


Measured memory_bytes: 11092
import java.util.Scanner;

class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int[][][] bfr = new int[4][3][10];
        StringBuilder sb = new StringBuilder();

        int dataCnt = in.nextInt(); // not use
        while (in.hasNext()) {
            int b = in.nextInt() -1;
            int f = in.nextInt() -1;
            int r = in.nextInt() -1;
            int v = in.nextInt();

            bfr[b][f][r] += v;
        }

        printLives(bfr[0], sb);
        sb.append("####################\n");
        printLives(bfr[1], sb);
        sb.append("####################\n");
        printLives(bfr[2], sb);
        sb.append("####################\n");
        printLives(bfr[3], sb);

        System.out.print(sb.toString());
    }

    private static void printLives(int[][] noseCnt, StringBuilder sb) {
        for (int i = 0, iMax = noseCnt.length; i < iMax; i++) {
            for (int j = 0, jMax = noseCnt[i].length ; j < jMax; j++) {
                sb.append(" ").append(noseCnt[i][j]);
            }
            sb.append("\n");
        }
        return;
    }
}

Measured memory_bytes: 21080
#include<bits/stdc++.h>
using namespace std;
#define num 1000000007
//#define num 998244353
#define REP(i,a,n) for(ll i=a;i<n;i++)
#define inarr(i,a,n,A) for(ll i=a;i<n;i++) { cin>>A[i]; }
#define vll vector<long long>
#define pii pair <int,int>
#define pll pair<long long, long long>
#define vpii vector< pair <int,int>>
#define vpll vector< pair<long long, long long>>
#define max(a,b) ((a>b)?a:b)
#define min(a,b) ((a>b)?b:a)
#define max3(a,b,c) ((a>b)?(a>c)?a:c:(b>c)?b:c)
#define min3(a,b,c) ((a<b)?(a<c)?a:c:(b<c)?b:c)
#define avg(a,b) ((a)+(b))/2
#define push push_back
#define pop pop_back
#define mp make_pair
#define sf int flag=0     //Remember semicolon
#define assmin(a,b) if(b<=a) { a=b; }
#define assmax(a,b) if(b>=a) { a=b; }
#define f first
#define s second
#define fix(f,n) std::fixed<<std::setprecision(n)<<f
typedef long long ll;
ll mod(ll a, ll b)
{
	if(a%b<0)
	{
		return a%b + b;
	}
	return a%b;
}
 
 
ll mod_exp(ll a, ll b, ll c)
{
	ll res=1;
	a=a%c;
	while(b>0)
	{
		if(b%2==1)
		{
			res=(res*a)%c;
		}
		b/=2;
		a=(a*a)%c;
	}
	return res;
}
ll mymod(ll a,ll b=num)
{
    return ((a%b)+b)%b;
}
bool prime[200000];
vll v;
void SieveOfEratosthenes() 
{ 
    memset(prime, true, sizeof(prime)); 
    prime[1]=false;
    for (int p=2; p*p<=200000; p++) 
    { 
        if (prime[p] == true) 
        { 
            v.push(p);
            for (int i=p*p; i<=200000; i += p) 
                prime[i] = false; 
        } 
    } 
}
ll powe[60];
void power()
{
    powe[0]=1;
    REP(i,1,15)
    {
        powe[i]=2*powe[i-1];
    }
}
ll gcdExtended(ll,ll,ll *,ll *);
ll modInverse(ll a, ll m=num) 
{ 
    ll x, y; 
    ll g = gcdExtended(a, m, &x, &y); 
        ll res = (x%m + m) % m;
        return res;
} 
ll gcdExtended(ll a, ll b, ll *x, ll *y) 
{ 
    if (a == 0) 
    { 
        *x = 0, *y = 1; 
        return b; 
    } 
    ll x1, y1; 
    ll gcd = gcdExtended(b%a, a, &x1, &y1); 
    *x = y1 - (b/a) * x1; 
    *y = x1; 
    return gcd; 
} 
ll fact[100005];
void factorial()
{
    fact[0]=1;
    REP(i,1,100002)
    {
        fact[i]=mymod(i*fact[i-1], num);
    }
}
ll gcd(ll a,ll b)
{
    if(b==0)
        return a;
    return gcd(b,a%b);
}
bool my(pll p1,pll p2)
{
    if(p1.f<p2.f) return true;
    if(p1.f==p2.f && p1.s<p2.s) return true;
    return false;
}
bool isprime(ll n)
{
    REP(i,2,sqrt(n))
    {
        if(n%i==0)
        return false;
    }
    return true;
}
ll solve(ll h)
{
    if(h==1)
    return 1;
    else
    return 1+2*solve(h/2);
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll h;
    cin>>h;
    cout<<solve(h);
	return 0;
}


Measured memory_bytes: 256
import sys

A, B, M = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = []
for e in sys.stdin:
  c.append(list(map(int, e.split())))

ans = min(a) + min(b)

for i in range(len(c)):
  temp_val = a[c[i][0]-1] + b[c[i][1]-1] - c[i][2]
  if temp_val < ans:
    ans = temp_val

print(ans)

Measured memory_bytes: 38504
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int,int>;
//マクロ
//forループ関係
//引数は、(ループ内変数,動く範囲)か(ループ内変数,始めの数,終わりの数)、のどちらか
//Dがついてないものはループ変数は1ずつインクリメントされ、Dがついてるものはループ変数は1ずつデクリメントされる
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
//xにはvectorなどのコンテナ
#define ALL(x) (x).begin(),(x).end() //sortなどの引数を省略したい
#define SIZE(x) ((ll)(x).size()) //sizeをsize_tからllに直しておく
#define MAX(x) *max_element(ALL(x)) //最大値を求める
#define MIN(x) *min_element(ALL(x)) //最小値を求める
//定数
#define INF 1000000000000 //10^12:極めて大きい値,∞
#define MOD 1000000007 //10^9+7:合同式の法
#define MAXR 100000 //10^5:配列の最大のrange(素数列挙などで使用)
//略記
#define PB push_back //vectorヘの挿入
#define MP make_pair //pairのコンストラクタ
#define F first //pairの一つ目の要素
#define S second //pairの二つ目の要素
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;
}
int main() {
    int n,m,x;cin>>n>>m>>x;
    vector<int> v(n+1,0);
    rep(i,m){
        int s;cin>>s;
        v[s]=1;
    }
    int lans=0;
    int rans=0;
    for (int i = x; i <= n; i++) {
        rans+=v[i];
    }
    for (int i = x; i >= 0; i--) {
        lans+=v[i];
    }
    cout<<min(lans,rans)<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define all(x) (x).begin(), (x).end()
#define dbg(x) cerr << #x << ": " << x << endl
int main() {
  int h, n;
  cin >> h >> n;
  rep(i, n) {
    int a;
    cin >> a;
    h -= a;
    if(h <= 0) {
      cout << "Yes" << endl;
      return 0;
    }
  }
  cout << "No" << endl;
  return 0;
}

Measured memory_bytes: 256
N = int(input())
a = list(map(int, input().split()))
s = []

b = 0
for i in range(N):
  b += a[i]
  s.append(b)
  
ans = abs(2*s[0]-s[N-1])
#print(ans)
for i in range(N-1):
  ans = min(ans, abs(2*s[i]-s[N-1]))
  #print(ans)
  
print(ans)


Measured memory_bytes: 23800