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


int main(){
  bool flag =true,find=true;
  char s[100];
  cin>>s;
  for(int i=0;i<strlen(s);i++){
    if((i+1)%2==0){
      if(s[i]=='L') continue;
      else if (s[i]=='U') continue;
      else if(s[i]=='D') continue;
      else {
        flag=false;break;
      }
    }
if((i+1)%2!=0){
      if(s[i]=='R') continue;
      else if (s[i]=='U') continue;
      else if(s[i]=='D') continue;
      else {
        find=false;break;
      }
    }

  }
  if(flag==false||find==false) cout<<"No";
  else cout<<"Yes";
  
    

 return 0;
}

Measured memory_bytes: 384
#include<bits/stdc++.h>
int n,i,f=1,ans;
int main(){
	std::cin>>n;
	int p[n];
	for(;i<n;)std::cin>>p[i],(p[i]==++i&&f)?ans++,f=0:f=1;
	std::cout<<ans;
	return 0;
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
#include <math.h>
#include <algorithm>
#include <functional>
#include<iostream>
#include <string>
using namespace std;
typedef long long ll;
#define pb pushback
#define fr(i,n) for(int i=0;i<n;i++)
#define fro(i,j,n) for(int i=j;i<n;i++)
#define ifr(i,n) for(int i=n-1;i>=0;i--)


int main() {
    int x,y;
	cin >> x>> y;
    if(y!=1)cout << (y-2)/(x-1)+1 << endl;
    else cout << 0 << endl;
      
}


Measured memory_bytes: 256
n = int(input())
a = list(map(int,input().split()))

class Bit:
    def __init__(self, n):
        self.size = n
        self.tree = [0]*(n+1)

    def sum(self, i):
        # [0, i) の要素の総和を返す
        s = 0
        while i>0:
            s += self.tree[i]
            i -= i & -i
        return s

    def add(self, i, x):
        if not (0 <= i < self.size): raise ValueError("error!")
        i += 1
        while i <= self.size:
            self.tree[i] += x
            i += i & -i

def search(x):
    l = [1 if i >= x else -1 for i in a]
    c = [n]
    for i in range(n):
        c.append(c[-1]+l[i])

    count = 0
    bit = Bit(2*n+1)
    for i in c:
        count += bit.sum(i+1)
        bit.add(i,1)
    
    return x,count

k = (n*(n+1)/2+1)//2
le = 0
ri = max(a)+1

while ri > le + 1:
    m = (ri+le)//2
    ans,count = search(m)

    if count >= k:
        le = m
    else:
        ri = m
print(le)

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

using namespace std;

typedef long long ll;
#define fi first
#define se second
#define pb push_back

const int N = 100005;
vector <int> v[N];
bool vis[N];

void dfs(int x) {
    vis[x] = true;
    for (int y : v[x]) {
        if (!vis[y]) {
            dfs(y);
        }
    }
}

int main() {
    //ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    int n, m;
    scanf("%d %d", &n, &m);
    for (int i = 0; i < m; i++) {
        int x, y, z;
        scanf("%d %d %d", &x, &y, &z);
        v[x].pb(y);
        v[y].pb(x);
    }
    int cnt = 0;
    for (int i = 1; i <= n; i++) {
        if (!vis[i]) {
            cnt++;
            dfs(i);
        }
    }
    printf("%d", cnt);
    return 0;
}


Measured memory_bytes: 12348
import logging

logging.basicConfig(level=logging.INFO, format="%(message)s")
#logging.disable(logging.CRITICAL)

def main():
    N = int(input())
    L_1 = list(map(int, input().split()))

    L_1.sort()

    logging.info(L_1)

    print(sum(L_1[::2]))
    
if __name__ == "__main__":
    main()


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

int main() {
  int a,b,c,cnt,cntt;cin >> a >> b >> c;
  cnt = abs(a-b);
  cntt = abs(a-c);
  if(cnt<cntt){
    cout << 'A' << endl;
  }else{
    cout << 'B' << endl;
  }
}

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

int MAIN()
{
	int T;
	cin >> T;
	while(T--)
	{
		int n, x;
		cin >> n >> x;
		int curXor = 0;
		if(n % 2 == 1) curXor = 127;
		int needModify = curXor ^ x;
		int lastNum = 127 ^ needModify;
		cout << (n - 1) * 127 + lastNum << endl;
	}
	return 0;
}

int main()
{
	int start = clock();
	#ifdef LOCAL_TEST
		freopen("in.txt", "r", stdin);
		freopen("out.txt", "w", stdout);
	#endif
	ios :: sync_with_stdio(false);
	cout << fixed << setprecision(16);
	int ret = MAIN();
	#ifdef LOCAL_TEST
		cout << "[Finished in " << clock() - start << " ms]" << endl;
	#endif
	return ret;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MOD = 1000000007;
//cout << setprecision(20) << 

int main() {
    ll N; cin >> N;
    string S; cin >> S;
    ll ans = 1;
    char prev = S[0];
    for (int i = 1; i < S.size(); ++i) {
        if (S[i] != prev) ans++;
        prev = S[i];
    }
    cout << ans << endl;
}

Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int a,b,c;
	cin>>a>>b>>c;
	for(long long i=a;i<=a*1000;i=a+i)
	{
		if(i%b==c)
		{
			cout<<"YES"<<endl;
			return 0;
		}
	}
	cout<<"NO"<<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <bitset>
#include <algorithm>
#include <complex>
using namespace std;
 
#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define ALL(c) (c).begin(), (c).end()
 
typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VL> VVL;
typedef vector<VI> VVI;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;
typedef vector<double> VD;

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

ll calc(VL l, VL r){
    int n = l.size();
    ll ret = 0;
    vector<PL> x(n), y(n);
    REP(i,n){
        x[i] = PL(l[i], i);
        y[i] = PL(r[i], i);
    }
    sort(ALL(x));
    reverse(ALL(x));
    sort(ALL(y));
    VI use(n);
    ll pos = 0;
    int mv = 0, ix = 0, iy = 0;
    REP(i,n){
        if (mv == 0){
            while (ix < n && use[x[ix].second]) ix++;
            if (ix < n && x[ix].first > pos){
                ret += x[ix].first - pos;
                pos = x[ix].first;
                use[x[ix].second] = 1;
            }
        }else{
            while (iy < n && use[y[iy].second]) iy++;
            if (iy < n && y[iy].first < pos){
                ret += pos - y[iy].first;
                pos = y[iy].first;
                use[y[iy].second] = 1;
            }
        }
        mv ^= 1;
    }
    ret += abs(pos);
    return ret;
}

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

    VL l(n), r(n);
    REP(i,n){
        l[i] = in();
        r[i] = in();
    }

    ll ans = calc(l, r);

    REP(i,n){
        swap(l[i], r[i]);
        l[i] *= -1;
        r[i] *= -1;
    }

    ans = max(ans, calc(l, r));
    cout << ans << endl;

    return 0;
}


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


int nb[12][10];

void fait(int K)
{
	int pre = K;
	for (int i = 0 ; i <= 9 ; i++)
	{
		nb[0][i] = 1;
	}
	for (int i = 1 ; i < 12 ; i++)
	{
		for (int j = 0 ; j < 10 ; j++)
		{
			nb[i][j] = 0;
			for (int k = -1 ; k < 2 ; k++)
			{
				int no = j + k;
				if (no >= 0 && no < 10)
				{
					nb[i][j] += nb[i - 1][no];
				}
			}
		}
	}


	//trouver nbDigits
	int nbChiffres = 0;
	vector <int> sortie;
	int somme = 0;
	int in = 1;
	while (somme <= K)
	{
		//cout<<nbChiffres<<" "<<in<<" "<<nb[nbChiffres][in]<<endl;
		if (nb[nbChiffres][in] + somme >= K) break;
		somme += nb[nbChiffres][in];
		in++;
		if (in == 10)
		{
			nbChiffres++;
			in = 1;
		}
	}
	sortie.push_back(in);
	K -= somme;
	int inActu = in;
	int pre2 = K;
	//cout<<K<<endl;
	for (int i = nbChiffres -1 ; i >= 0 ; i--)
	{
		if (inActu > 0)
		{
			if (nb[i][inActu - 1] >= K)
			{
				inActu--;
				sortie.push_back(inActu);
				continue;
			}
			if (nb[i][inActu] + nb[i][inActu - 1] >= K)
			{
				sortie.push_back(inActu);
				K-=nb[i][inActu - 1];
				continue;
			}
			if (inActu < 9)
			{
				if (nb[i][inActu + 1] + nb[i][inActu] + nb[i][inActu - 1] >= K)
				{
					K-=(nb[i][inActu] + nb[i][inActu -1]);

					inActu++;
					sortie.push_back(inActu);
					continue;
				}
			}
		}
		else
		{
			if (nb[i][inActu] >= K)
			{
				sortie.push_back(inActu);
				continue;
			}
			if (inActu < 9)
			{
				if (nb[i][inActu + 1] + nb[i][inActu]  >= K)
				{
					K-=(nb[i][inActu] );

					inActu++;
					sortie.push_back(inActu);
					continue;
				}
			}	
		}
		

	}
	for (int i = 0 ; i < sortie.size() ; i++) cout<<sortie[i];
	cout<<endl;


/*
	int nombre = 0;
	int mult = 1;
	for (int i = sortie.size() - 1 ; i>= 0 ; i--)
	{
		nombre += sortie[i] * mult;
		mult *= 10;
	}
	if (creer[pre - 1] != nombre) cout<<pre<<" "<<creer[pre - 1]<<" "<<nombre<<endl;
*/
}


bool bon(int nombre)
{
	while (nombre >= 10)
	{
		int der = nombre % 10;
		int av = (nombre / 10) % 10;
		if (abs(av - der) > 1) return false;
		nombre/=10;
	}
	return true;
}
int32_t main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	
	int K;
	cin >> K;
	fait(K);

}

