akhauriyash/Code-Regression huggingface dataset:
#include <algorithm>
#include <cmath>
#include <deque>
#include <iostream>
#include <numeric>
#include <sstream>
#include <string>
#include <string.h>
#include <vector>

#define REP(i,x) for(int i{ 0 }; i < (int)(x); i++)
#define REPC(i,x) for(int i{ 0 }; i <= (int)(x); i++)
#define RREP(i,x) for(int i{ (int)(x) - 1 }; i >= 0 ;i--)
#define RREPC(i,x) for(int i{ (int)(x)}; i >= 0; i--)
#define REP1O(i,x) for(int i{ 1 }; i < (int)(x); i++)
#define REP1C(i,x) for(int i{ 1 }; i <= (int)(x); i++)

#define PB push_back
#define MP make_pair
#define F first
#define S second
#define SZ(x) ((int)(x).size())
#define ALL(x) (x).begin(),(x).end()

using namespace std;

typedef int64_t ll;
typedef pair<int, int> pii;

const int dx[4] = { 1, 0, -1,  0 };
const int dy[4] = { 0, 1,  0, -1 };
const int INTMAX = 2147483647;
const ll LLMAX = 9223372036854775807;

template<class T>bool chmax(T& a, const T& b) { if (a < b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T& a, const T& b) { if (b < a) { a = b; return 1; } return 0; }
void SWAP(ll& a, ll& b) { a ^= b; b ^= a; a ^= b; }
void SWAP(int& a, int& b) { a ^= b; b ^= a; a ^= b; }


class C {
	int c[3][3];
public:
	C()
	{
		REP(i, 3)
			REP(j, 3)
			cin >> c[i][j];
	}
	void solve()
	{
		REP(i, 2)
		{
			if (c[i][0] - c[i + 1][0] == c[i][1] - c[i + 1][1] && c[i][1] - c[i + 1][1] == c[i][2] - c[i + 1][2])
				continue;
			else
			{
				cout << "No" << endl;
				//cout << "when comparing row " << i << " and row" << i + 1 << endl;
				return;
			}
		}

		REP(j, 2)
		{
			if (c[0][j] - c[0][j + 1] == c[1][j] - c[1][j + 1]&& c[1][j] - c[1][j + 1] == c[2][j] - c[2][j + 1])
				continue;
			else
			{
				cout << "No" << endl;
				//cout << "when comparing col " << j << "and col" << j + 1 << endl;
				return;
			}

		}

		cout << "Yes" << endl;
	}
};


int main()
{
	C solution;
	solution.solve();

	return 0;
}

Measured memory_bytes: 256
use proconio::{input, fastout};
use itertools::Itertools;

#[fastout]
fn main() {
    input! {
        n: usize,
        a: [usize; n-1],
    }

    let mut sn = vec![0; n];

    for &sub in a.iter() {
        sn[sub-1] += 1;
    }

    println!("{}", sn.iter().format("\n"));
}


Measured memory_bytes: 5544
#include <bits/stdc++.h>
using namespace std;
const int maxn=300000+10;

int against;int mini;
int dir[maxn];

int main(){
	int N;
	cin>>N;string ss;cin>>ss;
	for(int i=1;i<=N;i++){
		if(ss[i-1]=='E')
			dir[i]=1,against++;
		else
			dir[i]=0;
	}
	if(dir[1]==1)
		against--;
	mini=against;
	for(int i=2;i<=N;i++){
		if(dir[i]==1){
			against--;
		}
		if(dir[i-1]==0){
			against++;
		}
		if(against<mini){
			mini=against;
		}
	}
	cout<<mini<<endl;
	return 0;
}

Measured memory_bytes: 1924
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect

def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
MOD = 10 ** 9 + 7


def main():
	N, M = MAP()
	dp = [INF]*(1<<N)
	dp[0] = 0

	for _ in range(M):
		a, b = MAP()
		c = LIST()
		d = 0
		for x in c:
			d += 1<<(x-1)

		for j in range(1<<N):
			tmp = j|d
			dp[tmp] = min(dp[tmp], dp[j]+a)

	if dp[-1] == INF:
		print(-1)
	else:
		print(dp[-1])

if __name__ == "__main__":
	main()


Measured memory_bytes: 4084
#include <bits/stdc++.h>
using namespace std;
int main()
{
	int a,b,x;
	cin>>a>>b;
	if((a+b)%2==0)
	x=(a+b)/2;
	else
	x=(a+b)/2+1;
	cout<<x<<endl;
	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#define MIN(a,b) (((a)<(b)) ? (a) : (b))
#define MAX(a,b) (((a)>(b)) ? (a) : (b))
#define RATE 5
int main(){
  int i,n,sum=100000;
  scanf("%d",&n);
  for(i=0;i<n;i++)
    {
      sum = sum*(100+RATE)/100;
      sum = ((sum%1000)>0)?(sum/1000+1)*1000:(sum/1000)*1000;
    }
  printf("%d\n",sum);
  return 0;
}

Measured memory_bytes: 592
import java.util.*;
import java.io.*;

/**
 * @author Azuz
 * 
 */
public class Main {

    void solve(Scanner in, PrintWriter out) {
      int N = in.nextInt();
      double d = in.nextDouble();
      int ans = 0;
      for (int i = 0; i < N; ++i) {
        double x = in.nextInt();
        double y = in.nextInt();

        double dist = Math.sqrt(x*x + y*y);
        if (dist <= d) {
          ++ans;
        }
      }

      System.out.println(ans);
    }

    public static void main(String[] args) {
        try(Scanner in = new Scanner(System.in);
            PrintWriter out = new PrintWriter(System.out)) {
            new Main().solve(in, out);
        }
    }
}


Measured memory_bytes: 61308
#include<bits/stdc++.h>
using namespace std;
int n; 
int a[1000],K,s,ans,b[1000],t,_t;
int main()
{
	cin>>n;
	cin>>K;
	for (int i=0;i<n;i++)
	
	   cin>>a[i],s+=a[i];
	for (int k=1;k*k<=s;k++)
	{
		_t=0;
		if (s%k) continue;
		for (int i=0;i<n;i++)
		    b[i]=a[i]%k,_t+=b[i];
		sort(b,b+n,greater<int>());
		t=_t;
		for (int i=0;i<_t/k;i++)
		    t-=b[i];
		if (t<=K) ans=k;
		k=s/k;
		_t=0;
		for (int i=0;i<n;i++)
		    b[i]=a[i]%k,_t+=b[i];
		sort(b,b+n,greater<int>());
		t=_t;
		for (int i=0;i<_t/k;i++)
		    t-=b[i];
		if (t<=K) 
		{
			cout<<k<<endl;
			return 0;
		}
		k=s/k;
	}
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 256
#define DEB
#include<bits/stdc++.h>
#define REP(i,m) for(int i=0;i<(m);++i)
#define REPN(i,m,in) for(int i=(in);i<(m);++i)
#define ALL(t) (t).begin(),(t).end()
#define CLR(a) memset((a),0,sizeof(a))
#define pb push_back
#define mp make_pair
#define fr first
#define sc second

using namespace std;


#ifdef DEB
#define dump(x)  cerr << #x << " = " << (x) << endl
#define prl cerr<<"called:"<< __LINE__<<endl
#define dumpR(x) cerr<<"\x1b[31m"<<#x<<" = " <<(x)<<"\x1b[39m"<<endl
#define dumpY(x) cerr<<"\x1b[33m"<<#x<<" = " <<(x)<<"\x1b[39m"<<endl
#define dumpG(x) cerr<<"\x1b[32m"<<#x<<" = " <<(x)<<"\x1b[39m"<<endl
template<class T> void debug(T a,T b){ for(;a!=b;++a) cerr<<*a<<' ';cerr<<endl;}
#else
#define dump(x) ;
#define dumpR(x) ;
#define dumpY(x) ;
#define dumpG(x) ;
#define prl ;
template<class T> void debug(T a,T b){ ;}
#endif

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

typedef long long int lint;
typedef pair<int,int> pi;

namespace std{
  template<class S,class T>
  ostream &operator <<(ostream& out,const pair<S,T>& a){
    out<<'('<<a.fr<<','<<a.sc<<')';
    return out;
  }
}

const lint INF=1e18;
const lint INF2=INF/2;

int n;
lint w[5005];
vector<int> g[5005];
lint dp[5005][5005][2];//[1]: contains server
void doit(lint ar1[5005][2],lint ar2[5005][2],int& n,int m){
  lint tmp[5005][2];
  REP(i,n+m+1) REP(t,2) tmp[i][t]=INF;
  REP(i,n+1) REP(j,m+1) REP(t,2) REP(s,2){
    chmin(tmp[i+j][t|s],ar1[i][t]+ar2[j][s]);
  }
  REP(i,n+m+1) REP(t,2) ar1[i][t]=tmp[i][t];
  n+=m;
}
int dfs(int v,int p){
  int size=1;
  
  if(w[v]>0){
    dp[v][0][0]=w[v];
  }
  else{
    dp[v][0][1]=w[v];
  }
  
  for(auto to:g[v]){
    if(to==p) continue;
    int s=dfs(to,v);
    doit(dp[v],dp[to],size,s);
  }
  for(int i=size;i>=0;--i) REP(t,2) if((t==0 && dp[v][i][t]<INF2)|| (t==1 && dp[v][i][t]<0)){
    chmin(dp[v][i+1][0],0ll);
  }

  return size;
}
int main(){
  cin>>n;
  REP(i,n) cin>>w[i];
  REP(i,n-1){
    int a,b;cin>>a>>b;--a;--b;
    g[a].pb(b);g[b].pb(a);
  }
  REP(i,n) REP(j,n+1) REP(t,2) dp[i][j][t]=INF;
  dfs(0,-1);
  int res=-1;
  REP(i,n) REP(t,2) if((t==0 && dp[0][i][t]<INF2) || (t==1 && dp[0][i][t]<0)){
    res=i;
    goto exi;
  }
exi:;
  cout<<res<<endl;
  return 0;
}





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

int main(){
  int n;
  cin >> n;
  vector<int> a(n);
  vector<int> b(n);
  for(int i=0;i<n;i++){
    cin >> a[i];
    b[i]=a[i];
  }
  sort(a.begin(),a.end());
  int median=a[n/2-1];
  int hitotudekai=a[n/2];
  for(int i=0;i<n;i++){
    if(b[i]<=median){
      cout << hitotudekai << endl;
    }else{
      cout << median << endl;
    }
  }

  return 0;
}


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

struct UnionFind {
    vector<int> par;
    vector<int> rank;
    UnionFind(int n) {
        par.assign(n, 0);
        iota(par.begin(), par.end(), 0);
        rank.assign(n, 0);
    }
    int find(int x) {
        if (par[x] == x) {
            return x;
        }
        return par[x] = find(par[x]);
    }
    void unite(int x, int y) {
        x = find(x);
        y = find(y);
        if (x == y) return;
        if (rank[x] < rank[y]) {
            par[x] = y;
        } else {
            par[y] = x;
            if (rank[x] == rank[y]) {
                rank[x]++;
            }
        }
    }
};

struct edge {
    int from, to, cost;
};

int main()
{
    int n;
    cin >> n;
    UnionFind uf(n);
    vector<P> xs(n);
    vector<P> ys(n);
    rep(i, n) {
        int x, y;
        cin >> x >> y;
        xs[i] = P(x, i);
        ys[i] = P(y, i);
    }
    sort(xs.begin(), xs.end());
    sort(ys.begin(), ys.end());
    vector<edge> es;
    rep(i, n) {
        if (i + 1 < n) es.push_back({xs[i].second, xs[i + 1].second, xs[i + 1].first - xs[i].first});
        if (i + 1 < n) es.push_back({ys[i].second, ys[i + 1].second, ys[i + 1].first - ys[i].first});
    }
    sort(es.begin(), es.end(), [](auto& e1, auto& e2) {
        return e1.cost < e2.cost;
    });
    ll ans = 0;
    for (int i = 0; i < es.size(); i++) {
        edge e = es[i];
        if (uf.find(e.from) != uf.find(e.to)) {
            uf.unite(e.from, e.to);
            ans += e.cost;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 7284
#include <bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define M 1000000007
#define ll long long
#define REP(i,a,b) for(ll i=a;i<b;i++)
#define REPI(i,a,b) for(ll i=b-1;i>=a;i--)
#define F first
#define S second
#define PB push_back
#define MP make_pair
#define MT make_tuple
#define G(a,b) get<a>(b)
#define VI vector<int>
#define VLL vector<long long>

#define o_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
#define o_setll tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update>
//member functions :
//1. order_of_key(k) : number of elements strictly lesser than k
//2. find_by_order(k) : k-th element in the set

ll modI(ll a, ll m);
ll gcd(ll a, ll b);
ll powM(ll x, unsigned ll y, unsigned ll m);
void pairsort(int a[], int b[], int n);
void pairsortll(ll a[],ll b[],ll n);
ll logint(ll x,ll y);


ll gcd(ll x,ll y)
{
    if(x==0) return y;
    return gcd(y%x,x);
}

ll powM(ll x,ll y,ll m)
{
    if(y==0) return 1;
    ll p=powM(x,y/2,m)%m;
    p=(p*p)%m;
    return (y%2==0)?p:(x*p)%m;
}

ll modI(ll a, ll m)
{
    ll m0=m,y=0,x=1;
    if(m==1) return 0;
    while(a>1)
    {
        ll q=a/m;
        ll t=m;
        m=a%m;
        a=t;
        t=y;
        y=x-q*y;
        x=t;
    }
    if(x<0) x+=m0;
    return x;
}

void pairsort(int a[],int b[],int n)
{
    pair<int,int> v[n];
    REP(i,0,n)
    {
        v[i].F=a[i];
        v[i].S=b[i];
    }
    sort(v,v+n);
    REP(i,0,n)
    {
        a[i]=v[i].F;
        b[i]=v[i].S;
    }
}

void pairsortll(ll a[],ll b[],ll n)
{
    pair<ll,ll> v[n];
    REP(i,0,n)
    {
        v[i].F=a[i];
        v[i].S=b[i];
    }
    sort(v,v+n);
    REP(i,0,n)
    {
        a[i]=v[i].F;
        b[i]=v[i].S;
    }
}

ll logint(ll x,ll y)
{
    ll ans=0;
    ll a=1;
    for(ll i=0;i<=x;i++)
    {
        if(x<a)
        {
            return ans;
        }
        ans++;
        a*=y;
    }
    return -1;
}

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

    /*
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    */

    ll q=1;
    //cin>>q;
    while(q--)
    {
        ll a,b;
        cin>>a>>b;
        if(abs(a-b)%2) cout<<"IMPOSSIBLE";
        else cout<<min(a,b)+abs(a-b)/2;
    }

    return 0;
}


Measured memory_bytes: 256
package main

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

var sc = bufio.NewScanner(os.Stdin)
var out = bufio.NewWriter(os.Stdout)

func main() {
	/*/TODO:!!!!!!!テスト用!!!!!!!!!
	sc = bufio.NewScanner(strings.NewReader(`


		`))
	//TODO:!!!!!!!テスト用!!!!!!!!!*/

	buf := make([]byte, 1024*1024)
	sc.Buffer(buf, bufio.MaxScanTokenSize)
	sc.Split(bufio.ScanWords)
	defer out.Flush() // !!!!caution!!!! you must use Fprint(out, ) not Print()
	/* --- code --- */

	s := next()

	re, _ := regexp.Compile("[ACGT]+")
	a := re.FindAllString(s, -1)

	ans := 0
	for i := 0; i < len(a); i++ {
		if ans < len(a[i]) {
			ans = len(a[i])
		}
	}

	//fmt.Fprintln(out, "[DEBUG]", d)
	fmt.Fprintln(out, ans)
}

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

// -*-*-*-*-*-*-*-*-
// * I/O utilities *
// -*-*-*-*-*-*-*-*-

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

func nextInt() int {
	a, _ := strconv.Atoi(next())
	return a
}

func nextFloat64() float64 {
	a, _ := strconv.ParseFloat(next(), 64)
	return a
}

func nextInts(n int) []int {
	ret := make([]int, n)
	for i := 0; i < n; i++ {
		ret[i] = nextInt()
	}
	return ret
}
func nextFloats(n int) []float64 {
	ret := make([]float64, n)
	for i := 0; i < n; i++ {
		ret[i] = nextFloat64()
	}
	return ret
}
func nextStrings(n int) []string {
	ret := make([]string, n)
	for i := 0; i < n; i++ {
		ret[i] = next()
	}
	return ret
}

func chars(s string) []string {
	ret := make([]string, len([]rune(s)))
	for i, v := range []rune(s) {
		ret[i] = string(v)
	}
	return ret
}


Measured memory_bytes: 640
n = int(input())
a = list(map(int, input().split()))
ans = 0
i = 0
while i + 1 <= len(a):
    #index+1がリストの要素と違ったら
    if a[i] != i + 1:
        #正しい要素があるか確認
        if i + 1 in a:
            #正しい要素の手前まで削除
            del a[i:a.index(i + 1)]
        #正しい要素がないなら全部削除
        else:
            del a[i:]
        
    #index+1がリストの要素と同じなら次の要素へ
    else:
        i += 1
#全部消しちゃったら不可能
if len(a) == 0:
  print(-1)
#残ってる要素を引いたら壊した数になる
else:
    print(n - len(a))

Measured memory_bytes: 26140
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Scanner;

//Compress Files
public class Main{

	int INF = 1<<29;
	void run(){
		Scanner sc = new Scanner(System.in);
		for(;;){
			int n = sc.nextInt(), m = sc.nextInt();
			if((n|m)==0)break;
			int[] a = new int[n], b = new int[n];
			for(int i=0;i<n;i++){
				b[i] = sc.nextInt(); a[i] = sc.nextInt();
			}
			int[] dp = new int[1<<n];
			Arrays.fill(dp, INF);
			dp[(1<<n)-1] = 0;
			List<Integer> l = new ArrayList<Integer>();
			l.add((1<<n)-1);
			while(!l.isEmpty()&&dp[0]==INF){
				List<Integer> next = new ArrayList<Integer>();
				for(int S:l){
					int e = m, s = (S-1)&S;
					for(int k=0;k<n;k++)if(((S>>k)&1)==0)e+=b[k]-a[k];
					while(s!=S){
						if(dp[s]==INF){
							int r = 0;
							for(int k=0;k<n;k++)if(((S>>k)&1)>0&&((s>>k)&1)==0)r+=a[k];
							if(r<=e){
								dp[s] = dp[S]+1; next.add(s);
							}
						}
						s = (s-1)&S;
					}
				}
				l = next;
			}
			System.out.println(dp[0]==INF?"Impossible":dp[0]);
		}
	}

	public static void main(String[] args) {
		new Main().run();
	}
}

Measured memory_bytes: 14000
#include<iostream>
#include<cmath>
using namespace std;
int main(){
	int a,b,c,d;
	cin >> a >> b >> c >> d;
	if(a>=d){
		cout << d;
	}else if(a+b>=d){
		cout << a;
	}else{
		cout << a-(d-b-a);
	}
	

}


	



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

typedef long long LL;
const int MAXN = 1234567;
int n,K;
struct D{
	int a,b;
}num[MAXN];
LL ans;

int main(){
	scanf("%d%d",&n,&K);
	K++;
	int i,opt;
	for(i=1;i<=n;i++){
		scanf("%d%d",&num[i].a,&num[i].b);
	}
	int Same=0;
	for(opt=30;opt>=0;opt--){
		LL tmp=0;
		if(K&(1<<opt)){
			Same^=(1<<opt);
			for(i=1;i<=n;i++){
				if((num[i].a & Same)==0){
					tmp+=num[i].b;
				}
			}
			Same^=(1<<opt);
		}
		else
			Same^=(1<<opt);
		ans=max(ans,tmp);
	}
	printf("%lld\n",ans);
}


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

typedef long long ll;
const ll INF = 1e9, MOD = 1e9 + 7;
const double EPS = 1e-9, PI = 3.141592653589793;
#define REP(i,a,b) for(ll i=a;i<b;i++)
#define rep(i,n) REP(i,0,n)
#define REPR(i,a,b) for(ll i=b;i>=a;i--)
#define repr(i,n) REPR(i,0,n)
#define all(v) (v).begin(), (v).end()
#define pb push_back
#define fi first
#define se second
#define m_p make_pair

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

    ll n,m,amount,ans=0;
    cin >> n >> m;
    vector<ll> a(n),b(n);
    rep(i,n) cin >> a[i] >> b[i];
    vector<pair<ll,ll>> p(n);
    rep(i,n) p[i] = m_p(a[i],b[i]);
    sort(all(p));
    rep(i,n){
        amount = min(m,p[i].se);
        ans += p[i].fi * amount;
        m -= amount;
        if(m==0) break;
    }
    cout << ans << "\n";
    return 0;
}

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

using namespace std;

#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define fin(ans) cout << (ans) << endl;
#define blank(ans) cout << (ans) << " ";
#define mp(p, q) make_pair(p, q)
#define pb(n) push_back(n)
#define all(a) a.begin(), a.end()

typedef long long ll;
typedef long long lli;
typedef unsigned long long ull;
typedef long double ld;
typedef string str;

typedef vector<char> vc;
typedef vector<bool> vb;
typedef vector<ld> vd;
typedef vector<str> vs;
typedef vector<ll> vll;
typedef vector<pair<ll, ll>> vpll;
typedef vector<pair<ll, str>> vpls;
typedef vector<tuple<str, ll, ll>> vtsl;
typedef vector<vector<ll>> vvll;
typedef vector<vector<char>> vvc;
typedef vector<vector<str>> vvs;

const ld PI = acos(-1.0);
const ll MAX = 9000000000000000000;
const ll MIN = -9000000000000000000;
const ld DMAX = 4500;
const ld DMIN = -4500;
const ll MOD = 1000000007;

//実行部
void Main()
{
  ll R, G, B, N; cin >> R >> G >> B >> N;
  ll r = N / R, g = N / G, b = N / B;
  ll ans = 0;
  for(ll i = 0;i <= r;i++)
  {
    for(ll j = 0;j <= g;j++)
    {
      if((N - R * i - G * j) % B == 0&&(N - R * i - G * j) >= 0)
      {
        ans++;
      }
    }
  }
  fin(ans)
  return;
}

//前処理
int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout << fixed << setprecision(20); //高精度少数表示
  Main();
  return 0;
}

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

int main(){
  int n,ans;
  ans = 0;
  cin >> n;
  vector<int> p(n);
  for(int i=0;i<n;i++){
    cin >> p.at(i);}
  
  for(int i=1;i<n-1;i++){
    if(p.at(i-1)>p.at(i)  && p.at(i)>p.at(i+1)){ans++;}
    else if(p.at(i+1)>p.at(i) && p.at(i) > p.at(i-1)){ans++;}
  }
  cout << ans << endl;
  return 0;
}
  
    
    
    
  


Measured memory_bytes: 256
S = input()

n = len(S)
Slen = 2**(n-1)
ans = 0

for i in range(Slen):
    Slis = S[0]
    for j in range(n-1):
        if i &(1 << j):
            Slis += "+"
        Slis += S[j+1]
    ans += sum(map(int,Slis.split("+")))

print(ans)


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

int main() {
    int N;
    int result = 0;
    int test = 0;
    vector<string> S;
    string SS, X;
    vector<int> T;
    int TT;
    bool B = true;

    cin >> N;

    for (int i = 0; i < N; i++) {
        cin >> SS >> TT;
        S.push_back(SS);
        T.push_back(TT);
    }

    cin >> X;

    for (int i = 0; i < N && B; i++) {
        test++;
        if (S.at(i) == X) {
            for (int j = test; j < N; j++) {
                result = result + T.at(j);
            }
            break;
            B = false;
        }
    }
    cout << result << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <sstream>
#include <string>
#include <cmath>
#include <array>
#include <vector>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <utility>
#include <iomanip>
#include <numeric>
#include <climits>
#include <algorithm>
#include <cstdint>
using namespace std;

int main()
{
    int a, b, c;
    cin >> a >> b >> c;

    int temp = a;
    a = b;
    b = temp;
    temp = a;
    a = c;
    c = temp;

    cout << a << " " << b << " " << c;
}

Measured memory_bytes: 3588
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,k,n) for(int i = (int)(k); i < (int)(n); i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(a) a.begin(), a.end()
#define MS(m,v) memset(m,v,sizeof(m))
#define D10 fixed<<setprecision(10)
typedef long long ll;
typedef long double ld;
typedef vector<ll> vi;
typedef vector<string> vs;
typedef pair <int, ll> pii;
const int MOD = 1000000007;
const int INF = MOD + 1;
const ld EPS = 1e-12;
template<class T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template<class T> T &chmax(T &a, const T &b) { return a = max(a, b); }

/*--------------------template--------------------*/

struct UnionFind
{
	vector<int> par;
	UnionFind(int n) :par(n, -1) {}
	int find(int x) { return par[x] < 0 ? x : par[x] = find(par[x]); }
	void unite(int x, int y)
	{
		x = find(x); y = find(y);
		if (x == y) return;
		if (par[y] < par[x]) swap(x, y);
		if (par[x] == par[y]) par[x]--;
		par[y] = x;
		if (find(x) != find(y)) par[find(y)] = x;
	}
	int count()
	{
		int cnt = 0;
		REP(i, par.size()) if (par[i] < 0) cnt++;
		return cnt;
	}
	bool same(int x, int y)
	{
		return find(x) == find(y);
	}
};

typedef tuple<char, vi> query;

vector<query> q;
vector<vector<pii>> es;

int main()
{
	cin.sync_with_stdio(false);
	int n, m;
	while (cin >> n >> m, n)
	{
		UnionFind uf1(n);
		q.clear();
		es.clear(); es.resize(n);
		REP(i, m)
		{
			char c;
			cin >> c;
			int p = (c == '!' ? 3 : 2);
			vi v(p);
			REP(i, p) cin >> v[i];
			v[0]--; v[1]--;
			q.emplace_back(c, v);
			if (c == '!')
			{
				uf1.unite(v[0], v[1]);
				es[v[0]].emplace_back(v[1], v[2]);
				es[v[1]].emplace_back(v[0], -v[2]);
			}
		}
		vi dist(n, INF);
		REP(i, n)
		{
			if (uf1.par[i] >= 0) continue;
			dist[i] = 0;
			queue<int> que;
			que.push(i);
			while (que.size())
			{
				int t = que.front();
				que.pop();
				for (auto j: es[t])
				{
					if (dist[j.first] != INF) continue;
					dist[j.first] = dist[t] + j.second;
					que.push(j.first);
				}
			}
		}
		UnionFind uf2(n);
		for (auto i: q)
		{
			vi v = get<1>(i);
			if (get<0>(i) == '!') uf2.unite(v[0], v[1]);
			else
			{
				if (uf2.same(v[0], v[1]))
				{
					cout << dist[v[1]] - dist[v[0]] << endl;
				}
				else
				{
					cout << "UNKNOWN" << endl;
				}
			}
		}
	}
	return 0;
}

Measured memory_bytes: 16240
#include <iostream>
#include <string>
#define GYOU_RETSU_MAX 100
using namespace std;

int main()
{
	int gyouresu[GYOU_RETSU_MAX][GYOU_RETSU_MAX];
	int bekutoru[GYOU_RETSU_MAX];
	int gyou_beku[GYOU_RETSU_MAX];
	for (int g = 0; g < GYOU_RETSU_MAX; g++)
	{
		for (int r = 0; r < GYOU_RETSU_MAX; r++)
		{
			gyouresu[g][r] = 0;
			bekutoru[r] = 0;
			gyou_beku[r] = 0;
		}
	}

	int n,m;
	cin >> n >> m;
	
	for (int g = 0; g < n; g++)
	{
		for (int r = 0; r <m ; r++)
		{
			cin >> gyouresu[g][r];
		}
	}
	
	for (int i = 0; i < m; i++)
	{
		cin >> bekutoru[i];
	}

	int g = 0;
	for (int i = 0; i < n; i++)
	{
		for (int r = 0; r < m; r++)
		{
			gyou_beku[i] = gyou_beku[i] + (gyouresu[g][r] * bekutoru[r]);
		}
		g = g + 1;
	}

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

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

class DSU:
    def __init__(self, n):
        self._n = n
        self.parent_or_size = [-1] * n

    def merge(self, a, b):
        x, y = self.leader(a), self.leader(b)
        if x == y:
            return x
        if -self.parent_or_size[x] < -self.parent_or_size[y]:
            x, y = y, x
        self.parent_or_size[x] += self.parent_or_size[y]
        self.parent_or_size[y] = x
        return x

    def same(self, a, b):
        return self.leader(a) == self.leader(b)

    def leader(self, a):
        stack = []
        while self.parent_or_size[a] >= 0:
            stack.append(a)
            a = self.parent_or_size[a]
        for i in stack:
            self.parent_or_size[i] = a
        return a

n, q = map(int, input().split())
dsu = DSU(n)

for _ in range(q):
    t, u, v = map(int, input().split())
    if t == 0:
        dsu.merge(u, v)
    else:
        print(1 if dsu.same(u, v) else 0)


Measured memory_bytes: 11988
N, M = map(int, input().split())
ks = [list(map(int, input().split())) for i in range(M)]
p = list(map(int, input().split()))
ans = 0
for i in range(2 ** N):
    flag = [False] * M
    for k in range(M):
        cnt = 0
        for j in range(N):
            if ((i >> j) & 1): 
                if j + 1 in ks[k][1:]:
                    cnt += 1
        if cnt % 2 == p[k]:
            flag[k] = True
    if all(flag):
        ans += 1       
print(ans)

Measured memory_bytes: 3064
import java.util.*;
public class Main {
 public static void main(String args[]) {
	 Scanner sc =new Scanner(System.in);
	 int N =sc.nextInt();
	 int D=sc.nextInt();
	 int t=D*2+1;
	 int ans=N%t;
	 int ans2=(int)N/t;
	
	 if(ans==0) {
		 
	 }else {
		 ans2++;
	 }
	 System.out.println(ans2);
	 

	 
 }
}



Measured memory_bytes: 21716
import java.io.*;
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        PrintWriter pw = new PrintWriter(System.out);

        int n = sc.nextInt();
        int q = sc.nextInt();

        Node[] nodes = new Node[n];
        for (int i = 0; i < n; i++) {
            nodes[i] = new Node();
        }

        for (int i = 0; i < n-1; i++) {
            int a = sc.nextInt() - 1;
            int b = sc.nextInt() - 1;
            nodes[a].children.add(nodes[b]);
            nodes[b].children.add(nodes[a]);
        }

        for (int i = 0; i < q; i++) {
            int p = sc.nextInt()-1;
            int x = sc.nextInt();
            nodes[p].sum += x;
        }

        Deque<Node> deque = new ArrayDeque<>();
        deque.add(nodes[0]);
        nodes[0].isChecked = true;
        while (!deque.isEmpty()) {
            Node node = deque.poll();
            for (Node child : node.children) {
                if (child.isChecked)
                    continue;
                child.sum += node.sum;
                child.isChecked = true;
                deque.add(child);
            }
        }

        for (Node i : nodes) {
            pw.print(i.sum + " ");
        }
        pw.println();

        pw.flush();
    }

    static class Node {
        int sum = 0;
        boolean isChecked = false;
        List<Node> children = new ArrayList<>();
    }

    static class MyScanner {
        BufferedReader reader = new BufferedReader(new InputStreamReader(System.in), 1 << 15);
        StringTokenizer tokenizer;

        String next() {
            try {
                while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                    tokenizer = new StringTokenizer(reader.readLine());
                }
            } catch (IOException ignored) {
            }
            return tokenizer.nextToken();
        }

        int nextInt() {
            return Integer.parseInt(next());
        }

        long nextLong() {
            return Long.parseLong(next());
        }
    }
}

Measured memory_bytes: 193472
N = int(input())
V = [int(zz) for zz in input().split()]

V.sort()
ans = V[0]+V[1]
for i in range(2,N):
    ans += V[i]*(2**(i-1))
ans = ans/(2**(N-1))

if ans == int(ans):
    print(int(ans))
else:
    print(ans)


Measured memory_bytes: 3060
Scanf.scanf "%d" (fun n ->
    let sq = int_of_float (sqrt (float n)) in

    let a = Array.make (n + 1) 0 in

    for x = 1 to sq do
        for y = 1 to sq do
            for z = 1 to sq do
                let v = x * x + y * y + z * z + x * y + y * z + z * x in
                if v <= n then a.(v) <- a.(v) + 1
            done
        done
    done;
    for i = 1 to n do
        Printf.printf "%d\n" a.(i)
    done
)

Measured memory_bytes: 5576
import sys
N = input()
A = list(map(int,input().split()))
B = False
total = 1
for a in A:
    if a == 0:
        print(0)
        sys.exit()
    elif total <=10**18:
        total *= a
    else:
        B = True
if B or total>10**18:
    print(-1)
else:
    print(total)
        



Measured memory_bytes: 21776
#define _CRT_SECURE_NO_WARNINGS

#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <cstring>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <list>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <unordered_set>
#include <unordered_map>
#include <array>
#include <cassert>
#include <bitset>
using namespace std;
using LL = long long;

LL N;
vector<string>vec;

int P, Q, R;

int main() {
	cin >> N;
	int ans = 0;
	for (int i = 0; i < N; ++i) {
		string tmp;
		cin >> tmp;
		vec.push_back(tmp);
		for (int j = 1; j < tmp.size(); ++j) {
			if (tmp[j - 1] == 'A' && tmp[j] == 'B') {
				++ans;
			}
		}
		if (tmp.front() == 'B' && tmp.back() == 'A') {
			++P;
		}
		else if (tmp.front() == 'B') {
			++Q;
		}
		else if (tmp.back() == 'A') {
			++R;
		}
	}
	if (P == 0) {
		ans += min(Q, R);
		cout << ans << endl;
		return 0;
	}
	ans += P - 1;
	P = 1;

	if (Q == 0 && R == 0) {
		cout << ans << endl;
	}
	else {
		ans++;
		P = 0;
		ans += min(Q, R);
		cout << ans << endl;
	}
	return 0;
}


Measured memory_bytes: 768
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep2(i, m, n) for(int i=int(m); i<int(n); i++)
#define rep(i, n) rep2(i, 0, n)
#define all(a) a.begin(), a.end()
using ll = long long;
using ld = long double;
using V = vector<int>;
using Vll = vector<ll>;
using Vld = vector<ld>;
using VV = vector<V>;
using VVll = vector<Vll>;
using VVld = vector<Vld>;
using VVVld = vector<VVld>;
using P = pair<int, int>;
using Pll = pair<ll, ll>;
using Pld = pair<ld, ld>;
const int INF = 1<<30;
const ll INFll = 1ll<<62;
const ld EPS = 1e-10;
const int MOD = int(1e9)+7;
template<typename T> inline bool chmin(T& a, T b) {if(a>b) {a=b; return true;} return false;}
template<typename T> inline bool chmax(T& a, T b) {if(a<b) {a=b; return true;} return false;}


int main() {
  int N, K; cin >> N >> K;
  V a(N);
  rep(i, N) cin >> a[i];

  VV dp(N+1, V(K+1));
  rep(i, N+1) dp[i][0] = 1;

  rep(i, N) rep2(k, 1, K+1) {
    dp[i+1][k] = dp[i+1][k-1];
    (dp[i+1][k] += dp[i][k]) %= MOD;
    if (k > a[i]) (dp[i+1][k] += MOD - dp[i][k-a[i]-1]) %= MOD;
  }

  ll ans = dp[N][K];
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 40192
#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define rep(i,a,b) for(int i = (a);i <= (b);i++)
#define pii pair<int,int>
#define pll pair<long long, long long>
#define fi first
#define se second
using namespace std;
typedef long long ll;
const ll mod = 998244353;
const ll INF = 0x3f3f3f3f3f3f3f3f;
const int inf = 0x3f3f3f3f;
const int maxn = 2e5 + 5;
const int maxm = 1e6 + 5;
const double eps = 1e-8;
const double pi = acos(-1.0);
ll gcd(ll a,ll b){return !b?a:gcd(b,a%b);}
ll poww(ll x,ll y,ll p){ll ans = 1;while(y){if(y & 1) ans = ans * x % p;x = x * x % p;y >>= 1;}return ans % p;}
string s;
int main(){
 	ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
	cin >> s;
	for(int i = 0;i < s.size();i++) cout << 'x';
	cout << endl; 
	return 0;
}

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

int main()
{
  int a = 0;
  while(1){
    int m;
    cin >> m;
    if(m == 0) break;
    int coin[4];
    cin >> coin[0] >> coin[1] >> coin[2] >> coin[3];
    int ans[4];
    fill(ans, ans+4, 20);
    int z = 0;
    for(int i = 0; i < 4; i++)
      z += ans[i];
    int u = 100;
    for(int i = 0; i <= coin[0]; i++){
      for(int j = 0; j <= coin[1]; j++){
        for(int k = 0; k <= coin[2]; k++){
          for(int l = 0; l <= coin[3]; l++){
            int x = i*10 + j*50 + k*100 + l*500 - m;
            if(x >= 0){
              int c = 0, n = 0;
              while(x >= 500){
                c++;
                x -= 500;
              }
              if(c > 0 && l > 0)
                continue;
              n += c;
              c = 0;
              while(x >= 100){
                c++;
                x -= 100;
              }
              if(c > 0 && k > 0)
                continue;
              n += c;
              c = 0;
              while(x >= 50){
                c++;
                x -= 50;
              }
              if(c > 0 && j > 0)
                continue;
              n += c;
              c = 0;
              while(x >= 10){
                c++;
                x -= 10;
              }
              if(c > 0 && i > 0)
                continue;
              n += c;
              if(coin[0] + coin[1] + coin[2] + coin[3] - (i + j + k + l) + n < u){
                ans[0] = i;
                ans[1] = j;
                ans[2] = k;
                ans[3] = l;
                z = i + j + k + l;
                u = coin[0] + coin[1] + coin[2] + coin[3] - z + n;
              }
            }
          }
        }
      }
    }
    if(a > 0)
      cout << endl;
    if(ans[0] != 0)
      cout << "10 " << ans[0] << endl;
    if(ans[1] != 0)
      cout << "50 " << ans[1] << endl;
    if(ans[2] != 0)
      cout << "100 " << ans[2] << endl;
    if(ans[3] != 0)
      cout << "500 " << ans[3] << endl;
    a = 1;
  }
}

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


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

    int a;  cin >> a;

    cout << a+pow(a,2)+pow(a,3) << endl;
    return 0;
}



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


int main() {
  int N;
  cin >> N;
  
  vector<int> A(N);
  for (int i=0; i<N; i++) {
    cin >> A.at(i);
  }
  
  int cnt = 0, min = -1;
  for (auto x : A) {
    cnt = 0;
    while (x%2==0) {
      x /= 2;
      cnt++;
    }
    if (min==-1) min = cnt;
    if (cnt<=min) min = cnt;
  }
  
  cout << min << endl;

  return 0;
}


Measured memory_bytes: 3584
#include <iostream>
using namespace std;
int gcd(int a, int b){
    if(b==0) // 再帰の終了条件
        return a;

    return gcd(b, a%b);
}
int main(){
    while(true){
        int a, b;
        cin >> a >> b;
        if(cin.eof())
            break;
        int g = gcd(a, b);
        cout << g << ' ' << a/g*b << endl;
    }
    return 0;
}


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

int main()
{
	int n;
	cin>>n;
	vector<int>a(n+1);
	vector<int>b(n);
	for(int i=0;i<n+1;i++)
		cin>>a[i];
	for(int i=0;i<n;i++)
		cin>>b[i];
	long long ans=0;
	for(int i=0;i<n;i++)
	{
		ans+=min(a[i],b[i]);
		int t=a[i];
		a[i]=max(0,a[i]-b[i]);
		b[i]-=t-a[i];
		ans+=min(a[i+1],b[i]);
		a[i+1]=max(0,a[i+1]-b[i]);
	}
	cout<<ans;

	return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <cstdio>
#include <string>
#include <list>
#include <stack>
#include <queue>
#include <algorithm>
#include <utility>
#include <vector>
#include <map>

using namespace std;

int main()
{
	int N;
	int maxcost=0;
	vector<pair<int,int> > cost;
	cin>>N;
	vector<int> parent(N,-1);
	pair<int,int> ddata;
	for(int i=0;i<N*N;i++){
		cin>>ddata.first;
		if(ddata.first!=-1){
			ddata.second=i;
			cost.push_back(ddata);
		}
	}
	sort(cost.begin(),cost.end());
	for(int i=0;i<cost.size();i++){
		while(parent[cost[i].second/N]!=-1&&parent[parent[cost[i].second/N]]!=-1){
			parent[cost[i].second/N]=parent[parent[cost[i].second/N]];
		}
		while(parent[cost[i].second%N]!=-1&&parent[parent[cost[i].second%N]]!=-1){
			parent[cost[i].second%N]=parent[parent[cost[i].second%N]];
		}
		if(parent[cost[i].second/N]!=cost[i].second%N&&parent[cost[i].second%N]!=cost[i].second/N&&(parent[cost[i].second%N]!=parent[cost[i].second/N]||parent[cost[i].second/N]==-1||parent[cost[i].second%N]==-1)){
			//cout<<' '<<cost[i].second/N<<' '<<cost[i].second%N<<endl;
			maxcost+=cost[i].first;
			if(parent[cost[i].second/N]==-1){
				if(parent[cost[i].second%N]!=-1){
					parent[parent[cost[i].second%N]]=cost[i].second/N;
				}
				parent[cost[i].second%N]=cost[i].second/N;
			}else if(parent[cost[i].second%N]==-1){
				parent[parent[cost[i].second/N]]=cost[i].second%N;
				parent[cost[i].second/N]=cost[i].second%N;
			}else{
				parent[parent[cost[i].second%N]]=parent[cost[i].second/N];
				parent[cost[i].second%N]=parent[cost[i].second/N];
			}
		}
		int c=0;
		for(int i=0;i<N;i++){
			if(parent[i]==-1){
				c++;
			}
		}
		if(c<2){
			break;
		}
	}
	cout<<maxcost<<endl;
	/*
	for(int i=0;i<N;i++){
		cout<<parent[i]<<endl;
	}//*/
	return 0;
}

Measured memory_bytes: 1324
#include<iostream>
#include<string>
#include<algorithm>
#include<bits/stdc++.h>
using namespace std;

int main(){
  int N,a,b;
  cin >> N;
  long long X[N+1],Y[N+1];
  for(int i=0; i<N; i++){
    cin >> X[i];
    Y[i]=X[i];
  }
  sort(X,X+N);
  a=X[N/2-1];
  b=X[N/2];
 
 for(int j=0; j<N; j++){
   if(Y[j]<=a){
     cout << b << endl;
   }else{
     cout << a << endl;
   }
 }
}


Measured memory_bytes: 5248
#include<bits/stdc++.h>
using namespace std;
#define result(a) cout<<a<<endl;
int main()
{
    string s,t;
    int n,i,cnt=0;
    cin>>s>>t;

    if(s==t)
    {
        result(0);
    }
    else
    {
        for(i=0;i<s.size();i++)
        if(s[i]!=t[i])cnt++;

        result(cnt);
    }
    


}

Measured memory_bytes: 3920
N,M=map(int,input().split())

AB=[list(map(int,input().split()))for _ in range(N)]
CD=[list(map(int,input().split()))for _ in range(M)]

ans=[0]*N
i=0
while i<N:
    count=0
    j=0
    distance=abs(AB[i][0]-CD[j][0])+abs(AB[i][1]-CD[j][1])
    while j<M:
        if distance>abs(AB[i][0]-CD[j][0])+abs(AB[i][1]-CD[j][1]):
            count=j
            distance=abs(AB[i][0]-CD[j][0])+abs(AB[i][1]-CD[j][1])
        j+=1
    ans[i]=count
    i+=1

for k in ans:
    print(k+1)

Measured memory_bytes: 3064
#include <stdio.h>

int main(void){
	int H, W, i, j;
	scanf("%d %d", &H, &W);

	while (H!=0 && W!=0){
		if (3 <= H && H <= 300 && 3 <= W && W <= 300){
			for (i = 0; i < H; i++){
				for (j = 0; j < W; j++){
					if (i == 0 || i==H-1)printf("#");
					else {
						if (j == 0 || j == W - 1) printf("#");
						else printf(".");
					}
				}
				printf("\n");
			}
		}
		printf("\n");
		scanf("%d %d", &H, &W);
	}

	return 0;
}

Measured memory_bytes: 572
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
int main(){
  int n,m,a,tt,th,sa,flag;
  vector<int> t;
  vector<int> h;
  while(1){
    //skk
    tt=0;
    th=0;
    t.clear();
    h.clear();
      
    flag=0;
    //in
    cin >> n >> m;
    if(n==0&&m==0)break;
    for(int i=0;i<n;i++){
      cin >> a;
      t.push_back(a);
      tt+=a;
    }
    for(int i=0;i<m;i++){
      cin >> a;
      h.push_back(a);
      th+=a;
    }
    if((tt+th)%2!=0){
      cout << -1 << endl;
      continue;
    }
    sort(t.begin(),t.end());
    sa=th-tt;
    for(int i=0;i<n;i++){
      for(int j=0;j<m;j++){
	if(t[i]+sa/2==h[j]){
	  cout << t[i] << " " << h[j] << endl;
	  flag=1;
	  break;
	}
      }
      if(flag==1)break;
    }
    if(flag==0)cout << -1 << endl;
  }
  return 0;
}

Measured memory_bytes: 1220
#include <bits/stdc++.h>
using namespace std;
 
int main(){
    char X, Y;
    cin >> X >> Y;

    if(X < Y){
        cout << "<" << endl;
    }else if(X > Y){
        cout << ">" << endl;
    }else{
        cout << "=" << endl;
    }

}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define SZ(x) ((int)x.size())
#define ALL(x) x.begin(),x.end()
#define L(i,u) for (register int i=head[u]; i; i=nxt[i])
#define rep(i,a,b) for (register int i=(a); i<=(b); i++)
#define per(i,a,b) for (register int i=(a); i>=(b); i--)
using namespace std;
typedef long double ld;
typedef long long ll;
typedef unsigned int ui;
typedef pair<int,int> Pii;
typedef pair<ll,ll> Pll;
typedef vector<int> Vi;
template<class T> inline void read(T &x){
	x=0; char c=getchar(); int f=1;
	while (!isdigit(c)) {if (c=='-') f=-1; c=getchar();}
	while (isdigit(c)) {x=x*10+c-'0'; c=getchar();} x*=f;
}
template<class T> T gcd(T a, T b){return !b?a:gcd(b,a%b);}
template<class T> inline void umin(T &x, T y){x=x<y?x:y;}
template<class T> inline void umax(T &x, T y){x=x>y?x:y;}
mt19937 R(chrono::system_clock().now().time_since_epoch().count());

const int N = 122;
int n,m;char s[N][N];
int f[N][N];
int main() {
	read(n);read(m);
	rep(i,1,n)scanf("%s",s[i]+1);
	rep(i,0,n)rep(j,0,m)f[i][j]=1e9;
	f[1][1]=s[1][1]=='#';
	rep(i,1,n)rep(j,1,m)if(i+j>2){
		f[i][j]=min(f[i-1][j]+(s[i][j]=='#'&&s[i-1][j]!='#'),f[i][j-1]+(s[i][j]=='#'&&s[i][j-1]!='#'));
	}
	cout<<f[n][m];
	return 0;
}


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

#ifdef DEBUG
#define PRINT(x)\
    cout<<"func "<<__func__<<": line "<<__LINE__<<": "<<#x<<" = "<<(x)<<endl;
#define PRINTA(a,first,last)\
    cout<<"func "<<__func__<<": line "<<__LINE__<<": "<<#a<<"["<<(first)<<", "<<(last)<<")"<<endl;\
    for (int i=(first);i<(last);++i){cout<<#a<<"["<<i<<"] = "<<(a)[i]<<endl;}
#define PRINTP(p)\
    cout<<"func "<<__func__<<": line "<<__LINE__<<": "<<#p<<" = ("<<(p.first)<<", "<<(p.second)<<")"<<endl;
#define PRINTI(a,i)\
    cout<<"func "<<__func__<<": line "<<__LINE__<<": "<<#a<<"["<<#i<<"] = "<<#a<<"["<<(i)<<"] = "<<(a)[i]<<endl;
#else
#define PRINT(x)
#define PRINTA(a,first,last)
#define PRINTP(p)
#define PRINTI(a,i)
#endif

#define FOR(i,a,b) for (int i=(a);i<(b);++i)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);--i)
#define REP(i,n) for (int i=0;i<(n);++i)
#define RREP(i,n) for (int i=(n)-1;i>=0;--i)
#define pb push_back
#define mp make_pair
#define all(a) (a).begin(),(a).end()
#define MOD 1000000007

using namespace std;

using ll = long long;
using ull = unsigned long long;
using pii = pair<int, int>;

template <class T, class U> void amax(T& x, U y) {if (x < y) x = y;}
template <class T, class U> void amin(T& x, U y) {if (x > y) x = y;}

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

template <class Pred>
ll partition_point_ll(ll first, ll last, Pred p) {
    ll count = last - first;
    while (count > 0) {
        ll step = count / 2;
        ll mid = first + step;
        if (p(mid)) {
            first = mid + 1;
            count -= step + 1;
        } else {
            count = step;
        }
    }
    return first;
}

// if x is square, return sqrt(x),
// else return -1
ll sqrt_ll(ll x) {
    function<ll(ll)> p = [=](ll y) { return y * y < x; };
    ll y = partition_point_ll(0, x + 1, p);
    if (y * y == x) {
        return y;
    } else {
        return -1;
    }
}

int main() {
    int N, D;
    cin >> N >> D;
    vector<vector<int>> X(N, vector<int>(D));
    REP(i, N) REP(j, D) cin >> X[i][j];
    int result = 0;
    REP(i, N) FOR(j, i + 1, N) {
        int d2 = 0;
        REP(k, D) {
            int dx = X[i][k] - X[j][k];
            d2 += dx * dx;
        }
        if (sqrt_ll(d2) != -1) {
            ++result;
        }
    }
    cout << result << endl;

    return 0;
}



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

using namespace std;

int main() {
  // Put your favorite codes here
  int n, m;
  int buf[30];

  cin >> n >> m;
  for(int i=0; i<30; i++) {
    if(i < m) {
      buf[i] = 1;
    } else {
      buf[i] = 0;
    }
  }

  for(int i=0; i<n; i++) {
    int k;
    cin >> k;
    for(int j=0; j<k; j++) {
      int a;
      cin >> a;
      if(buf[a-1] != 0) {
        buf[a-1] = 2;
      }
    }
    for(int j=0; j<m; j++) {
      if(buf[j] == 2) {
        buf[j] = 1;
      } else {
        buf[j] = 0;
      }
    }
  }

  int res = 0;
  for(int i=0; i<m; i++) {
    res += buf[i];
  }

  cout << res << endl;
  
  return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);

		String A = sc.next();
		String B = sc.next();
		String C = sc.next();
		String ans = "";

		if ( A.substring(A.length() -1).equals(B.substring(0,1)) &&  B.substring(B.length() -1).equals(C.substring(0,1))) {
			ans = "YES";
		} else {
			ans = "NO";
		}

		System.out.println( ans );
	}
}

Measured memory_bytes: 21844
n, m, x = map(int, input().split())
ca = []
for _ in range(n):
    ca.append(list(map(int, input().split())))

INF = float("inf")
ans = INF

for i in range(2**n):
    A = [0] * m
    price = 0

    # j番目の本について
    for j in range(n):
        if i>>j & 1:
            price += ca[j][0]
            for k in range(m):
                A[k] += ca[j][k+1]

    gtX = True
    for j in range(m):
        if A[j] < x:
            gtX = False
            break
    if gtX:
        ans = min(ans, price)

if ans == INF:
    ans = -1
print(ans)




Measured memory_bytes: 9028
n,m=map(int,input().split())
al=[]
cl=[]
for i in range(n):
    al.append(list(map(int,input().split())))
for i in range(m):
    cl.append(list(map(int,input().split())))
for i in range(n):
    cost=[]
    for j in range(m):
        cost.append(abs(al[i][0]-cl[j][0])+abs(al[i][1]-cl[j][1]))
    print(cost.index(min(cost))+1)

Measured memory_bytes: 3064
#include<stdio.h>
#include<string.h>
#include<ctype.h>

int main(){
	char word[10];
	char T[1000];
	char end[]="END_OF_TEXT";
	int count=0;
	int i=0;
	
	scanf("%s",word);
	
	while(1){
		scanf("%s",T);
		if(strcmp(T,end)==0){
			break;
		}
		while(T[i]!='\0'){
			if(isupper(T[i])){
				T[i]=tolower(T[i]);
			}
			i++;
		}
		i=0;
		
		if(strcmp(T,word)==0){
			count++;
		}
	}
	printf("%d\n",count);
	
	return 0;
}

Measured memory_bytes: 552
#include <bits/stdc++.h>
#define int long long
#define mod (int)(1e9+7)
#define inf (int)(3e18+7)
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,n) for(int i=1;i<n;i++)
#define P pair<int,int>
#define PiP pair<int,pair<int,int>>
#define all(v) v.begin(),v.end()
#define mkp make_pair
#define mkt make_tuple
#define prique(T) priority_queue<T,vector<T>,greater<T>>
#define vecunique(vec) sort(vec.begin(), vec.end());decltype(vec)::iterator result = std::unique(vec.begin(), vec.end());vec.erase(result, vec.end())
using namespace std;

bool prime(int x) {
	for (int i = 2; i * i <= x; i++) {
		if (x % i == 0)return false;
	}
	return x > 1;
}
int gcd(int x, int y) {
	if (y == 0)return x;
	return gcd(y, x % y);
}
int lcm(int x, int y) {
	return x / gcd(x, y) * y;
}
int kai(int x) {
	if (x == 0)return 1;
	return kai(x - 1) * x % mod;
}
int mod_pow(int x, int y, int mod_) {
	int res = 1;
	while (y > 0) {
		if (y & 1) {
			res = res * x % mod_;
		}
		x = x * x % mod_;
		y >>= 1;
	}
	return res;
}
int comb(int x, int y) {
	if (y > x)return 0;
	return kai(x)* mod_pow(kai(x - y), mod - 2, mod) % mod * mod_pow(kai(y), mod - 2, mod) % mod;
}
/*--------Library Zone!--------*/
/*
	int a, b; cin >> a >> b;
	cout << (a * 3 + b) / 2 << endl;
	*/
int n;
pair<string, P>p[114];
signed main() {
	cin >> n;
	rep(i, n) {
		cin >> p[i].first >> p[i].second.first;
		p[i].second.second = i + 1;
		p[i].second.first *= -1;
	}
	sort(p, p + n);
	rep(i, n)cout << p[i].second.second << endl;
}


Measured memory_bytes: 256
#include <stdio.h> 
#define SEATS (100000)
int N;
int l[SEATS];
int r[SEATS];

void input(void){
	scanf("%d",&N);
	int i=0;
	for(i=0;i<N;i++){
		scanf("%d %d",l+i,r+i);
	}
}


int main(void){
	input();	
	int i=0;
	int sum = 0;
	for(i=0;i<N;i++){
		sum+=r[i]-l[i]+1;
	}
	printf("%d\r\n",sum);
	return 0;

}

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

#define ll long long
#define vi vector<int>
#define pi pair<int, int>
  
using namespace std;                           

int a, b;

int main(){
	cin >> a >> b;
	if((a == 1 && b == 2) || (a == 2 && b == 1)){
		cout << 3;
		return 0;
	}
	if((a == 1 && b == 3) || (a == 3 && b == 1)){
		cout << 2;
		return 0;
	}
	else {
		cout << 1;
		return 0;
	}
	return 0;
}	

Measured memory_bytes: 256