akhauriyash/Code-Regression huggingface dataset:
#include <algorithm>
#include <vector>
#include <cmath>
#include <tuple>
#include <cmath>
#include <algorithm>
#include <map>
#include <iomanip>
#include <queue>
#include <numeric>
#include <iostream>
#include <set>

using namespace std;


int main() {

    int N, M, X, Y;
    cin >> N >> M >> X >> Y;

    int maxX = -100;

    for (int i = 0; i < N; i++) {
        int x;
        cin >> x;
        maxX = max(maxX, x);
    }

    int minY = 100;

    for (int i = 0; i < M; i++) {
        int y;
        cin >> y;
        minY = min(minY, y);
    }

    bool shouldOccur = true;

    for (int z = -100; z <= 100; z++) {

        if (X < z and z <= Y and maxX < z and minY >= z) {
            shouldOccur = false;
            break;
        }

    }

    if (shouldOccur) {
        cout << "War" << "\n";
    } else {
        cout << "No War" << "\n";
    }

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
  int n;
  cin >> n;
  vector<float> x(n);
  vector<float> u(n);
  for(int i = 0;i < n;i++){
    string U;
    cin >> x[i] >> U;
    if(U == "JPY") u[i] = 1;
    else u[i] = 380000;
  }
  float answer = 0;
  for(int i = 0;i < n;i++){
    answer += x[i]*u[i];
  }
  cout << answer << endl;
}

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

typedef long long ll;
#define REP(i,n) for(int i=0,_n=(int)(n);i<_n;++i)
#define ALL(v) (v).begin(),(v).end()
#define CLR(t,v) memset(t,(v),sizeof(t))
template<class T1,class T2>ostream& operator<<(ostream& os,const pair<T1,T2>&a){return os<<"("<<a.first<<","<<a.second<< ")";}
template<class T>void pv(T a,T b){for(T i=a;i!=b;++i)cout<<(*i)<<" ";cout<<endl;}
template<class T>void chmin(T&a,const T&b){if(a>b)a=b;}
template<class T>void chmax(T&a,const T&b){if(a<b)a=b;}


int nextInt() { int x; scanf("%d", &x); return x;}
ll nextLong() { ll x; scanf("%lld", &x); return x;}

const int MAX_N = 212345;
int ans[MAX_N];
vector<int> g[MAX_N];

int num[3];

void dfs(int v, int prev, int side) {
  num[side]++;
  for (int nxt : g[v]) if (nxt != prev) {
    dfs(nxt, v, 3-side);
  }
}

void dfs2(int v, int prev, int side, const int zero) {
  if (zero == 1) {
    if (side == 1) ans[v] = 0;
    else {
      if (num[2] > 0)      { ans[v] = 2; num[2]--; }
      else if (num[1] > 0) { ans[v] = 1; num[1]--; }
      else { ans[v] = 0; }
    }
  }
  else if (zero == 2) {
    if (side == 2) ans[v] = 0;
    else {
      if (num[1] > 0)      { ans[v] = 1; num[1]--; }
      else if (num[2] > 0) { ans[v] = 2; num[2]--; }
      else { ans[v] = 0; }
    }
  }
  else {
    if (num[side] > 0) {
      num[side]--;
      ans[v] = side;
    } else {
      ans[v] = 0;
    }
  }
  for (int nxt : g[v]) if (nxt != prev) {
    dfs2(nxt, v, 3-side, zero);
  }
}

int main2() {

  CLR(ans, 0);
  REP(i, MAX_N) g[i].clear();

  int N = nextInt();
  REP(i, N-1) {
    int a = nextInt() - 1;
    int b = nextInt() - 1;
    g[a].push_back(b);
    g[b].push_back(a);
  }

  num[0] = 0;
  num[1] = 0;
  num[2] = 0;
  dfs(0, -1, 1);

  int zero = 0;
  if (num[1] <= N/3) {
    zero = 1;
  } else if (num[2] <= N/3) {
    zero = 2;
  }

  num[0] = N/3;
  num[1] = N/3 + (N%3 >= 1);
  num[2] = N/3 + (N%3 >= 2);
  dfs2(0, -1, 1, zero);


  int c0 = 3;
  int c1 = 1;
  int c2 = 2;
  REP(i, N) {
    if (ans[i] == 0) { ans[i] = c0; c0 += 3; }
    if (ans[i] == 1) { ans[i] = c1; c1 += 3; }
    if (ans[i] == 2) { ans[i] = c2; c2 += 3; }
  }

  REP(i, N) {
    if (i > 0) printf(" ");
    printf("%d", ans[i]);
  }
  printf("\n");
  return 0;
}

int main() {

#ifdef LOCAL
  for (;!cin.eof();cin>>ws)
#endif
    main2();
  return 0;
}

Measured memory_bytes: 21376
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<c && c<b) {
   System.out.print("Yes");
    }else if(b<c && c<a){
   System.out.print("Yes");
      
      }else{
   System.out.println("No");

      
    }
  }
}

Measured memory_bytes: 22740
N, M = (int(x) for x in input().split())
KA = [[int(x) for x in l] for l in [input().split() for i in range(N)]]
[x.pop(0) for x in KA]
#print(KA)
x = []
for s in KA:
  x.extend(s)
#print(x)
c = 0
for i in range(1, M + 1):
  #print(x.count(i))
  c = c + (1 if x.count(i) == N else 0)
print(c)

Measured memory_bytes: 3060
from collections import defaultdict,deque
import sys,heapq,bisect,math,itertools,string,queue,datetime
sys.setrecursionlimit(10**8)
INF = float('inf')
mod = 10**9+7
eps = 10**-7
def inp(): return int(input())
def inpl(): return list(map(int, input().split()))
def inpl_s(): return list(input().split())

N,M = inpl()
xyz = [inpl() for i in range(N)]
ans = 0
for flags in itertools.product([False,True], repeat=3):
	tmp = []
	for x,y,z in xyz:
		if not flags[0]:
			x *= -1
		if not flags[1]:
			y *= -1
		if not flags[2]:
			z *= -1
		tmp.append(x+y+z)
	tmp.sort(reverse=True)
	ans = max(sum(tmp[:M]),ans)

print(ans)


Measured memory_bytes: 4504
# B Shift only

n = int(input())
a = list(map(int, input().split()))

ans = len(format(10**9, "b"))-1
for ai in a:
  for i in range(len(format(ai, "b"))):
    if (ai >> i) & 1 and ans > i:
      ans = i
print(ans)


Measured memory_bytes: 8960
import java.util.*;
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int mul4 = 0;
        int mul2 = 0;
        int mul1 = 0;
        for (int i = 0; i < n; i++) {
            int a = sc.nextInt();
            if (a % 4 == 0) {
                mul4++;
            } else if (a % 2 == 0) {
                mul2++;
            } else {
                mul1++;
            }
        }
        if (mul2 > 0) {
            mul1++;
        }
        if (mul4+1 >= mul1) {
            System.out.println("Yes");
        } else {
            System.out.println("No");
        }
    }
}