Measured memory_bytes: 256
from itertools import accumulate
N, M, K = map(int,input().split())
A_list = [0] + list(map(int,input().split()))
B_list = [0] + list(map(int,input().split()))
A_sums_list = list(accumulate(A_list))
B_sums_list = list(accumulate(B_list))
ans = 0
for i, A_sums in enumerate(A_sums_list):
    B_min = -1
    B_max = M + 1
    while B_max - B_min > 1:
        B_index = int((B_max + B_min) * 0.5)
        if A_sums + B_sums_list[B_index] <= K:
            B_min = B_index
        else:
            B_max = B_index
#    B_index = int((B_max + B_min) * 0.5)
    if i + B_min > ans and A_sums + B_sums_list[B_min] <= K:
        ans = i + B_min
print(ans)

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

int main(){
  int n;
  string s;
  cin >> n >> s;
  int ans = 0;
  for(int i = 0; i < n - 2; i++){
    if(s.substr(i, 3) == "ABC")
      ans++;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;


public class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int a = in.nextInt();
        int b = in.nextInt();
        int c = in.nextInt();
        if(a==b && c==a)
            System.out.println("No");
        else if(a!=b && b!=c && c!=a)
             System.out.println("No");
        else
            System.out.println("Yes");
            
            
    }
    
}

Measured memory_bytes: 23764
#include <bits/stdc++.h>
#define ll long long
#define db double
using namespace std;
const db EPS=1e-10;
const int M=310;
int n,a[3];
db dp[M][M][M];
db dfs(int x,int y,int z)
{
    if(dp[x][y][z]>EPS)
        return dp[x][y][z];
    if(!(x+y+z)) return 0;
    db re=0;
    if(z)
        re+=dfs(x,y+1,z-1)*z;
    if(y)
        re+=dfs(x+1,y-1,z)*y;
    if(x)
        re+=dfs(x-1,y,z)*x;
    return dp[x][y][z]=1.*n/(x+y+z)+1.*re/(x+y+z);
}
int main()
{
    scanf("%d",&n);
    for(int i=0,x;i<n;i++)
        scanf("%d",&x),a[x-1]++;
    printf("%.10f\n",dfs(a[0],a[1],a[2]));
    return 0;
}


Measured memory_bytes: 225536
#!/usr/bin/env python

from collections import deque
import itertools as ite
import sys
import math

sys.setrecursionlimit(1000000)

INF = 10 ** 18
MOD = 10 ** 9 + 7

S = raw_input()
n1 = int(S[:2])
n2 = int(S[2:])
flag1 = (1 <= n1 <= 12)
flag2 = (1 <= n2 <= 12)
if flag1 and flag2:
    print "AMBIGUOUS"
elif flag1 and not flag2:
    print "MMYY"
elif not flag1 and flag2:
    print "YYMM"
else:
    print "NA"

Measured memory_bytes: 2812
#include "iostream"
#include "algorithm"
#include "string"
#include "vector"
#include "cmath"
#define lp(n) for (int i = 0; i < n; i++)
#define lop(n,i) for (int i = 0; i < n; i++)
#define INT_MAX 2147483647
#define LLINT_MAX 9223372036854775807
#define mod 1000000007
#define ll long long int
using namespace std;


int n, m;
int a, b;
bool g[8][8];
int dp[1 << 7][8];
int main(){
	cin >> n >> m;
	lp(8)
		lop(8, j) {
		g[i][j] = false;
		}
	lp(m) {
		cin >> a >> b;
		g[a - 1][b - 1] = true;
		g[b - 1][a - 1] = true;
	}

	lp(n)dp[0][i] = 0;
	dp[0][0] = 1;
	for(int i=1;i<(1<<(n-1));i++){
		m = i;
		dp[i][0] = 0;
		for (int j = 1; j < 8; j++) {
			dp[i][j] = 0;
			if (m % 2 == 1) {
				lop(n, k) {
					if (g[j][k]) {
						dp[i][j] += dp[i -(1 << (j - 1))][k];
					}
				}
			}
			m = m >> 1;
		}
	}
//	lp(4) {
//		lop(3, j) {
//			cout << i << ' ' << j << ' ' << dp[i][j] << endl;
//		}
//	}
	int ans = 0;
//	cout << (1 << (n - 1)) - 1 << endl;
	lp(n) {
//		cout<< dp[(1 << (n - 1)) - 1][i]<<endl;
		ans += dp[(1 << (n - 1))-1][i];
	}
	cout << ans << endl;
	return 0;
}

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