Measured memory_bytes: 49248
#include <bits/stdc++.h>
using namespace std;
#define FAST       			ios_base :: sync_with_stdio(false); cin.tie(NULL);

int main() {
  FAST;
  int K, X;
  cin >> K >> X;
  if (500 * K >= X) {
    cout << "Yes" << endl;
  }
  else {
    cout << "No" << endl;
  }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn = 1e4 + 7;
const double pi = acos(-1);
const int mod = 100007;
const double eps = 1e-8;
const int inf = 0x3f3f3f3f;

int main(){
	ll n;
	cin >> n;
	int cnt = 0;
	ll x = 100;
	while(x < n){
		x += x /100;
		cnt++;
	}
	cout << cnt << endl;
    return 0;
}

Measured memory_bytes: 3636
#include <cstdio>
#include <queue>
using namespace std;
priority_queue<double,vector<double>,greater<double> > q;
int main()
{
 int n;
 scanf("%d",&n);
 for(int i=1;i<=n;i++)
 {
  int x;
  scanf("%d",&x);
  q.push(x);
 }
 for(int i=1;i<n;i++)
 {
  double tmp1=q.top();
  q.pop();
  double tmp2=q.top();
  q.pop();
  q.push((tmp1+tmp2)/2);
 }
 printf("%.10lf\n",q.top());
 return 0;
}

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

const long mod = 1000000007;

long power(long a, long n) {
  if (n == 0) return 1;
  if (n % 2 == 0) return power(a * a % mod, n / 2);
  return a * power(a * a % mod, n / 2) % mod;
}

int main()
{
  string l;
  cin >> l;
  long total = 0, total1s = 0;
  for (long i = 0; i < l.size(); i++) {
    if (l.at(i) == '1') {
      total += power(2, total1s) * power(3, l.size() - 1 - i);
      total %= mod;
      total1s++;
    }
  }
  total += power(2, total1s);
  total %= mod;
  cout << total << endl;
}


Measured memory_bytes: 512
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)n;i++)
#define all(c) (c).begin(),(c).end()
#define pb push_back
#define dbg(...) do{cerr<<__LINE__<<": ";dbgprint(#__VA_ARGS__, __VA_ARGS__);}while(0);

using namespace std;

namespace std{template<class S,class T>struct hash<pair<S,T>>{size_t operator()(const pair<S,T>&p)const{return ((size_t)1e9+7)*hash<S>()(p.first)+hash<T>()(p.second);}};template<class T>struct hash<vector<T>>{size_t operator()(const vector<T> &v)const{size_t h=0;for(auto i : v)h=h*((size_t)1e9+7)+hash<T>()(i)+1;return h;}};}
template<class T>ostream& operator<<(ostream &os, const vector<T> &v){os<<"[ ";rep(i,v.size())os<<v[i]<<(i==v.size()-1?" ]":", ");return os;}template<class T>ostream& operator<<(ostream &os,const set<T> &v){os<<"{ "; for(const auto &i:v)os<<i<<", ";return os<<"}";}
template<class T,class U>ostream& operator<<(ostream &os,const map<T,U> &v){os<<"{";for(const auto &i:v)os<<" "<<i.first<<": "<<i.second<<",";return os<<"}";}template<class T,class U>ostream& operator<<(ostream &os,const pair<T,U> &p){return os<<"("<<p.first<<", "<<p.second<<")";}
void dbgprint(const string &fmt){cerr<<endl;}template<class H,class... T>void dbgprint(const string &fmt,const H &h,const T&... r){cerr<<fmt.substr(0,fmt.find(","))<<"= "<<h<<" ";dbgprint(fmt.substr(fmt.find(",")+1),r...);}
typedef long long ll;typedef vector<int> vi;typedef pair<int,int> pi;const int inf = (int)1e9;const double INF = 1e12, EPS = 1e-9;

int main(){
	cin.tie(0); cin.sync_with_stdio(0);
	
	int n; cin >> n;
	ll a, b; cin >> a >> b;
	rep(i, n - 1){
		ll c, d; cin >> c >> d;
		ll k = max((a + c - 1) / c, (b + d - 1) /d);
		a = c * k;
		b = d * k;
	}
	cout << a + b << endl;
	return 0;
}

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

using namespace std;

#define REP(i,n)	for(int i=0, i##_len=(n); i<i##_len; ++i)
#define REPS(i,s,n)	for(int i=(s), i##_len=(n); i<i##_len; ++i)

#define ALL(obj)	(obj).begin(),(obj).end()

typedef unsigned int 			uint;
typedef unsigned long long int	ull;
typedef long long int 			ll;

typedef pair<int,int>			P;
typedef vector<int>				V;
typedef vector<V>				VV;

#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define MAX 		2505

const ll LINF = (ll)1e18+7;		//
const int INF = 1e9+7;			//2,147,483,647 (Max int)
const int MOD = 1e9+7;
// テンプレ終了
//====================================================================//

//
int main(){
	int N,M;cin>>N>>M;
	VV j(M);
	REP(i,N){
		int a,b;cin >> a >> b;
		if(a>M)continue;
		j[a-1].push_back(b);
	}

	ll ans = 0;

	priority_queue<int> q;
	REP(i,M){
		for(int itr : j[i]){
			q.push(itr);
		}
		if(!q.empty()){
			ans += q.top();
			q.pop();
		}
	}

	cout << ans << endl;

	return 0;
}




Measured memory_bytes: 5504
N = int(input())
a = [int(i) for i in input().split()]
ruiseki = []
for i in range(N):
    if i == 0:
        ruiseki.append(a[i])
        continue
    else:
        ruiseki.append(ruiseki[-1] + a[i])
ans = abs(ruiseki[-1] - 2 * ruiseki[0])
for i in range(1, N-1):
    ans = min(ans, abs(ruiseki[-1] - 2 * ruiseki[i]))
print(ans)


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


int main() {
	int A, B, H, M;
	double PI = 3.14159265359;
	scanf("%d %d %d %d", &A, &B, &H, &M);
	double a, b;
	a = (double)M * 6;
	
	b = (double)H * 30 + M * 0.5;
	double radA, radB;
	radA = (double)(90-a) * PI / 180.0;
	radB = (double)(90-b) * PI / 180.0;
	//printf("%f", radA);
	double ax = A * cos(radA);
	double ay = A * sin(radA);
	double bx = B * cos(radB);
	double by = B * sin(radB);
	//printf("%f %f \n%f %f", ax, ay, bx, by);
	double c =sqrt((ax - bx) * (ax - bx) + (ay - by) * (ay - by));
	printf("%.15f", c);
	return 0;
}

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

int N, T;
int c[100];
int t[100];

int main() {

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

	int ans = 1001;
	for( int i = 0; i < N; i++ ) {
		if( t[i] <= T  ) {
			if( c[i] < ans ) {
				ans = c[i];
			}
		}
	}

	if( ans > 1000 ) {
		cout << "TLE" << endl;
	}
	else {
		cout << ans << endl;
	}

	return 0;
}


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

int main(){
    int a,b,c,k;
    scanf("%d %d %d %d",&a,&b,&c,&k);
    ll res = 0;
    int fromA = min(k,a);
    k -= fromA;
    res += fromA;
    int fromB = min(k,b);
    k -= fromB;
    int fromC = min(k,c);
    res -= fromC;
    printf("%lld\n", res);
}


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

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

	int nEvenCnt = 0;
	int nOddCnt = 0;
	for (int i = 0; i < nCnt; i++)
	{
		long lnTmp = 0;
		cin >> lnTmp;
		if (0 == lnTmp % 2)
			nEvenCnt++;
		else
			nOddCnt++;
	}

	bool bOneLast = false;
	if (0 == nOddCnt)
	{
		// 奇数が0個なので、残りはすべて偶数だが、
		// 偶数が1個以上ある場合、必ず最後に偶数が1個残る。
		bOneLast = true;
	}
	else if(1 == nOddCnt)
	{
		// 偶数が1個以上ある場合、必ず最後に偶数が1個は残る。
		// このルートでは、黒板に数字を1個残るには奇数だけ残る必要があるが
		// 大前提与えられる数Nが2個以上の制約があるので無理
		bOneLast = false;
	}
	else
	{
		// 奇数が2個以上の時、奇数どうしを加算して、1個は偶数ができているはず
		// よって、黒板に1個だけ残る場合は、偶数が1個残ることになる。
		if (0 == nOddCnt % 2)
			bOneLast = true;
		else
			bOneLast = false;
	}

	if (bOneLast)
		cout << "YES";
	else 
		cout << "NO";

	return 0;
}


Measured memory_bytes: 256
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define repo(i,n) for(int i = 1; i < (int)(n); i++)
#define pb push_back
#define mp make_pair
#define np next_permutation
#define fi first
#define se second
#define all(x) (x).begin(),(x).end()
#define mod 1000000007
#define pi acos(-1.0)
ll gcd(ll x, ll y) { return y ? gcd(y, x % y) : x; }
ll lcm(ll x, ll y) { return x / gcd(x, y) * y; }
ll jou(ll N, ll P){if(P==0) return 1;
    if(P%2==0){ll t = jou(N, P/2);return t*t % mod;
    }return (N * jou(N, P-1)) % mod;}  //jou(n,mod-2)で逆元
//intの最大値2147483647 ≒ 2×10^9
//long longの最大値9223372036854775807 ≒ 9×10^18
//'0'+=16;        で大文字に
//'大文字'+=32;    で小文字に
//  cout << fixed << setprecision (20);   小数点以下2０桁まで
//実行時間制約2秒では２×10^8回くらいまで計算できる



int main() {
  string s;
  ll k;
  cin >> s >> k;
  int n=s.size();
  
  ll ans=0;
  ll ren=1;
  
  if(s[0]!=s[n-1]) {
    repo(i,n) {
      if(s[i]!=s[i-1]) ans+=ren/2, ren=1;
      else ren++;
    }
  ans+=ren/2;
  ans*=k;
  }
  
  else{
    int st=0;
    int go=n-1;
    ll aida;
    rep(i,n){
      if(s[i]!=s[0]) {
        st=i;
        break;
      }
    }
    for(int i=n-1;i>=0;i--){
      if(s[i]!=s[0]) {
        go=i; 
        break;
      }
    }
    if(st==0 && go==n-1) {
      cout << n*k/2 << endl;
      return 0;    
    }
    aida=(st+n-1-go)/2;
        
    for(int i=st;i<=go;i++){
      if(s[i]!=s[i-1]) ans+=ren/2, ren=1;
      else ren++;
    }
    ans+=ren/2;
        
    ans=ans*k+aida*(k-1)+st/2+(n-1-go)/2;
  }
    
  cout << ans << endl;
  
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <cmath>
#include<algorithm>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<iomanip>
#define _USE_MATH_DEFINES
#include <math.h>
#include <functional>
using namespace std;

#define rep(i,x) for(int i=0;i<x;i++)
#define repn(i,x) for(int i=1;i<=x;i++)

typedef long long ll;
const ll INF = 1e17;
const ll MOD = 1000000007;
const ll MAX = 1000001;

ll max(ll a, ll b) {
	if (a > b) { return a; }
	return b;
}

ll min(ll a, ll b) {
	if (a > b) { return b; }
	return a;
}

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

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





///////////////////////////

ll p(ll n) {
	if (n == 0) { return 1; }
	return 2 * p(n - 1);
}


int main() {

	string S;
	cin >> S;

	string T[3] = { "Sunny","Cloudy","Rainy" };

	rep(i, 3) {
		if (S == T[i]) { cout << T[(i + 1) % 3]; }
	}
	
	

	system("PAUSE");

}


Measured memory_bytes: 504
N = int(input())
A = list(map(int, input().split()))
B = [0] * 200001

for i in range(N):
    j = A[i]
    B[j] = B[j] + 1
ans = 0

for i in range(200001):
    y = B[i]
    ans = ans +(y * (y - 1) / 2 )
    
for i in range(N):
    j = A[i]
    p = ans - B[j] + 1
    p = int(p)
    print(p)


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

using namespace std;

#define int long long

const int mod = 1e9+7;

int x,y;
int res = 0;
int fact[1000001];
int re_fact[1000001];

int p(int a,int b)
{
	if (b == 0)
		return 1;
	int tmp = p(a,b/2);
	if (b%2 == 0) return (tmp * tmp)%mod;
	return ((tmp * tmp)%mod * a)%mod;	
}

int inv(int x)
{
	return p(x,mod-2);
}

int comb(int n,int k)
{
	if (k > n) return 0;
	return ((fact[n] * re_fact[k])%mod * re_fact[n-k])%mod;
}

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

	fact[0] = 1;
	for (int i=1;i<=1000000;i++)
		fact[i] = (fact[i-1] * i)%mod;
	re_fact[1000000] = inv(fact[1000000]);
	for (int i=1000000;i>=1;i--)
		re_fact[i-1] = (re_fact[i] * i)%mod;
	cin >> x >> y;
	for (int i=0;i<=1000000;i++)
	{
		if (i > x || 2*i > y)
			break;
		if ((x - i) % 2 == 0) 
			if ((x - i)/2 == y - 2*i)
			{
				int sum = i + y - 2*i;
				res = (res + comb(sum,i))%mod;
			}
	}
	cout << res;	
}

Measured memory_bytes: 15872
a = 3.times.map{gets.split(' ').map(&:to_i)}
n = gets.to_i
b = readlines.map(&:to_i)

flag = 0