using ll = long long;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;


#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define all(x) (x).begin(),(x).end()
#define m0(x) memset(x,0,sizeof(x))

int dx4[4] = {1,0,-1,0}, dy4[4] = {0,1,0,-1};

class UnionFind {
  std::vector<int> p;

public:
  UnionFind(int n) : p(n, -1) {}

  int root(int x) { return p[x] < 0 ? x : p[x] = root(p[x]); }

  bool same(int x, int y) { return root(x) == root(y); }

  bool unite(int x, int y) {
    x = root(x);
    y = root(y);
    if (x == y) return false;
    if (p[y] < p[x]) std::swap(x, y);
    if (p[x] == p[y]) --p[x];
    p[y] = x;
    return true;
  }
};


int main()
{
    int n,m,k;
    cin>>n>>m>>k;
    vector<int> a(m),b(m),c(k),d(k);
    for (int i = 0; i < m; i++)
    {
        cin>>a[i]>>b[i];
        a[i]--;
        b[i]--;
    }
    for (int i = 0; i < k; i++)
    {
        cin>>c[i]>>d[i];
        c[i]--;
        d[i]--;
    }
    
    vector<int> ans(n),ufRoot(n);
    UnionFind uf(n);
    vector<unordered_set<int>> frie(n);
    for (int i = 0; i < m; i++)
    {
        uf.unite(a[i],b[i]);
        frie[a[i]].emplace(b[i]);
        frie[b[i]].emplace(a[i]);
    }
    for (int i = 0; i < n; i++)
    {
        ufRoot[uf.root(i)]++;
    }
    
    vector<unordered_set<int>> block(n);
    for (int i = 0; i < k; i++)
    {
        if(uf.root(c[i])==uf.root(d[i]))
        {
            block[c[i]].emplace(d[i]);
            block[d[i]].emplace(c[i]);
        }

    }
    for (int i = 0; i < n; i++)
    {
        cout<<ufRoot[uf.root(i)]-frie[i].size()-block[i].size()-1;
        if(i==n-1) cout<<endl;
        else cout<<" ";
    }
    
    
    return 0;
}

Measured memory_bytes: 35072
#include <iostream>
#include <bitset>
#include <string>
#include <algorithm>
#include <cmath>
using namespace std;

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

int main()
{
    string S; cin >> S;

    //int white = 0;
    //int black = 0;

    /*REP(i, S.length())
    {
        if (S[i] == 'B')
        {
            black++;
        }
        else
        {
            white++;
        }
    }*/

    //cout << "Black: " << black;
    //cout << ", White: " << white << endl;

    //int index_w = 0;
    int black = 0;
    long max = 0;
    REP(i, S.length())
    {
        if (S[i] == 'W')
        {
            max += black;
            /*max += i - index_w;
            index_w++;*/
        }
        else if (S[i] == 'B')
        {
            black++;
        }
    }

    cout << max << endl;
}

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

int main() {
  int N ;
  cin >> N ;
  
  // 1110で割った余りが10より小さい
  // 1111で割った余りが0
  // 1000で割った余りを111で割った余り0  3888 > 888 > 0
  
  if ( ( N % 1110) < 10 ){
    cout << "Yes" << endl;
  }
  else if ( N % 1111 == 0 ){
    cout << "Yes" << endl;
  }
  else if ( (N % 1000) % 111 == 0 ) {
    cout << "Yes" << endl;
  }
  else if ( (N % 1000) == 0 ) {
    cout << "Yes" << endl;
  }
  else {
    cout << "No" << endl;
  }
}


Measured memory_bytes: 3600
import sys

N,M = map(int,input().split())
s = {}
ans = 0

for i in range(N):
	a,b = map(int,input().split())
	if a in s.keys():
		s[a] += b
	else:
		s[a] = b

s = sorted(s.items(), key=lambda x:x[0])
for store in s:
	price = store[0]
	stock = store[1]
	if M == 0: break

	if M - stock >= 0:
		M -= stock
		ans += (stock * price)
	else:
		for i in range(stock):
			M -= 1
			ans += price
			if M == 0:
				print(ans)
				sys.exit()
print(ans)


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

int main() {
  int n;
  while(scanf("%d", &n), n) {
    char num[100001];
    char ans[100001];
    scanf("%s", num);
    while(n--) {
      int cnt = 0;
      int i;
      ans[0] = '\0';
      for(i = 0; num[i] != '\0'; i++) {
	if(num[i] == num[i+1]) cnt++;
	else {
	  char buf[256];
	  sprintf(buf, "%d%c", cnt+1, num[i]);
	  strcat(ans, buf);
	  cnt = 0;
	}
      }
      for(i = 0; ; i++) {
	num[i] = ans[i];
	if(ans[i] == '\0') break;
      }
    }
    puts(ans);
  }
  return 0;
}

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


void solve(long long a, long long b){
    ll ans = a;
    if(a>b) ans --;
    cout << ans << endl;
}