#横
3.times.each do |r|
	if b.include?(a[r][0])
		if b.include?(a[r][1])
			if b.include?(a[r][2])
				flag = 1
				break
			end
		end
	end
end

#縦
3.times.each do |c|
	if b.include?(a[0][c])
		if b.include?(a[1][c])
			if b.include?(a[2][c])
				flag = 1
			end
		end
	end
end

if b.include?(a[0][0])
	if b.include?(a[1][1])
		if b.include?(a[2][2])
			flag = 1
		end
	end
end

if b.include?(a[0][2])
	if b.include?(a[1][1])
		if b.include?(a[2][0])
			flag = 1
		end
	end
end

if flag == 1
	puts 'Yes'
else
	puts 'No'
end

Measured memory_bytes: 1788
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define P pair<ll,ll>
#define FOR(I,A,B) for(ll I = (A); I < (B); ++I)
#define FORR(I,A,B) for(ll I = (B-1); I >= (A); --I)
#define SORT(x) (sort(x.begin(),x.end())) // 0 2 2 3 4 5 8 9
#define REV(x) (reverse(x.begin(),x.end())) //reverse
ll gcd(ll a,ll b){if(a<b)swap(a,b);if(a%b==0)return b;else return gcd(b,a%b);}
ll lcm(ll a,ll b){ll c=gcd(a,b);return ((a/c)*(b/c)*c);}//saisyo kobaisu
#define NEXTP(x) next_permutation(x.begin(),x.end())
const ll INF=1e18+7;
const ll MOD=1e9+7;


int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	int x;
	cin >> x;
	for(int i=111;i<1000;i+=111){
		if(x<=i){
			cout << i << endl;
			return 0;
		}
	}
}


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

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

  int n, a, b;
  cin >> n >> a >> b;

  vector<int> p(n);

  int cnt1 = 0, cnt2 = 0, cnt3 = 0;

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

    if (p[i] <= a) {
      cnt1++;
    } else if (p[i] <= b) {
      cnt2++;
    } else {
      cnt3++;
    }
  }
  cout << min({cnt1, cnt2, cnt3}) << endl;

  return 0;
}

Measured memory_bytes: 256
//#pragma GCC optimize("Og,no-stack-protector,unroll-loops,fast-math")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include <bits/stdc++.h>
//#include <boost/multiprecision/cpp_int.hpp>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
using namespace std;
//using namespace boost::multiprecision;
using namespace __gnu_pbds;
template <typename T>
using os = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
typedef long long  ll;
typedef double ld;
#define ios ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define pii pair<ll,ll>
#define vi  vector<ll>
#define vii vector<pii >
#define mi  map<ll,ll>
#define all(a)  (a).begin(),(a).end()
#define pb push_back
#define make make_pair
#define ff first
#define ss second
#define osl os<ll>
#define ospii os<pair<ll,ll> >
#define endl "\n"
template <typename  R>
void println(R r){
    for(auto i:r)
        cout<<i<<" ";
    cout<<endl;

}
template <typename  R>
void print(R r){
    for(auto i:r)
        cout<<i<<endl;
}
ll st[100005]={0},ft[100005]={0},parent[100005],tt=0,state[100005]={0},fans=0;
set<ll> st1,st2;
void dfs(vi graph[],ll start,ll *visit,ll pp){
    visit[start]=1;
    if(graph[start].size()!=0) {
        if (st1.find(parent[start]) == st1.end()) {
            st1.insert(start);
        }
    }
    for(auto child:graph[start]){
        parent[child]=start;
        if(!visit[child]){

            visit[child]=1;
            dfs(graph,child,visit,start);

        }
    }

}

int bfs1(vi graph[],ll *visit,ll *level){
    queue<ll> q;
    ll start=1;
    q.push(start);
    level[start]=0;
    visit[start]=1;
    while(q.size()!=0){
        ll p=q.front();
        q.pop();
        for(auto it=graph[p].begin();it!=graph[p].end();it++){
            level[(*it)]=min(level[*it],level[p]+1);
            if(visit[(*it)]!=1){
                q.push((*it));
                visit[(*it)]=1;


            }
        }

    }
}

int main(){
    ios
    ll n,wt;
    cin>>n>>wt;
    ll dp[n+1][wt+1],w[n+1],v[n+1];
    w[0]=0;// for first i elements max value considering weight limit as j
    v[0]=0;
    memset(dp,0, sizeof(dp));
    rep(i,1,n+1){
        cin>>w[i]>>v[i];
    }
    rep(i,0,n+1){
        dp[0][i]=0;   // for no elements chosen , value is 0 for very weight limit
    }
    rep(i,1,n+1){
        rep(j,0,wt+1){
            if(j-w[i]>=0) {
                dp[i][j] = max(dp[i-1][j],v[i] + dp[i - 1][j - w[i]]);
               // cout<<i<<" "<<j<<" "<<dp[i][j]<<endl;
            }
            else{
                dp[i][j]=dp[i-1][j];
               // cout<<i<<" "<<j<<" "<<dp[i][j]<<endl;
            }
        }
    }
    ll ans=-INT_MAX;
    rep(i,0,n+1)
      ans=max(ans,dp[i][wt]);
    cout<<ans<<endl;









}






Measured memory_bytes: 79232
#include <bits/stdc++.h>
#include <iostream>
#include <string>
#include <stdio.h>
#include <math.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
typedef long long ll;
typedef long double lb;
using namespace std;
int main() {
  lb X1,Y1,X2,Y2;
  cin >> X1 >> Y1 >> X2 >> Y2;
  lb P = (X2 - X1) * (X2 - X1) + (Y2 - Y1) * (Y2 - Y1);
  lb SQ = sqrt(P);
  cout << fixed << setprecision(10) << SQ << endl;
  return 0;
}


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

template <class T>
inline int read (T & x) {
  static char ch; static bool neg;
  for (ch = neg = 0; ch < '0' || '9' < ch; neg |= ch == '-', ch = getchar());
  for (x = 0; '0' <= ch && ch <= '9'; (x *= 10) += ch - '0', ch = getchar());
  return (x = neg ? -x : x);
}

#define lint long long 

int main (void) {
	long long n, x, y;
	scanf("%lld%lld%lld", &n, &x, &y);
	if (x % 2 == y % 2)
		printf("%lld\n", (y - x) / 2);
	else 
		printf("%lld\n", min(x - 1, n - y) + (y - x + 1) / 2);
}

Measured memory_bytes: 256
use proconio::input;

macro_rules! chmax {
    ($max_v: expr, $v: expr) => {
        if $v > $max_v {
            $max_v = $v;
            true
        } else {
            false
        }
    };
}

fn main() {
    input! {
        n: usize,
        m: usize,
        k: i64,
        a: [i64; n],
        b: [i64; m],
    };
    let ca = std::iter::once(0)
        .chain(a.iter().scan(0, |acc, a_i| {
            *acc += a_i;
            Some(*acc)
        }))
        .collect::<Vec<_>>();
    let cb = std::iter::once(0)
        .chain(b.iter().scan(0, |acc, b_i| {
            *acc += b_i;
            Some(*acc)
        }))
        .collect::<Vec<_>>();

    let mut ans = 0;
    let mut j = cb.len() - 1;
    for (i, &ca_i) in ca.iter().enumerate() {
        if ca_i > k {
            break;
        }
        while ca_i + cb[j] > k {
            j -= 1;
        }
        chmax!(ans, i + j);
    }

    // 二分探索 (superslice の upper_bound) を使う方法
    // for i in 0..=n {
    //     let x = k - ca[i];
    //     if x < 0 {
    //         continue;
    //     }
    //     let j = cb.upper_bound(&x);
    //     chmax!(ans, i + j - 1);
    // }

    println!("{}", ans);
}


Measured memory_bytes: 12520
#include <bits/stdc++.h>
#include <cstdlib>
#include <cmath>
#include <algorithm>
using namespace std;
using ll = long long;
using P = pair<int,int>;
using Graph= vector<vector<int>>; 
#define rep(i,n) for (ll i=0; i < (n); ++i)
#define rep2(i,n,m) for(ll i=n;i<=m;i++)
#define rep3(i,n,m) for(ll i=n;i>=m;i--)
#define pb push_back
#define eb emplace_back
#define ppb pop_back
#define fi first 
#define se second
const ll INF=1e18 ;
inline void chmax(ll& a,ll b){a=max(a,b);}
inline void chmin(ll& a,ll b){a=min(a,b);}
// ミント
const int mod = 1e9+7 ;
//998244353;

struct mint {
  ll x; // typedef long long ll;
  mint(ll x=0):x((x%mod+mod)%mod){}
  mint operator-() const { return mint(-x);}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this;}
  mint operator+(const mint a) const { return mint(*this) += a;}
  mint operator-(const mint a) const { return mint(*this) -= a;}
  mint operator*(const mint a) const { return mint(*this) *= a;}
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const { return pow(mod-2);}
  mint& operator/=(const mint a) { return *this *= a.inv();}
  mint operator/(const mint a) const { return mint(*this) /= a;}
};
istream& operator>>(istream& is, const mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}
//昆布
struct combination {
  vector<mint> fact, ifact;
  combination(int n):fact(n+1),ifact(n+1) {
    assert(n < mod);
    fact[0] = 1;
    for (int i = 1; i <= n; ++i) fact[i] = fact[i-1]*i;
    ifact[n] = fact[n].inv();
    for (int i = n; i >= 1; --i) ifact[i-1] = ifact[i]*i;
  }
  mint operator()(int n, int k) {
    if (k < 0 || k > n) return 0;
    return fact[n]*ifact[k]*ifact[n-k];
  }
}   ;
 
mint modpow(ll a,ll b){
 if(b==0) return 1 ;
 mint c= modpow(a,b/2) ;
 if(b%2==1) return c*c*a ;
 else return c*c ;
}

mint komb(ll n,ll m){
  mint x=1 ;mint y=1 ;
  rep(i,m){
    x*= n-i ;
    y*= i+1 ;
  }
  return x/y ;
}

 
 map<ll,ll> factor(ll n){  //素因数とオーダーをマップで管理
  map <ll,ll> ord ;  
  for(ll i=2;i*i<=n;i++){
        if(n%i==0){
            int res=0;
            while(n%i==0){
                n/=i;
                res++;
            }
            ord[i]=res;
        }
    }
   if(n!=1) ord[n]++;
   return ord ;
 }

int main(){
  ll n; cin>> n;
  map<ll,ll>  mp ;
  rep2(i,1,n){
    ll k=i ;
    for(ll j=2 ;j*j<=k;j++){
      if(k%j==0){
        ll res= 0;
      while(k%j==0){
        k/= j ;
         res++ ;
      } 
      mp[j]+= res ;
    }
    }
    if(k!=1) mp[k] ++ ;
  
  }
  mint ans=1 ;
  for(auto u :mp){
    ans = ans*(u.se+1) ;
  }
  
  cout<<ans<<endl ;
    return 0;
  }
   

Measured memory_bytes: 3608
from collections import defaultdict,deque
import sys,heapq,bisect,math,itertools,string,queue,copy,time
sys.setrecursionlimit(10**8)
INF = float('inf')
mod = 10**9+7
eps = 10**-7
def inp(): return int(input())
def inpl(): return list(map(int, input().split()))
def inpl_str(): return list(input().split())

N = inp()
ans = 0
for i in range(1,N+1):
    ans += len(str(i))%2

print(ans)


Measured memory_bytes: 4076
#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define ll long long
#define ld long double
#define f first
#define s second
#define mp make_pair
#define pb push_back
#define vll vector<ll>
#define endl "\n"
#define pll pair<ll,ll>
#define all(x) (x).begin() , (x).end()
#define in insert
#define int ll
using namespace std;
using namespace __gnu_pbds;
 
const ll N =(3e5+5);
const ll MOD = 998244353;
const ll INF = 1e16;
const ll LOG = 25;
 
 
long long binpow(long long a, long long b) {
    // a %= m;
    long long res = 1;
    while (b > 0) {
        if (b & 1)
            res = res * a ;
        a = a * a ;
        b >>= 1;
    }
    return res;
}
bool pali(string s){
    string t=s;
    reverse(all(t));
    if(t==s) return true;
    return false;
}
ll co[200005];
signed main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(NULL);
    
    ll n;
    cin >> n;
    ll a[n+1];
    ll ans = 0;
    for(int i =1;i<=n;i++){
        cin >> a[i];
        co[a[i]]++;
    }
    for(int i =1;i<=n;i++){
        ans += ((co[i]*(co[i]-1))/2ll);
    }


    for(int i = 1;i<=n;i++){
        ll tmp = ans;
        tmp-=((co[a[i]] * (co[a[i]]-1))/2ll);
        co[a[i]]--;
        tmp += ((co[a[i]] * (co[a[i]]-1))/2ll);
        co[a[i]]++;
        cout<<tmp<<endl;
    }


}
/*
for(int i =1;i<=m;i++){
        for(int j = 1;j<=i;j++){
            cout<<"ELEMENTS : " << i << " , " << "ROUNDED DOWN : " << j << " DP VALUE : "<< dp[i][j] << endl;
        }
    }
*/

Measured memory_bytes: 4736
#include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007
int main(){
  long long N,K;
  cin>>N>>K;
  long long a[N];
  for(long long i = 0;i<N;i++){
    cin>>a[i];
  }
  long long ans1 = 0;
  long long ans2 = 0;
  for(long long i = 0;i<N;i++){
    for(long long k = i;k<N;k++){
      if(a[i]>a[k]){
        ans1++;
      }
    }
  }
  for(long long i = 0;i<N;i++){
    for(long long k = 0;k<N;k++){
      if(a[i]>a[k]){
        ans2++;
      }
    }
  }
  long long x = (K*(K-1)/2)%MOD;
  cout << (x*ans2%MOD+K*ans1%MOD)%MOD << endl;
  return 0;
}

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