int main(){
    long long a;
    scanf("%lld",&a);
    long long b;
    scanf("%lld",&b);
    solve(a, b);
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<string>
#define rep(i, start, end) for (int i = (int)start; i < (int)end; ++i)
#define rrep(i, start, end) for (int i = (int)start - 1; i >= end; --i)
#define arep(i, c) for (auto i = (c).begin(); i != (c).end(); ++i)
#define all(x) (x).begin(), (x).end()
using namespace std;
typedef long long ll;
typedef pair<char, ll> P;

vector<P> run_length(string a) {
    vector<P> res;
    char now = a[0];
    ll cnt = 1;
    rep(i, 1, a.size()) {
        if (now == a[i]) ++cnt;
        else {
            res.push_back(P(now, cnt));
            now = a[i];
            cnt = 1;
        }
    }
    res.push_back(P(now, cnt));
    return res;
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    string S;
    cin >> S;
    int N = (int)S.size();
    vector<P> a = run_length(S);
    ll ans = 0;
    int start = 0;
    int stop = (int)a.size();
    if (a[0].first == '>') {
        ++start;
        rep(i, 1, a[0].second + 1) {
            ans += i;
        }
    }
    if (a[a.size() - 1].first == '<') {
        --stop;
        rep(i, 1, a[a.size() - 1].second + 1) {
            ans += i;
        }
    }
    for(int i = start; i < stop - 1; i += 2) {
        if (a[i].second < a[i + 1].second) {
            rep(j, 0, a[i].second - 1) {
                ans += j + 1;
            }
            rep(j, 0, a[i + 1].second) {
                ans += j + 1;
            }
        }
        else {
            rep(j, 0, a[i].second) {
                ans += j + 1;
            }
            rep(j, 0, a[i + 1].second - 1) {
                ans += j + 1;
            }
        }
    }
    cout << ans << endl;
    return 0;
}

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

#define REP(i,n) for(ll i=0; i<(ll)(n); i++)
#define FOR(i,n,m) for (ll i=n; i<(ll)(m); i++)
#define pb push_back
#define INF 1000000007LL
#define all(a) (a).begin(),(a).end()
#define chmin(a,b) a=min(a,b)
#define chmax(a,b) a=max(a,b)

typedef long long ll;
typedef pair<int,int> p;

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

#define MAX_N 100001

int N;
int A[MAX_N];
int main(){
    ios::sync_with_stdio(false);
    cin >> N;
    REP(i,N) cin >> A[i];
    
    int cursor = 0;
    
    int part = 1;
    while(cursor < N) {
        
        // 単調非減少
        int a = 1;
        FOR(i, cursor+1, N) {
            if (A[i-1] <= A[i]) {
                a++;
            } else {
                break;
            }
        }
        
        // 単調非増加
        int b = 1;
        FOR(i, cursor+1, N) {
            if (A[i-1] >= A[i]) {
                b++;
            } else {
                break;
            }
        }
        
        if (a < b) {
            cursor += b;
            if (cursor != N) {
                part++;
            }
        } else {
            cursor += a;
            if (cursor != N) {
                part++;
            }
        }
    }
    
    cout << part << endl;
    return 0;
}

Measured memory_bytes: 640
<?php
  $n = trim(fgets(STDIN));
  $p = explode(" " , trim(fgets(STDIN)));
  $count = 0;
  for($i=1; $i<$n-1; $i++){
      if($p[$i] > $p[$i-1] && $p[$i] < $p[$i+1]){
          $count++;
      }
      if($p[$i] < $p[$i-1] && $p[$i] > $p[$i+1]){
          $count++;
      }
  }
  echo $count;

Measured memory_bytes: 4728
n=input()
s=[[1 for i in range(13)] for j in range(4)]
for i in range(n):
  a,b=map(str,raw_input().split())
  b=int(b)
  if a=='S':s[0][b-1]=0
  elif a=='H':s[1][b-1]=0
  elif a=='C':s[2][b-1]=0
  else:s[3][b-1]=0
for i in range(4):
  for j in range(13):
    if s[i][j]:
      if i==0:print'S',j+1
      if i==1:print'H',j+1
      if i==2:print'C',j+1
      if i==3:print'D',j+1


Measured memory_bytes: 4680
s = input()
t = input()
slist = []
for i in range(0, len(s)):
	slist.append(s[i])
tlist = []
for i in range(0, len(t)):
	tlist.append(t[i])
slist.sort()
tlist.sort(reverse = True)
news = ''
for i in range(0, len(slist)):
	news = news + slist[i]
newt = ''
for i in range(0, len(tlist)):
	newt = newt + tlist[i]
if news < newt: print('Yes')
else: print('No')

Measured memory_bytes: 38384
#include <bits/stdc++.h>
#include <vector>
#include <string>
#include <algorithm>

using namespace std;

vector<string> split(const string &s, char delim) {
  vector<string> elems;
  string item;
  for (char ch: s) {
    if (ch == delim) {
      if (!item.empty()) {
        elems.push_back(item);
      }
      item.clear();
    }
    else {
      item += ch;
    }
  }
  if (!item.empty()) {
    elems.push_back(item);
  }
  return elems;
}

string to_str_with_zero(int i, int w) {
  ostringstream sout;
  sout << std::setfill('0') << std::setw(w) << i;
  string s = sout.str();
  return s;
}

int letter_to_int(char c) {
  return tolower(c) - 'a';
}

int compare_array(vector<int> a1, vector<int>a2) {
  if (a1.size() != a2.size()) {
    return a1.size() - a2.size();
  }
  for (int i=0; i<a1.size(); i++) {
    if (a1.at(i) != a2.at(i)) {
      return a1.at(i) - a2.at(i);
    }
  }
  return 0;
}

int gcd(int a, int b) {
  if (a == b) {
    return a;
  }
  else if (a > b) {
    return gcd(a - b, b);
  }
  else {
    return gcd(a, b - a);
  }
}

char int_to_char(int a) {
  if (a == -1) {
    return 'z';
  }
  else {
    return 'a' + a;
  }
}

long nCr(int n, int r) {
    long ans = 1;
    for (int i = n; i > n - r; --i) {
        ans = ans*i;
    }
    for (int i = 1 ; i < r + 1; ++i) {
        ans = ans / i;
    }
    return ans;
}

long long modinv(long long a, long long m) {
    long long b = m, u = 1, v = 0;
    while (b) {
        long long t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m; 
    if (u < 0) u += m;
    return u;
}

int divide_count(int a, int divider) {
  int r = 0;
  while(a % divider == 0) {
    a /= divider;
    r++;
  }
  return r;
}

bool is_prime(int a) {
  int i = 2;
  while(i * i <= a) {
    if(a % i == 0) {
      return false;
    }
    i++;
  }
  return true;
}

int main() {
  std::cout << std::setprecision(9);
  int a, b;
  cin >> a >> b;

  int ans = -1;
  for(int i=b*10; i<b*10+10; i++) {
    if((int)(i * 0.08) == a) {
      ans = i;
      break;
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 3612
from heapq import heappush, heappop

N, M, *A = map(int, open(0).read().split())

q = []
for v in A:
    heappush(q, -v)
    
for _ in range(M):
    v = heappop(q)
    heappush(q, -(-v // 2))
    
print(-sum(q))


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

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

	int c = 0;

	for (int i = 1; i<=3; i++)
	{
		if (N % 10 == (N / 10) % 10)
		{
			++c;
			N = N / 10;
			if (c >= 2)
			{
				break;
			}
		}
		else
		{
			c = 0;
			N = N / 10;
		}
	}

	if (c >= 2)
	{
		cout << " Yes ";
	}
	else
	{
		cout << " No ";
	}

	system("pause");
	return 0;
}

Measured memory_bytes: 504
package main

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

func getScanner(fp *os.File) *bufio.Scanner {
	scanner := bufio.NewScanner(fp)
	scanner.Split(bufio.ScanWords)
	scanner.Buffer(make([]byte, 500001), 500000)
	return scanner
}

func getNextString(scanner *bufio.Scanner) string {
	scanner.Scan()
	return scanner.Text()
}

func getNextInt(scanner *bufio.Scanner) int {
	i, _ := strconv.Atoi(getNextString(scanner))
	return i
}

func getNextInt64(scanner *bufio.Scanner) int64 {
	i, _ := strconv.ParseInt(getNextString(scanner), 10, 64)
	return i
}

func getNextUint64(scanner *bufio.Scanner) uint64 {
	i, _ := strconv.ParseUint(getNextString(scanner), 10, 64)
	return i
}

func getNextFloat64(scanner *bufio.Scanner) float64 {
	i, _ := strconv.ParseFloat(getNextString(scanner), 64)
	return i
}

func main() {
	fp := os.Stdin
	wfp := os.Stdout
	cnt := 0

	if os.Getenv("MASPY") == "ますピ" {
		fp, _ = os.Open(os.Getenv("BEET_THE_HARMONY_OF_PERFECT"))
		cnt = 1
	}
	if os.Getenv("MASPYPY") == "ますピッピ" {
		wfp, _ = os.Create(os.Getenv("NGTKANA_IS_GENIUS10"))
	}

	scanner := getScanner(fp)
	writer := bufio.NewWriter(wfp)
	solve(scanner, writer)
	for i := 0; i < cnt; i++ {
		fmt.Fprintln(writer, "-----------------------------------")
		solve(scanner, writer)
	}
	writer.Flush()
}

func solve(scanner *bufio.Scanner, writer *bufio.Writer) {
	t := getNextInt(scanner)

	for i := 0; i < t; i++ {
		a := getNextInt64(scanner)
		b := getNextInt64(scanner)
		c := getNextInt64(scanner)
		d := getNextInt64(scanner)

		if a < b {
			fmt.Fprintln(writer, "No")
			continue
		}
		if d < b {
			fmt.Fprintln(writer, "No")
			continue
		}
		if a%b > c {
			fmt.Fprintln(writer, "No")
			continue
		}
		if d == b {
			fmt.Fprintln(writer, "Yes")
			continue
		}

		g := gcd(b, d-b)
		x := a%b + g*((b-a%b)/g)
		if x >= b {
			x -= g
		}
		if x > c {
			fmt.Fprintln(writer, "No")
			continue
		}
		fmt.Fprintln(writer, "Yes")
	}
}

func gcd(m, n int64) int64 {
	if n == 0 {
		return m
	}
	return gcd(n, m%n)
}


Measured memory_bytes: 640
#include <iostream>
#include <vector>
#include <set>
#include <string>
#include <algorithm>
#include <utility>
#include <functional>
#include <queue>
#include <cmath>
#include <numeric>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <boost/math/common_factor.hpp>
#include <boost/numeric/ublas/vector.hpp>
#include <boost/numeric/ublas/matrix.hpp>
#include <boost/numeric/ublas/io.hpp>
#define REP(i, N) for(int i=0; i<(N); i++)
using namespace std;
using namespace boost::math;
using namespace boost::numeric;

int main() {
	int N;

	cin >> N;
  vector<long long> A(N+1), B(N);
  
  for (auto& i : A)
    cin >> i;
  for (auto& i : B)
    cin >> i;
  
  long long r = 0LL;
  for (int i = N-1; i >= 0;i--) {
    long long tmp = min(A[i+1], B[i]);
    r += tmp;
    B[i] -= tmp;
    tmp = min(A[i], B[i]);
    r += tmp;
    A[i] -= tmp;
    B[i] -= tmp;
  }

	cout << r << endl;

	return 0;
}


Measured memory_bytes: 1792
import java.util.Scanner;

public class Main{
	public static void main(String args[]){
		Scanner sc=new Scanner(System.in);
		int w,n;
		int a,b;
		int[] d;
		w=sc.nextInt();
		n=sc.nextInt();
		d=new int[w+1];
		for(int i=1;i<=w;i++)d[i]=i;
		for(int i=0;i<n;i++){
			String str=sc.next();
			String[] ab=str.split(",");
			a=Integer.parseInt(ab[0]);
			b=Integer.parseInt(ab[1]);
			int t=d[a];
			d[a]=d[b];
			d[b]=t;

		}
		for(int i=1;i<=w;i++)System.out.printf("%d\n",d[i]);
	}
}

Measured memory_bytes: 15396
p = int(input())
n = p%100
m = p//100
flag = 0
while n!=0:
  if n>=5:
    n-=5
    flag+=1
  elif n>=4:
    n-=4
    flag+=1
  elif n>=3:
    n-=3
    flag+=1
  elif n>=2:
    n-=2
    flag+=1
  elif n>=1:
    n-=1
    flag+=1
if flag<=m:
  print(1)
else:
  print(0)

Measured memory_bytes: 3064
#include "bits/stdc++.h"

using namespace std;

typedef unsigned long long ull;
typedef long long ll;

const int inf = 1e9 + 7;

void maxi(ll& a, ll b) {
  a = max(a, b);
}

int main() {
  int n, W;
  scanf("%d %d", &n, &W);

  vector<ll> dp(W + 1, 0);
  for (int i=0; i<n; ++i) {
    int w, v;
    scanf("%d %d", &w, &v);
    for (int x=W; x >=w; --x)
      maxi(dp[x], dp[x-w] + v);
  }
  ll ans = *max_element(begin(dp), end(dp));
  printf("%lld", ans);
  return 0;
}

Measured memory_bytes: 1024
# import numpy as np
n=int(input())
# a=np.array(list(map(int,input().split())))
a=list(map(int,input().split()))

ans=0
mod=10**9+7
for i in range(60):
    x=0
    for j in range(n):
        if (a[j] >>i&1) :x+=1

    now = x*(n-x) % mod

    for j in range(i):
        now = now*2 % mod
    ans += now
    ans %= mod

print(ans)

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

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;
}

const Int INF = 1e18;

int main(){ 
  
  Int N, K; cin >> N >> K;
  vector<Int> h(N);
  rep(i,N) cin >> h[i];
  
  vector<Int> dp(110000, INF);
  
  dp[0] = 0;
  rep(i,N-1) {
    rep1(j,K) {
      chmin(dp[i+j], dp[i] + abs(h[i+j] - h[i]));
    }
  }
  
  cout << dp[N-1] << endl;

}


Measured memory_bytes: 1920
#include<iostream>
#include<algorithm>
#include<set>
#include<math.h>
#include<vector>
#include<sstream>
#include<queue>
#include<functional>
#include<bitset>
#include<cstdio>
#include<iomanip>
#include<map>
#include<unordered_map>
#include<unordered_set>
#include <string.h>
using ll = long long;

#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define reps(i,x) for(ll i=1;i<=(ll)(x);i++)
#define rrep(i,x) for(ll i=((ll)(x)-1);i>=0;i--)
#define rreps(i,x) for(ll i=(ll)(x);i>0;i--)
#define all(x) (x).begin(),(x).end()
#define m0(x) memset(x,0,sizeof(x))
#define vll vector<ll>
#define vi vector<int>
#define vpll vector<pair<ll,ll>>
#define vpi vector<pair<int,int>>
#define mod 1000000007 
using namespace std;
int main() {
  string s;
  cin >> s;
  int cnt = 0;
  bool flg = s[1] < 'a' || s[s.size() -1] < 'a';

  for(int i = 2; i < s.size() - 1; i++){
    if(s[i] == 'C') cnt++;
    else if(s[i] < 'a'){
      flg = true;
      break;
    }
  }
  if(flg || cnt != 1){
    cout << "WA" << endl;
  }
  else if(s[0] != 'A'){
    cout << "WA" << endl;
  } else{
    cout << "AC" << endl;
  }
  return 0;
}



Measured memory_bytes: 256
#include<cstdio>
#include<queue>
#include<algorithm>
#include<cstring>
using namespace std;

#define   M             105
#define   ll            long long
#define   PI            atan(1.0)*4
#define   mst(x,v)      memset(x,v,sizeof(x))
#define   inf           (int)1e9

typedef   pair<int,int> P;
int  vis[M][M];
char a[M][M];
int  go[4][2]={0,1,0,-1,1,0,-1,0};
int h,w;
bool check(int x,int y) {
	if(x>=1 && x<=h && y>=1 && y<=w && !vis[x][y] && a[x][y]!='#')
		return 1;
	return 0;
}

struct node{
	int x,y,num;
};

int bfs() {
	mst(vis,0);
	queue<node> q;
	node t,p;
	t.x=1;t.y=1;t.num=0;
	q.push(t);
	while(!q.empty()) {
		t=q.front();
		q.pop();
		
		if(t.x == h && t.y == w)
			return t.num;
		
		int dx,dy;
		for(int i=0;i<4;i++) {
			dx=t.x+go[i][0];
			dy=t.y+go[i][1];
			if(check(dx,dy)) {
				vis[dx][dy]=1;
				p.x=dx;
				p.y=dy;
				p.num=t.num+1;
				q.push(p);
				
			}
		}
	}
	return -1;
	
}

int main() {

	int sum=0;
	scanf("%d %d",&h,&w);
	
	for(int i=1;i<=h;i++) 
		for(int j=1;j<=w;j++) {
			scanf("\n%c",&a[i][j]);
			if(a[i][j]=='.')
				sum++;
		}
	
	if(bfs()==-1) puts("-1");
	else	printf("%d\n",sum-1-bfs());
}




Measured memory_bytes: 256
#include <iostream>
#include <climits>
#include <cmath>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <string>
#include <deque>
#define INF_INT (INT_MAX / 2)
#define INF_LONG (LONG_MAX / 2)
//#define DEBUG true
#define DEBUG false
using namespace std;

const int MAX = 100001;
const int MOD = 1000000007;

typedef long long ll;
typedef pair< int, int > pii;
typedef pair< ll, ll > pll;
typedef pair< ll, int > pli;
typedef pair< int, ll > pil;

int ceil(int x, int y){
  return (x % y == 0) ? x / y : x / y + 1;
}

int gcd(int x, int y){
  return y ? gcd(y, x % y) : x;
}

int lcm(int x, int y){
  return x / gcd(x, y) * y;
}

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

  int a, b, c;
  cin >> a >> b >> c;

  if((a < c && c < b) || (b < c && c < a)) cout << "Yes" << endl;
  else cout << "No" << endl;

  return 0;
}


Measured memory_bytes: 256
import sys
sys.setrecursionlimit(1000000000)
input = sys.stdin.readline
n,m=map(int,input().split())
a=sorted([tuple(map(int,input().split())) for _ in range(m)])
i=0
cnt=0
k=n
while i<m:
    k=a[i][1]
    if a[i][0]<k:
        while i<m and a[i][0]<k:
            k=min(k,a[i][1])
            i+=1
    if i<m and a[i][0]>=k:
        cnt+=1
    else:
        cnt+=1
        i+=1
print(cnt)

Measured memory_bytes: 17808
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
typedef long long ll;
typedef pair<int, int> P;
const int INF = 100100100;
const int MOD = (int)1e9 + 7;
const double EPS = 1e-9;
struct Edge {
  ll to;
  ll cost;
};
int main() {
  int N;
  cin >> N;
  vector<ll> A(N);
  REP(i, N) cin >> A[i];
  vector<ll> ruiseki(N);
  ruiseki[0] = A[0];
  for (int i = 1; i < N; i++) {
    ruiseki[i] = A[i] + ruiseki[i - 1];
  }
  ll mn = 1e16;
  REP(i, N) {
    ll left = ruiseki[i], right = ruiseki[N - 1] - ruiseki[i];
    mn = min(mn, abs(left-right));
  }
  cout << mn << endl;
}

Measured memory_bytes: 3328
use proconio::{fastout, input};

fn main() {
    input! {
        n :usize,
    }

    let mut res = 0;
    for i in 1..=n {
        if yakusu(i) == 8 {
            res += 1;
        }
    }
    println!("{}", res);
}

fn yakusu(x: usize) -> usize {
    let mut res = 0;
    for i in (1..=x).step_by(2) {
        if x % i == 0 {
            res += 1;
        }
    }

    res
}


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

int main(){
    int n, k;
    cin >> n >> k;
    vector<int> h(n);
    rep(i,n) cin >> h[i];
    sort(h.begin(), h.end());
    ll ans = 0;
    if(k>=n){
        cout << 0 << endl;
        return 0;
    }else{
        rep(i,n-k){
            ans += h[i];
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
#include<iostream>
#include<cstdio>
#include<vector>
#include<string>
#include<algorithm>
#include<map>
using namespace std;
#define rep(i,x) for(ll i = 0; i < (ll)(x); i++)
#define rrep(i,x) for(ll i = (ll)(x)-1;0 <= i; i--)
#define reps(i,x) for(ll i = 1; i < (ll)(x)+1; i++)
#define rreps(i,x) for(ll i = (ll)(x); 1 <= i; i--)
#define debug(x) cerr << #x << ": " << (x) << "\n";
#define all(x) (x).begin(), (x).end()
typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;
typedef pair<ll,ll> Pll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef vector<vector<vector<ll>>> vvvl;
const ll INF = numeric_limits<ll>::max()/4;
const int n_max = 1e5+10;
void print() {
    cout << endl;
}

template <class Head, class... Tail>
void print(Head&& head, Tail&&... tail) {
    cout << head;
    if (sizeof...(tail) != 0) cout << ' ';
    print(forward<Tail>(tail)...);
}

template <class T>
void print(vector<T> &vec) {
    for (auto& a : vec) {
        cout << a;
        if (&a != &vec.back()) cout << ' ';
    }
    cout << endl;
}

template <class T>
void print(vector<vector<T>> &df) {
    for (auto& vec : df) {
        print(vec);
    }
}

template<class T, class U>
void print(pair<T,U> &p){
    print(p.first, p.second);
}

int main(){
    ll x,y,z; cin >> x >> y >> z;
    print(z,x,y);
}

Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
int main(){
//	freopen("a.txt","r",stdin);
	stringstream ss;
	string s;
	getline(cin,s);
	ss<<s;
	bool combo=0;
	char c;int k;
	stack<int> a;
	for(int i=0;i<s.length();i++){
		if(s[i]==' ')combo=0;
		else if(s[i]>='0'&&s[i]<='9'){
			if(combo)continue;
			else combo=1;
			ss>>k;
			a.push(k);
		}else{
			ss>>c;
			if(c=='+'){
				int y=a.top();a.pop();
				int x=a.top();a.pop();
				a.push(x+y);
			}else if(c=='-'){
				int y=a.top();a.pop();
				int x=a.top();a.pop();
				a.push(x-y);
			}else if(c=='*'){
				int y=a.top();a.pop();
				int x=a.top();a.pop();
				a.push(x*y);
			}
		}
	}
	cout<<a.top()<<endl;
	
	return 0;
}



Measured memory_bytes: 3196
#include <iostream>
#include <stdio.h>
#include <string>
#include <math.h>
#include <vector>
#include <algorithm>
#include <functional>
#include <map>
#include <climits>
#include <memory>
#include <sstream>
#include <iomanip>

using namespace std;

int main() {

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

	string s;
	cin >> s;
	int ans = 0;
	int red = 0;
	int blue = 0;
	for (int i = 0; i < s.size(); i++) {
		if (s[i] == '0') {
			if(blue == 0)red++;
			else {
				blue--;
				ans+=2;
			}
		}
		else if (s[i] == '1') {
			if (red == 0)blue++;
			else {
				red--;
				ans+=2;
			}
		}
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 512
#include <stdio.h>
int main(){
  int c1,c5,c10,c50,c100,c500,s;
  scanf("%d %d %d %d %d %d",&c1,&c5,&c10,&c50,&c100,&c500);
  s=c1+5*c5+10*c10+50*c50+100*c100+500*c500;
  if (s>=1000){
    printf("%d\n",1);
  }
  else {
    printf("%d\n",0);
  }
  return 0;
}

Measured memory_bytes: 600
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <bitset>
#include <algorithm>
#include <complex>
#include <functional>
#include <stack>
using namespace std;

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

typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<double> VD;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef vector<VD> VVD;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;
int data[10][10][10];
int main(){
  int N,M;cin>>N>>M;
  vector<int> s(M);
  VI c(M);
  REP(i,M){
    cin>>s[i]>>c[i];
  }
  REP(i,10){
    REP(j,10){
      REP(r,10){
        data[i][j][r]=0;
      }
    }
  }
if(N==3){
  REP(i,M){
    if(s[i]==1){
      REP(j,10){
        REP(r,10){
          data[c[i]][j][r]++;
        }
      }
    }
    if(s[i]==2){
      REP(j,10){
        REP(r,10){
          data[j][c[i]][r]++;
        }
      }
    }
    if(s[i]==3){
      REP(j,10){
        REP(r,10){
          data[j][r][c[i]]++;
        }
      }
    }
  }
}
if(N==2){
  REP(i,M){
    if(s[i]==1){
      REP(j,10){
        REP(r,10){
          data[j][c[i]][r]++;
        }
      }
    }
    if(s[i]==2){
      REP(j,10){
        REP(r,10){
          data[j][r][c[i]]++;
        }
      }
    }
  }
}
if(N==1){
  REP(i,M){
    if(s[i]==1){
      REP(j,10){
        REP(r,10){
          data[r][j][c[i]]++;
        }
      }
    }
  }
}


  REP(i,10){
    REP(j,10){
      REP(r,10){
        if(data[i][j][r]==M){
          if(N==1){
            if(i==0&&j==0){
              cout<<r<<endl;
              return 0;
            }
          }
          if(N==2){
            if(i==0&&j!=0){
              cout<<j<<r<<endl;
              return 0;
            }
          }
          if(N==3){
            if(i!=0){
              cout<<i<<j<<r<<endl;
              return 0;
            }
          }
        }
      }
    }
  }
  cout<<-1<<endl;
}

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

using namespace std;
using ll = long long;
using vec = vector<ll>;
using mat = vector<vec>;
using pll = pair<ll,ll>;

#define INF (1LL << 60)
#define MOD 1000000007
#define PI 3.14159265358979323846

#define REP(i,m,n) for(ll (i)=(m),(i_len)=(n);(i)<(i_len);++(i))
#define FORR(i,v) for(auto (i):v)
#define ALL(x) (x).begin(), (x).end()
#define PR(x) cout << (x) << endl
#define PS(x) cout << (x) << " "
#define SZ(x) ((ll)(x).size())
#define MAX(a,b) (((a)>(b))?(a):(b))
#define MIN(a,b) (((a)<(b))?(a):(b))
#define REV(x) reverse(ALL((x)))
#define ASC(x) sort(ALL((x)))
#define DESC(x) ASC((x)); REV((x))
#define pb push_back
#define eb emplace_back

int main()
{
    ll N, M;
    cin >> N >> M;
    vec X(M);
    REP(i,0,M) cin >> X[i];

    if(N >= M) PR(0);
    else {
        vector<pll> D(M-1);
        ASC(X);
        REP(i,0,M-1) {
            D[i].first = X[i+1] - X[i];
            D[i].second = -i;
        }
        DESC(D);
        vec P(N-1);
        REP(i,0,N-1) P[i] = -D[i].second;
        ASC(P);
        ll k = X[0], sum = 0;
        REP(i,0,N-1) {
            sum += X[P[i]] - k;
            k = X[P[i]+1];
        }
        sum += X[M-1] - k;
        PR(sum);
    }
    return 0;
}

/*



*/

Measured memory_bytes: 6064
#include <stdio.h>
int main ()
{
	int a, b, c, d, n;
	scanf("%d", &n);
	d = n / 1000;
		a = n % 10;
		c = (n - d * 1000) / 100;
		b = n % 100 / 10;
	if(d + c + b + a == 7)
	{
		printf("%d+%d+%d+%d=7\n",d,c,b,a);
		goto xx;
	}
	if(d + c + b - a == 7)
	{
		printf("%d+%d+%d-%d=7\n",d,c,b,a);
		goto xx;
	}
	if(d + c - b + a == 7)
	{
		printf("%d+%d-%d+%d=7\n",d,c,b,a);
		goto xx;
	}
	if(d - c + b + a == 7)
	{
		printf("%d-%d+%d+%d=7\n",d,c,b,a);
		goto xx;
	}
	if(d + c - b - a == 7)
	{
		printf("%d+%d-%d-%d=7\n",d,c,b,a);
		goto xx;
	}
	if(d - c - b + a == 7)
	{
		printf("%d-%d-%d+%d=7\n",d,c,b,a);
		goto xx;
	}
	if(d - c + b - a == 7)
	{
		printf("%d-%d+%d-%d=7\n",d,c,b,a);
		goto xx;
	}

	if(d - c - b - a == 7)
	{
		printf("%d+%d+%d+%d=7\n",d,c,b,a);
		goto xx;
	}
	xx:
	return 0;
}


Measured memory_bytes: 128
using System;
using System.Collections.Generic;
using System.Linq;
using System.Xml.Schema;

class IDONTKNOWCSHARP
{

    public static void Main()
    {
        int num = int.Parse(Console.ReadLine());
        int count = 0;
        int A = 1;
        int B = 1;

        int beforeBig = 0;
        while (true)
        {
            if (A * B < num)
            {
                count++;
                B++;
                beforeBig = 1;
            }
            else
            {
                if (beforeBig != 2)
                {
                    A++;
                    B = 1;
                    beforeBig = 2;
                }
                else
                {
                    break;
                }
            }
        }

        Console.WriteLine(count);
      //  Console.ReadLine();


    }


}

Measured memory_bytes: 27528
#include<bits/stdc++.h>
#define de(x) cout<<#x<<"="<<x<<endl
#define dd(x) cout<<#x<<"="<<x<<" "
#define rep(i,a,b) for(int i=a;i<(b);++i)
#define repd(i,a,b) for(int i=a;i>=(b);--i)
#define repp(i,a,b,t) for(int i=a;i<(b);i+=t)
#define mt(a,b) memset(a,b,sizeof(a))
#define fi first
#define se second
#define mp(u,v) make_pair(u,v)
#define sz(a) (int)a.size()
#define pb push_back
#define PI acos(-1.0)
#define qc std::ios::sync_with_stdio(false)
#define all(a) a.begin(),a.end()
using namespace std;
typedef vector<int> vi;
typedef long long ll;
typedef double db;
typedef pair<ll,int> pli;
typedef pair<int,int> pii;

const ll mod = 1000000007;
const int N = 2e5+6;
const int M = 2e6+6;
const double eps = 1e-6;
const int inf = 0x3f3f3f3f;

bool eq(const db &a, const db &b) { return fabs(a - b) < eps; }
bool ls(const db &a, const db &b) { return a + eps < b; }
bool le(const db &a, const db &b) { return eq(a, b) || ls(a, b); }
ll gcd(ll a,ll b) { return a==0?b:gcd(b%a,a); };
ll lcm(ll a,ll b) { return a/gcd(a,b)*b; }
ll kpow(ll a,ll b) {ll res=1;a%=mod; if(b<0) return 1; for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll read(){
    ll x=0,f=1;char ch=getchar();
    while (ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
    while (ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
    return x*f;
}
//inv[1]=1;
//for(int i=2;i<=n;i++) inv[i]=(mod-mod/i)*inv[mod%i]%mod;
int main() {
	string s; cin>>s;
	int l = 0, r = sz(s) - 1;
	int ret = 0;
	while(l <= r) {
		if(s[l] != s[r]) ret++;
		l++;
		r--;
	}
	cout<<ret<<endl;
    return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;
import java.util.Arrays;
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt(), K = sc.nextInt();
		double[] dp = new double[K + 1];
		Arrays.fill(dp, 0);
		for (int i = 1;i <= Math.min(N, K);++ i) dp[i] = 1.0 / N;
		dp[K] += (double)Math.max(0, N - K) / N;
		for (int i = 1;i < K;++ i) dp[Math.min(i * 2, K)] += dp[i] / 2;
		System.out.println(dp[K]);
	}
}

Measured memory_bytes: 23124
n, m = input().split(' ')
n = int(n)
m = int(m)
dp = [float('inf')]*(2**n)
dp[0] = 0
for i in range(m):
    a, b = input().split(' ')
    a = int(a)
    b = int(b)
    M = 0
    for j in input().split(' '):
        M += 2**(int(j)-1)

    # for j in range(2**n):
    #     dp[j|M] = min(dp[j]+a, dp[j|M])

    for j in range(2**n):
        if dp[j|M] > dp[j] + a:
            dp[j|M] = dp[j] + a

print(dp[2**n-1] if dp[2**n-1] < float('inf') else -1)

Measured memory_bytes: 3188
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
typedef long long ll;
int main(){
    ll s;
    cin>>s;
    cout<<0<<" "<<0<<" ";
    if(s<=pow(10,9)) cout<<s<<" "<<0<<" "<<0<<" "<<1;
    else{
       ll B=1000000000;
       ll C;
       if(s%B==0) C=s/B;
       else C=s/B+1;
       cout<<B<<" "<<B*C-s<<" "<<1<<" "<<C;
    }
}

Measured memory_bytes: 256
main = do
  xs <- (return . map (read::String->Int) . words) =<< getLine
  cs <- getLine
  print $ head $ foldl f xs cs
  
f [x1,x2,x3,x4,x5,x6] c |c == 'N' = [x2,x6,x3,x4,x1,x5]
f [x1,x2,x3,x4,x5,x6] c |c == 'S' = [x5,x1,x3,x4,x6,x2]
f [x1,x2,x3,x4,x5,x6] c |c == 'E' = [x4,x2,x1,x6,x5,x3]
f [x1,x2,x3,x4,x5,x6] c |c == 'W' = [x3,x2,x6,x1,x5,x4]


Measured memory_bytes: 3608
#include "bits/stdc++.h"

using namespace std;
#ifdef _DEBUG
#define _GLIBCXX_DEBUG
#include "dump.hpp"
#else
#define dump(...)
#endif

#define int long long
#define ll long long
#define DBG 1
#define rep(i, a, b) for (int i = (a); i < (b); i++)
#define rrep(i, a, b) for (int i = (b)-1; i >= (a); i--)
#define loop(n) rep(loop, (0), (n))
#define all(c) begin(c), end(c)
const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)(1e9) + 7;
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
using pii = pair<int, int>;
// template<class T> ostream &operator<<(ostream &os,T &t){dump(t);return os;}
template <typename T, typename S>istream &operator>>(istream &is, pair<T, S> &p) { is >> p.first >> p.second; return is; }
//template <typename T, typename S>ostream &operator<<(ostream &os, pair<T, S> &p) {os << p.first << " " << p.second;return os;}

template <typename T> void printvv(const vector<vector<T>> &v) {
	cerr << endl;
	rep(i, 0, v.size()) rep(j, 0, v[i].size()) {
		if (typeid(v[i][j]).name() == typeid(INF).name() and v[i][j] == INF) {
			cerr << "INF";
		}
		else
			cerr << v[i][j];
		cerr << (j == v[i].size() - 1 ? '\n' : ' ');
	}
	cerr << endl;
}

#ifndef _DEBUG
#define printvv(...)
#endif
void YES(bool f) { cout << (f ? "YES" : "NO") << endl; }
void Yes(bool f) { cout << (f ? "Yes" : "No") << endl; }
template <class T, class U>bool chmin(T& a, U b) { if (a > b) { a = b; return true; }return false; }
template <class T, class U>bool chmax(T& a, U b) { if (a < b) { a = b; return true; }return false; }

signed main(signed argc, char *argv[]) {
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(12);

	int N; cin >> N;
	string S; cin >> S;

	int e = count(all(S), 'E');
	int ans = INF;
	int w = 0;
	rep(i, 0, N) {
		if (S[i] == 'E') {
			e--;
		}
		chmin(ans, e+w);
		if (S[i] == 'W') {
			w++;
		}
	}
	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 720
#include <iostream>
#include <stack>
using namespace std;
int main( void )
{
	int n;
	stack <int> S;

	while ( cin >> n )
	{
		if ( n == 0 )
		{
			cout << S.top() << endl;
			S.pop();
		}
		else
		{
			S.push( n );
		}
	}

	return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
#define ll long long
int arr[100010];

int main() {
	int n; scanf("%d", &n);
	for( int i = 0 ; i < n ; ++i ) scanf("%d", arr+i);
	ll s = 0;
	int neg = 0, mn=0x3f3f3f3f;
	for( int i = 0 ; i < n ; ++i ) {
		if( arr[i] < 0 ) ++neg;
		arr[i] = abs(arr[i]);
		s+= arr[i];
		mn = min( mn, arr[i] );
	}
	if( neg & 1 ) s -= 2*mn;
	printf("%lld\n", s );
	return 0;
}


Measured memory_bytes: 640