using namespace std;

typedef long long ll;

void print(vector<int> a){
	int n = a.size();
	rep(i, n) cout << a[i] << (i == n - 1 ? "\n" : " ");
}

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

	int n, k, s;
	cin >> n >> k >> s;
	
	vector<int> v(n);
	if(k == 0){
		if(s == 1e9){
			rep(i, n) v[i] = 1;
			print(v);
		}else{
			rep(i, n) v[i] = 1e9;
			print(v);
		}
		return 0;
	}

	if(s <= (n - k)){
		rep(i, n){
			if(i < k) v[i] = s;
			else v[i] = 1e9;
		}
		print(v);
		return 0;
	}
	
	rep(i, n){
		if(i % (n - k + 1) == 0){
			v[i] = s - (n - k);
		}else{
			v[i] = 1;
		}
	}
	print(v);
}


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

int main(void)
{
  char S[100], ANS[100], yyyymmdd[9];
  
  scanf("%s", S);
  yyyymmdd[0]=S[0];
  yyyymmdd[1]=S[1];
  yyyymmdd[2]=S[2];
  yyyymmdd[3]=S[3];
  yyyymmdd[4]=S[5];
  yyyymmdd[5]=S[6];
  yyyymmdd[6]=S[8];
  yyyymmdd[7]=S[9];
  yyyymmdd[8]=0x00;


  if (atoi(yyyymmdd)<=20190430) {
    printf("Heisei\n");
  } else  {
    printf("TBD\n");
  }
  
  return 0;
}


Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
int n,l,r,ans;
int main()
{
	scanf("%d",&n);
	while(n--)
	{
		scanf("%d %d",&l,&r);
		ans+=(r-l+1);
	}
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cmath>
#include <cstring>
#include <ctime>
#include <climits>
#include <iostream>
#include <algorithm>
#include <set>
#include <map>
#include <queue>
#include <vector>
#include <sstream>
#include <typeinfo>
#include <fstream>

#define DIV 1000000007

using namespace std;

long long n, s;

long long f(long long b, long long N){
	long long ret = 0;
	long long n = N;
	while(n >= b){
		ret += n%b;
		n = floor(n/b);
	}
	ret += n;
	return ret;

	//if(N < b){
	//	return N;
	//	//cout << N << " ";
	//}else{
	//	return f(b, floor(N/b)) + N%b;
	//	//cout << N%b << " ";
	//}
}

int main(){
	cin >> n >> s;
	if(s > n){
		cout << -1 << endl;
		return 0;
	}

	if(s == n){
		cout << n+1 << endl;
		return 0;
	}

	for(int i = 2; i <= sqrt(n); i++){
		if(f(i, n) == s){
			cout << i << endl;
			return 0;
		}
	}

	for(int p = sqrt(n); p > 0; p--){
		long long b = (n-s)/p+1;
		//cout << "n = " << n << "s = " << s << "p = " << p << " b= " << b << endl;
		if(b == 1 || b == 0){
			continue;
		}
		if(f(b, n) == s){
			cout << b << endl;
			return 0;
		}
	}

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


Measured memory_bytes: 256
def out_prod(v1,v2)
	v1[0]*v2[1]-v1[1]*v2[0]
end

while(input=gets)
	input=input.split(" ")
	x1=input[0].to_f
	y1=input[1].to_f
	x2=input[2].to_f
	y2=input[3].to_f
	x3=input[4].to_f
	y3=input[5].to_f
	xp=input[6].to_f
	yp=input[7].to_f

	p0=out_prod([x2-x1,y2-y1],[xp-x2,yp-y2])
	p1=out_prod([x3-x2,y3-y2],[xp-x3,yp-y3])
	p2=out_prod([x1-x3,y1-y3],[xp-x1,yp-y1])
	if((p0>0&&p1>0&&p2>0)||(p0<0&&p1<0&&p2<0)) then puts "YES"
	else puts "NO"
	end
end


Measured memory_bytes: 6892
mod reader {
    use std::fmt::Debug;
    use std::str::FromStr;
    use std::collections::VecDeque;
    use std::io::{self, Read};

    fn _read_line() -> String {
        let mut buf = String::new();
        io::stdin().read_to_string(&mut buf);
        buf
    }

    fn _read_vec_deque_string() -> VecDeque<String> {
        _read_line().split_whitespace().map(|s| s.to_string()).collect()
    }

    pub struct Reader {
        buf: VecDeque<String>
    }

    impl Reader {
        pub fn new() -> Reader {
            Reader {buf: VecDeque::new()}
        }

        fn update_buf(&mut self) {
            if self.buf.is_empty() {
                self.buf = _read_vec_deque_string();
            }
        }

        pub fn next<T>(&mut self) -> T where T: FromStr, T::Err: Debug {
            self.update_buf();
            self.buf.pop_front().unwrap().parse::<T>().unwrap()
        }

        pub fn nextN<T>(&mut self, n: usize) -> Vec<T> where T: FromStr, T::Err: Debug {
            let mut vec: Vec<T> = Vec::with_capacity(n);
            for i in 0..n {
                vec.push(self.next());
            }
            vec
        }
    }
}

mod data {
    pub struct UnionFind {
        root : Vec<usize>
    }

    impl UnionFind {
        pub fn new(size : usize) -> UnionFind {
            UnionFind {root : (0..size).collect()}
        }

        pub fn find(&mut self, x : usize) -> usize {
            let xroot = self.root[x];
            if x != xroot {
                self.root[x] = self.find(xroot);
            }
            self.root[x]
        }

        pub fn unite(&mut self, x : usize, y : usize) {
            let xroot = self.find(x);
            self.root[xroot] = self.find(y);
        }

        pub fn same(&mut self, x : usize, y : usize) -> bool {
            self.find(x) == self.find(y)
        }
    }
}

fn with_large_stack(func : fn() -> ()) {
    use std::thread::Builder;
    let builder = Builder::new();
    let th = builder.stack_size(10000000);

    th.spawn(move || {
        func();
    }).unwrap().join();
}

fn main() {
    with_large_stack(_main);
}

fn _main() {
    let mut reader = reader::Reader::new();

    let s: String = reader.next();
    let mut chars: Vec<char> = s.chars().collect();
    chars.sort_by(|a, b| a.cmp(b));
    chars.dedup();

    println!("{}", if s.len() == chars.len() {"yes"} else {"no"});
}

Measured memory_bytes: 8572
#include <bits/stdc++.h>
#define inchar			getchar
#define outchar(x)		putchar(x)
#define ll long long int
#define all(v) v.begin(), v.end()
#define SP outchar(' ')
#define LN outchar('\n')
using namespace std;
void solve ();
int dp[3005][3005]= {0};
int main () {
	int t;
	t = 1;
	while (t--) {
		solve();
	}
}

void solve (){
	string A;
	string B;
	cin >> A >> B;
	
	for (int i =0; i<A.size(); i++) {
		for (int j = 0; j<B.size(); j++) { // longest path such that ->neeche aa paye , 
			if (A[i] == B[j]) {
				dp[i+1][j+1] =  dp[i][j] + 1 ; 
			} else {
				dp[i+1][j+1] =max(dp[i][j+1] , dp[i+1][j]);
			}
		}
	}
	
	int i = A.size()-1;  
	int j = B.size()-1;
	string out;
	while (i>=0 && j>=0) {
		if (A[i] == B[j]) {
			out.push_back(A[i]);
			i--;
			j--;
		} else if (dp[i+1][j] >= dp[i][j+1]) {
			j--;
		} else {
			i--;
		}
	}
	reverse(all(out));
	cout << out ;
	

}

Measured memory_bytes: 35456
import static java.lang.Integer.*;
import static java.lang.Long.*;
import static java.lang.System.*;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;

public class Main {

    static void solve() throws Exception {
        long n = scanLong();
        if (n % 1000 == 0) {
            out.print(0);
        } else {
            out.print(1000 * (n / 1000 + 1) - n);
        }
    }

    static int scanInt() throws IOException {
        return parseInt(scanString());
    }

    static long scanLong() throws IOException {
        return parseLong(scanString());
    }

    static String scanString() throws IOException {
        while (tok == null || !tok.hasMoreTokens()) {
            tok = new StringTokenizer(in.readLine());
        }
        return tok.nextToken();
    }

    static BufferedReader in;
    static PrintWriter out;
    static StringTokenizer tok;

    public static void main(String[] args) {
        try {
            in = new BufferedReader(new InputStreamReader(System.in));
            out = new PrintWriter(System.out);
            solve();
            in.close();
            out.close();
        }
        catch (Throwable e) {
            e.printStackTrace();
            exit(1);
        }
    }
}

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

int main()
{
    int n;
    cin >> n;
    int t, a;
    cin >> t >> a;
    float diff;
    int ans;
    for (int i = 0; i < n; i++) {
        int h;
        cin >> h;
        float temp = t - 0.006 * h;
        if (i == 0 || fabs(temp - a) < diff) {
            diff = fabs(temp - a);
            ans = i + 1;
        }
    }
    cout << ans << endl;
    
    return 0;
}

Measured memory_bytes: 256
package main

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

var sc = bufio.NewScanner(os.Stdin)
var route [][]int

func scanInt() int {
	num, _ := strconv.Atoi(scanString())
	return num
}

func scanString() string {
	sc.Scan()
	return sc.Text()
}

func init() {
	sc.Split(bufio.ScanWords)
}

func dfs(h, w int) {
	if route[h][w] == 0 {
		return
	}

	route[h][w] = 0
	for _, x := range []int{-1, 0, 1} {
		for _, y := range []int{-1, 0, 1} {
			if route[h+x][w+y] == 0 {
				continue
			}
			dfs(h+x, w+y)
		}
	}
}

func main() {
	writer := bufio.NewWriter(os.Stdout)
	for {
		w, h := scanInt(), scanInt()
		if w == 0 && h == 0 {
			break
		}

		route = make([][]int, h+2)
		route[0] = make([]int, w+2)
		for i := 1; i <= h; i++ {
			route[i] = make([]int, w+2)
			for j := 1; j <= w; j++ {
				route[i][j] = scanInt()
			}
		}
		route[h+1] = make([]int, w+2)

		total := 0
		for i := 1; i <= h; i++ {
			for j := 1; j <= w; j++ {
				if route[i][j] == 1 {
					total++
					dfs(i, j)
				}
			}
		}
		fmt.Fprintln(writer, total)
	}
	writer.Flush()
}



Measured memory_bytes: 2068
#include <iostream>
#include <algorithm> 
#include <vector>
#include <set>

using namespace std;

int main() {

	int a, b, c = 0;

	//----------------------------------------------------------------------------------------------------

	int K;
	string S;
	cin >> K >> S;

	if (S.size() <= K) {
		cout << S << endl;
	}
	else {
		for (int i = 0; i < K; ++i)
		{
			cout << S[i];
		}
		cout << "..." << endl;
	}




	//----------------------------------------------------------------------------------------------------

	return 0;
}

Measured memory_bytes: 3592
#include <bits/stdc++.h>
#define DAU  ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define PLEC exit(0);
using namespace std;
int n, v[22], res;
int main() {
    DAU
    cin >> n;
    for (int i = 1; i <= n; ++i)
        cin >> v[i];
    for (int i = 2; i < n; ++i)
        if (((v[i] <= v[i-1]) && (v[i] >= v[i+1])) || (v[i] >= v[i-1] && v[i] <= v[i+1]))
            ++res;
    cout << res;
    PLEC
}


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

// boost
#include <boost/multiprecision/cpp_int.hpp>
using boost::multiprecision::cpp_int;

using ll = long long;
using ld = long double;

using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vb = vector<bool>;
using vs = vector<string>;
using vld = vector<ld>;
using vvld = vector<vld>;

typedef pair<ll, ll> P;

#define bit(n) (1LL << (n))

//#define int long long

#define all(v) v.begin(), v.end()

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

#define FOR(i, a, b) for (ll i = (a); i < (b); i++)
#define FORm(i, m) for (auto i = m.begin(); i != m.end(); i++)

template <class T>
inline void chmax(T& a, T b) {
  a = std::max(a, b);
}
template <class T>
inline void chmin(T& a, T b) {
  a = std::min(a, b);
}

#define mod (ll)(1e9 + 7)
// #define mod (998244353ll)

const long long INF = 1LL << 60;

ll d;
vll c(26);
vvll s;

vll create_first_answer() {
  vll ans(d);
  vll last(26, -1);

  rep(i, d) {
    vll cand(26);

    rep(j, 26) {
      cand[i] = s[i][j] + c[j] * (i - last[j]);
    }

    ll choice = distance(cand.begin(), max_element(all(cand)));
    ans[i] = choice;
    last[choice] = i;
  }
  return ans;
}

ll update_diff(ll idx, const vll& choice) {
  ll last = -1;
  ll total = 0;
  rep(today, d) {
    if (choice[today] == idx) {
      last = today;
      total += s[today][idx];
    } else {
      total -= c[idx] * (today - last);
    }
  }
  return total;
}

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

  cin >> d;
  rep(i, 26) {
    cin >> c[i];
  }

  s = vvll(d, vll(26));
  rep(i, d) {
    rep(j, 26) {
      cin >> s[i][j];
    }
  }

  srand(s[0][0]);

  vll ans(d);

  // ans = create_first_answer();

  vll score_con(26);
  ll score = 0;

  rep(i, 26) {
    score_con[i] = update_diff(i, ans);
    score += score_con[i];
  }

  rep(i, 50000) {
    vll cand = ans;
    vb changed(26);

    rep(j, rand() % 3 + 1) {
      ll tgt = (i + j) % d;
      cand[tgt] = rand() % 26;

      changed[ans[tgt]] = true;
      changed[cand[tgt]] = true;
    }

    ll cs = score;
    vll score_cand = score_con;
    rep(i, 26) {
      if (changed[i]) {
        cs -= score_cand[i];
        score_cand[i] = update_diff(i, cand);
        cs += score_cand[i];
      }
    }
    if (cs > score) {
      ans = cand;
      score_con = score_cand;
    }
  }

  rep(i, d) {
    cout << ans[i] + 1 << endl;
  }

  return 0;
}


Measured memory_bytes: 3748
def main():
    N, K = map(int, input().split())
    V = list(map(int, input().split()))
    ans = 0
    for i in range(K+1):
        cand = []
        for left in range(i+1):
            cand = V[:left]
            right = i - left
            cand += V[max(left,N-right):N]

            cnt = K - i
            n = len(cand)
            tmp = sum(cand)
            cand.sort()
            for c in range(min(cnt,n)):
                if cand[c] < 0:
                    tmp -= cand[c]
                else:
                    break
            ans = max(ans, tmp)


    print(ans)




        

if __name__ == "__main__":
    main()

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

using namespace std;

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int N;
	cin >> N;
	vector<int> arr(N);
	for (int i = 0; i < N; ++i) 
		cin >> arr[i];
	sort(arr.begin(), arr.end());
	double res = arr[0];
	for (size_t i = 0; i < arr.size() - 1; ++i){
		res = (res + arr[i + 1]) / 2.0;
	}
	cout << res;
}

Measured memory_bytes: 256
#include<stdio.h>

int main(){
	int n;
	scanf("%d", &n);
	
	char s[101];
	scanf("%s", s);
	
	int nb = 0;
    int nr = 0;
	for(int i=0; i<n; i++){
		if(s[i] == 'B'){
			nb++;
		}
		else{
			nr++;
		}
	}
	
	if(nr > nb){
		printf("Yes\n");
	}
	else{
		printf("No\n");
	}
	
	return 0;
}



Measured memory_bytes: 128
import itertools

N = int(input())
p = []
for _ in range(N):
    p.append(list(map(int, input().split())))
temp = list(itertools.permutations(p))
n = len(temp)
ans = 0
for i in temp:
    for j in range(N-1):
        ans += ((i[j+1][0] - i[j][0])**2 + (i[j+1][1] - i[j][1])**2)**0.5        
print(ans/n)

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

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

typedef long long ll;

#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 FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=(ll)(b);i--)
//定数
#define INF 1000000000 //10^9:極めて大きい値,∞
//略記
#define PB push_back //vectorヘの挿入
#define MP make_pair //pairのコンストラクタ
#define F first //pairの一つ目の要素
#define S second //pairの二つ目の要素

vector<int> c(26);
vector<vector<int>> s(365 ,vector<int>(26));
vector<vector<int>> last(365 ,vector<int>(26));

int culc(int d){
    int ret=0;
    int maxv=0;
    rep(j,26){
        if(s[d][j]+c[j]*(d+1-last[d][j])>maxv){
            maxv=s[d][j]+c[j]*(d+1-last[d][j]);
            ret=j+1;
        }
    }
    return ret;
}

int main(){
    int D;
    cin>>D;
    rep(i,26){ 
        cin>>c[i];
    }
    rep(d,D) rep(j,26) cin>>s[d][j];
    int t;
    int v=0;
    vector<int> kaisai_bi(26);
    int ans=18398+s[1][16];
    rep(j,26){
        if(j==16)continue;
        else if(j==0)ans-=c[j]*(2-1);
        else ans-=c[j]*(2-0);
    }
    rep(d,D) {
//        cin>>t;
        t=culc(d);
        cout<<t<<endl;
        t--;
        v+=s[d][t];
        kaisai_bi[t]=d+1;
        rep(j,26) last[d][j]=kaisai_bi[j];
        rep(j,26){ 
            v-=c[j]*(d+1-last[d][j]);
            }
    }
//    cout<<v<<endl;

    int m;
//    cin>>m;
m=0;
    rep(i,m){
        int dd,q;
        cin>>dd>>q;
        q--;
        int j=0;
        while(last[dd-1][j]!=dd || j>=26) j++;
        if(j==26){ 
            cout<<"error"<<endl;
            return 0;
        }
        v-=s[dd-1][j];
        for(int d=dd-1;d<D;d++){ 
            if(last[d][j]==dd){
                v+=c[j]*(d+1-last[d][j]);
                last[d][j]=(d==0? 0 : last[d-1][j]);
                v-=c[j]*(d+1-last[d][j]);
            }
            else{ 
                break;
            }
        }
        
        v+=s[dd-1][q];
        int before=last[dd-1][q];
        for(int d=dd-1;d<D;d++){ 
            if(last[d][q]==before){ 
                v+=c[q]*(d+1-last[d][q]);
                last[d][q]=dd;
                v-=c[q]*(d+1-last[d][q]);
            }
            else{ 
                break;
            }
        }
        cout<<v<<endl;
    }
    return 0;
}


Measured memory_bytes: 3732
A, B, C, X, Y = [int(i) for i in input().split()]
ma = max(X, Y)
mi = min(X, Y)
memo = []
if A + B > 2 * C:
    result1 = A * (X - mi) + B * (Y - mi) + C * 2 * mi
    result2 = C * 2 * ma
    print(min(result1, result2))
else:
    print(A * X + B * Y)


Measured memory_bytes: 3060
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;
int main(void){
   int N;
   cin>>N;
   int num[N];
   for(int i=0;i<N;i++){
       cin>>num[i];
   }
   sort(num,num+N);
   int check=0;
   for(int i=0;i<N-1;i++){
       if(num[i]==num[i+1]) check++;
   }
   cout<<N-check;
   return 0;
}

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

class Program {
    const int mod = 1000000007;

    static void Main() {
#if DEBUG
        var exStdIn = new System.IO.StreamReader("./../../TestStdin.txt");
        Console.SetIn(exStdIn);
#endif
        var args = Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse);
        var T = (float) args[0];
        var X = (float) args[1];

        Console.WriteLine(T / X);
    }
}

Measured memory_bytes: 11220
#include <iostream>
#include <vector>

int main() {
  int n, x;
  std::cin >> n >> x;

  std::vector<int> l(n);
  for (auto&& li : l) std::cin >> li;

  int count = 1;
  int di = 0;
  for (auto&& li : l) {
    di += li;
    if (di <= x)
      ++count;
    else
      break;
  }
  std::cout << count << std::endl;
}


Measured memory_bytes: 256