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

//.define
// #define FILE_IN_OUT
#define RET(_x)    return cout << (_x) << '\n', 0;
#define all(_obj)  (_obj).begin(), (_obj).end()
#define loop(_n)   for (int i = 0; i < (_n); ++i)
#define sz(_obj)   static_cast<int>((_obj).size())
#ifdef SHJ_LOCAL
#define debug(_x)  std::cerr << (#_x) << " = " << (_x) << '\n' << std::flush;
#else
#define debug(_x)  {}
#endif
#define endl "\n"
template<typename P, typename Q>
P CeilDiv(P _dividend, Q _divider) {
    return static_cast<P>((_dividend - 1LL + _divider) / _divider);
}
template<typename Tp>
inline void outarr(Tp _begin, Tp _end, const char* _delim = " ") {
    for (Tp current = _begin; current != _end; ++current) {
        std::cout << *current << _delim;
    }
    std::cout << '\n';
}

//.constant
using ll  = long long;
using pii = std::pair<int, int>;
constexpr int INF = 0x3f3f3f3f;
constexpr int MOD = static_cast<const int>(1e9 + 7);

//.data
constexpr int MAXN = 1000;

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

string gr[MAXN];
int dist[MAXN][MAXN];

void Bfs(vector<pii>& vec, int n, int m) {
    queue<pii> q;
    for (auto [xs, ys] : vec) {
        q.emplace(xs, ys);
        dist[xs][ys] = 0;
    }
    vec.clear();
    while (!q.empty()) {
        auto [x, y] = q.front();
        vec.emplace_back(x, y);
        q.pop();
        for (int k = 0; k < 4; ++k) {
            int nx = x + dx[k];
            int ny = y + dy[k];
            if (0 <= nx && nx < n && 0 <= ny && ny < m && gr[nx][ny] == '.' && dist[nx][ny] == -1) {
                dist[nx][ny] = dist[x][y] + 1;
                q.emplace(nx, ny);
            }
        }
    }
}

//.code
int main() {
#ifdef FILE_IN_OUT
    std::ifstream cin ("input.txt",  std::ios::in);
    std::ofstream cout("output.txt", std::ios::out);
#else
    std::ios_base::sync_with_stdio(false);
    std::cin.tie(nullptr);
#endif

    int n, m, xs, ys, xt, yt;
    cin >> n >> m >> xs >> ys >> xt >> yt;
    --xs; --ys;
    --xt; --yt;
    loop(n) {
        cin >> gr[i];
    }
    memset(dist, -1, sizeof(dist));
    vector<pii> vec, nv;
    vec.emplace_back(xs, ys);
    for (int ans = 0;; ++ans) {
        Bfs(vec, n, m);
        if (dist[xt][yt] != -1) {
            RET(ans);
        }
        if (vec.empty()) {
            RET(-1);
        }
        for (auto [x, y] : vec) {
            int lx = max(0, x - 2);
            int rx = min(n - 1, x + 2);
            int ly = max(0, y - 2);
            int ry = min(m - 1, y + 2);
            for (int i = lx; i <= rx; ++i) {
                for (int j = ly; j <= ry; ++j) {
                    if (gr[i][j] == '.' && dist[i][j] == -1) {
                        dist[i][j] = 0;
                        nv.emplace_back(i, j);
                    }
                }
            }
        }
        vec = nv;
        nv.clear();
    }

#ifdef FILE_IN_OUT
    cin.close();
    cout.close();
#endif
    return 0;
}

Measured memory_bytes: 8696
#include<stdio.h>
int main(){
  int n,number,card[4][14];
  int i,j;
  char s;
  for(i=0;i<=13;i++){
    card[0][i]=1;
    card[1][i]=1;
    card[2][i]=1;
    card[3][i]=1;
  }
  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf(" %c %d",&s,&number);
         if(s=='S')card[0][number]=0;
    else if(s=='H')card[1][number]=0;
    else if(s=='C')card[2][number]=0;
    else if(s=='D')card[3][number]=0;
  }
  for(i=0;i<4;i++){
    for(j=1;j<=13;j++){
      if(card[i][j]!=0){
    if(i==0)s='S';
    else if(i==1)s='H';
    else if(i==2)s='C';
    else if(i==3)s='D';
    printf("%c %d\n",s,j);
      }
    }
  }
  return(0);
}

Measured memory_bytes: 596
#include <stdio.h>
#define ll long long
#define rep(i,l,r)for(ll i=(l);i<(r);i++)
#define INF ((1LL<<62)-(1LL<<31))
#define min(p,q)((p)<(q)?(p):(q))

#define dinicVmax 110
ll vcnt;//頂点数
ll resflow[dinicVmax][dinicVmax];//残り流量
ll dist[dinicVmax];//ソースからの距離
ll checked[dinicVmax];//dfsの行き止まりフラグ
void dinicbfs(ll s){
	rep(i,0,vcnt)dist[i]=-1;
	dist[s]=0;
	//まだ流せる辺だけを使ってbfs
	ll que[dinicVmax*dinicVmax];
	ll qcnt=0,qptr=0;
	que[qcnt++]=s;
	while(qcnt!=qptr){
		ll a=que[qptr++];
		rep(b,0,vcnt)if(resflow[a][b]>0&&dist[b]==-1){
			dist[b]=dist[a]+1;
			que[qcnt++]=b;
		}
	}
}
ll dinicdfs(ll a,ll t,ll m){
	//aはm受け取ってる(⇔aから最大m流せる)
	//いくら流せるかを返す
	if(a==t)return m;
	if(checked[a])return 0;
	ll ans=0;
	checked[a]=1;
	rep(b,0,vcnt)if(dist[b]>dist[a]&&resflow[a][b]>0){
		ll addedflow=dinicdfs(b,t,min(m,resflow[a][b]));
		if(addedflow){
			resflow[a][b]-=addedflow;
			resflow[b][a]+=addedflow;
			checked[a]=0;
			ans+=addedflow;
			m-=addedflow;
			if(m<=0)break;
		}
	}
	return ans;
}
//ソース,シンク
ll dinic(ll s,ll t){
	ll ans=0;
	ll flag=1;
	while(flag){
		flag=0;//更新フラグ
		dinicbfs(s);
		while(!checked[s]){
			ll addedflow=dinicdfs(s,t,INF);
			ans+=addedflow;
			if(addedflow)flag=1;
		}
		rep(i,0,vcnt)checked[i]=0;
	}
	return ans;
}

int main(){
    ll ecnt;
    scanf("%lld%lld",&vcnt,&ecnt);
    rep(i,0,ecnt){
        ll a,b,c;
        scanf("%lld%lld%lld",&a,&b,&c);
        resflow[a][b]=c;
    }
    printf("%lld\n",dinic(0,vcnt-1));
}


Measured memory_bytes: 2064
#! /usr/bin/env python3

import sys
import numpy as np
int1 = lambda x: int(x) - 1
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(500000)


def query(q):
    print(q, flush=True)
    s = readline().decode().rstrip()
    if s[0] == 'V':
        sys.exit()
    return s


N = int(readline())

s = query(0)
l = 0
r = N
sex = s

while True:
    m = (l + r) // 2
    s = query(m)
    if sex == s:
        if (m - l) % 2:
            r = m
        else:
            l = m
    else:
        if (m - l) % 2:
            l = m
            sex = s
        else:
            r = m

Measured memory_bytes: 27112
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cmath>
#include <queue>
#include <map>
#include <unordered_map>
#include <set>
#include <functional>
using namespace std;

typedef long long ll;


int main() {
	int N, K, Q; cin >> N >> K >> Q;
	vector<int> a(N + 2);
	for (int i = 0; i < N; i++) cin >> a[i];
	a[N] = -1;
	int ans = 1e9;
	for (int i = 0; i < N; i++) {
		vector<int> q;
		int left = 0, right = 0;
		while (right <= N) {
			if (a[right] < a[i]) {
				priority_queue<int> que;
				for (int j = left; j < right; j++) que.push(-a[j]);
				for (int j = 0; j <= right - left - K; j++) q.push_back(-que.top()), que.pop();
				left = right + 1;
			}
			right++;
		}
		sort(q.begin(), q.end());
		if ((int)q.size() >= Q) ans = min(ans, q[Q - 1] - a[i]);
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 384
// Package main provides
//
// File:  main.go
// Author: ymiyamoto
//
// Created on Fri Aug 16 09:49:15 2019
//
package main

import "fmt"

func max(a, b int) int {
	if a < b {
		return b
	}
	return a
}

func main() {
	var a, b int
	fmt.Scanf("%d %d", &a, &b)
	fmt.Println(max(max(a+b, a-b), a*b))
}


Measured memory_bytes: 512
ABC = list(map(int, input().split()))
K = int(input())

A = ABC[0]
B = ABC[1]
C = ABC[2]

for i in range(0, K):
    if A >= B :
        B = 2*B
    elif B >= C:
        C = 2*C

if A < B < C:
    print("Yes")
else:
    print("No")



Measured memory_bytes: 9168
#include<bits/stdc++.h>
using namespace std;
#define FAST ios_base::sync_with_stdio(false);cin.tie(NULL);
#define ll long long int
#define ull unsigned long long int
#define ld long double
#define mod 1000000007
#define inf 1000000000000000007
#define eps 0.000001
#define pi 3.141592653589793
#define pii pair<int , int>
#define pdd pair<ld,ld>
#define pll pair<ll,ll>
#define ff first
#define ss second
#define vii vector<int>
#define vpl vector<pll>
#define vll vector<ll>
#define sti stack <int>
#define stll stack <ll>
#define mseti set <ll>
#define msetd multiset <ll, greater <ll> >
#define mp make_pair
#define pb push_back
#define lb lower_bound
#define ub upper_bound 
#define stp setprecision(20)//use fixed before stp
#define endl '\n'
ll find(ll gro[],ll sum[],ll mask)
{
    if(mask==0)
        return 0;
    if(gro[mask]!=-1)
        return gro[mask];
    ll val=-inf;
    for(ll i=mask;i>0;i=mask&(i-1))
    {
        val=max(val,sum[i]+find(gro,sum,(mask^i)));
    }
    gro[mask]=val;
    return val;

}
int main()
{  
    FAST
    ll n;
    cin>>n;
    ll max=pow(2,n);
    ll sum[max];
    ll gro[max];
    max--;
    ll a[n+1][n+1];
    for(ll i=1;i<=n;i++)
    {
        for(ll j=1;j<=n;j++)
        {
            cin>>a[i][j];
        }
    }
    for(ll i=0;i<=max;i++)
    {
        gro[i]=-1;
        sum[i]=0;
    }
    for(ll i=1;i<=n;i++)
    {
        for(ll j=1;j<i;j++)
        {
            ll q=((1<<(i-1))|(1<<(j-1)));
            for(ll k=0;k<=max;k++)
            {
                if((q&k)==q)
                {
                    sum[k]+=a[i][j];
                }
            }
        }
    }
    cout<<find(gro,sum,max);
}

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

int conv(char c) {
  if(islower(c)) return c - 'a';
  else return c - 'A' + 26;
}

char conv(int x) {
  if(x < 26) return x + 'a';
  else return x - 26 + 'A';
}

int main() {
  for(int n; cin >> n && n;) {
    vector<int> k(n);
    for(int i = 0; i < n; ++i) cin >> k[i];
    string s; cin >> s;
    for(int i = 0; i < s.size(); ++i) {
      cout << conv((conv(s[i]) - k[i%n] + 52) % 52);
    }
    cout << endl;
  }
  return 0;
}

Measured memory_bytes: 1204
#!/usr/bin/env python3
n, *h = map(int, open(0).read().split())
ans = 0
b = ["1"] * n
while sum(h) > 0:
    for i in range(n):
        if h[i] > 0:
            h[i] -= 1
        else:
            b[i] = "0"
    ans += sum(i != "" for i in "".join(b).split("0"))
print(ans)


Measured memory_bytes: 9076
#include<bits/stdc++.h>
#define p pair<pair<string,int>,int>
using namespace std;
int main(){
	int n;
	cin>>n;
	vector<p>arr(n);
	for(int i=0;i<n;i++){
		cin>>arr[i].first.first>>arr[i].first.second;
		arr[i].first.second*=-1;
		arr[i].second=i+1;
	}
	sort(arr.begin(),arr.end());
	for(int i=0;i<n;i++){
		cout<<arr[i].second<<"\n";
	}
	return 0;
}

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

int main(){
    int A = 0;
    int B = 0;
    cin >> A >> B;
    cout << A*B << endl;
    return 0;
}

Measured memory_bytes: 3580
def f(G, not_searched, results={0: '0'}):
    stack = []
    while len(not_searched) > 0:
        if len(stack) > 0:
            i = stack.pop()
            not_searched.remove(i)
        else:
            i = not_searched.pop()

        for key, val in G[i].items():
            if not key in not_searched:
                continue

            if val % 2 == 1:
                if results[i] == '0':
                    results[key] = '1'
                else:
                    results[key] = '0'
            else:
                results[key] = results[i]

            stack.append(key)

    return results

N = int(input())
G = [{} for _ in range(N)]
not_searched = set([i for i in range(N)])

if N == 1:
    print(results[0])
else:
    for i in range(N-1):
        u, v, w = map(int, input().split())
        G[u-1][v-1] = w
        G[v-1][u-1] = w

    results = f(G, not_searched)
    for i in range(N):
        print(results[i])

Measured memory_bytes: 60184
-- Try AtCoder
-- author: Leonardone @ NEETSDKASU
 
 
 
main = putStrLn . solve "" =<< getLine
 
solve xs []       = reverse xs
solve [] ('B':ys) = solve [] ys
solve xs ('B':ys) = solve (tail xs) ys
solve xs (y  :ys) = solve (y:xs)    ys
    



Measured memory_bytes: 380
#include <bits/stdc++.h>
using namespace std;
typedef pair<int, int> P;
#define INF 10000000000000
struct edge
{
    long long to, cost;
};
struct graph
{
    int V;                  //頂点数
    vector<vector<edge>> G; //頂点sからの最短距離
    vector<long long> d;
    graph(int n)
    {
        init(n);
    }
    void init(int n)
    {
        V = n;
        G.resize(V);
        d.resize(V);
        for (int i = 0; i < V; i++)
        {
            d[i] = INF;
        }
    }
    void add_edge(int s, int t, long long cost)
    {
        edge e;
        e.to = t;      //行き先
        e.cost = cost; //cost
        G[s].push_back(e);
    }
    void dijkstra(int s)
    {
        for (int i = 0; i < V; i++)
        {
            d[i] = INF;
        }
        d[s] = 0;
        priority_queue<P, vector<P>, greater<P>> que;
        que.push(P(0, s));
        while (!que.empty())
        {
            P p = que.top();
            que.pop();
            long long v = p.second;
            if (d[v] < p.first)
                continue;
            for (auto e : G[v])
            {
                if (d[e.to] > d[v] + e.cost)
                {
                    d[e.to] = d[v] + e.cost;
                    que.push(P(d[e.to], e.to));
                }
            }
        }
    }
};

int main()
{
    int N, M, s, t;
    cin >> N >> M >> s >> t;
    s--, t--;
    graph G1(N);
    graph G2(N);
    for (int i = 0; i < M; i++)
    {
        int x, y;
        cin >> x >> y;
        x--, y--;
        G1.add_edge(x, y, 1);
        G2.add_edge(x, y, 1);
        G1.add_edge(y, x, 1);
        G2.add_edge(y, x, 1);
    }
    G1.dijkstra(s);
    G2.dijkstra(t);
    map<long long, long long> g1, g2;
    for (int i = 0; i < N; i++)
    {
        g1[G1.d[i]]++;
        g2[G2.d[i]]++;
    }
    long long ans = 0;
    int dis = G1.d[t];
    for (int i = 0; i <= dis - 2; i++)
    {
        ans += g1[i] * g2[dis - i - 2];
    }
    cout << ans << endl;
}



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

int main() {
    int k, t;
    cin >> k >> t;
    int a[t];
    rep(i, t) cin >> a[i];

    if (t == 1) {
        cout << a[0] - 1 << endl;
        return 0;
    }

    sort(a, a + t);
    int l = 0, r = t - 1;
    int i = 0, cnt = 0;
    while (!all_of(a, a + t, [](int x) { return x == 0; })) {
        if (i % 2 == 0) {
            if (a[l] == 0) l++;
            a[l]--;
        } else {
            if (a[r] == 0) r++;
            a[r]--;
        }

        if (l == r) cnt++;
        i++;
    }

    if (cnt > 0) cnt--;
    cout << cnt << endl;
    return 0;
}


Measured memory_bytes: 256
import math

def gcd_ext(a, b):
    x, y, lastx, lasty = 0, 1, 1, 0
    while b != 0:
        q = a // b
        a, b = b, a % b
        x, y, lastx, lasty = lastx - q * x, lasty - q * y, x, y
    return (lastx, lasty)

n = int(input())
divisor_list = []
n *= 2
for x in range(2, int(n ** 0.5) + 1):
    if n % x == 0:
        divisor_list.append([x, n // x])
ans = n - 1
for m1, m2 in divisor_list:
    if math.gcd(m1, m2) != 1:
        continue
    p, q = gcd_ext(m1, m2)
    tmp = (-1 * m1 * p) % (m1 * m2)
    ans = min(tmp, ans)
    tmp = (-1 * m2 * q) % (m1 * m2)
    ans = min(tmp, ans)
print(ans)

Measured memory_bytes: 80072
a = input()
b = input()
if len(a) > len(b):
  print("GREATER")
elif len(a) < len(b):
  print("LESS")
else:
  for i in range(len(a)):
    if a[i] > b[i]:
      print("GREATER")
      break
    elif a[i] < b[i]:
      print("LESS")
      break
  else:
    print("EQUAL")

Measured memory_bytes: 9084
#include <stdio.h>
int main()
{
   int a,b,c;
   scanf("%d%d%d",&a,&b,&c);
   if(a==b&&b!=c)
   {
       if(a==5&&c==7)
        printf("YES");
       else
        printf("NO");
   }
    if(a==c&&a!=b)
    {
        if(a==5&&b==7)
            printf("YES");
        else
            printf("NO");
    }
    if(b==c&&b!=a)
    {
        if(b==5&&a==7)
          printf("YES");
        else
          printf("NO");
    }
  return 0;
}


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

using namespace std;

int n , ans , cnt;

int main(){
cin >> n;
for(int i = 1; i <= n; i+=2){
    ans++;
}
for(int j = 2; j <= n; j+=2){
    cnt++;
}
cout << ans * cnt;
return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long int
#define pb push_back
#define pf pop_front
#define mp make_pair
using namespace std;

#define int ll
signed main()
{
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
		
	int n,w;
	cin>>n>>w;
	int a[n];
	//for(int i=0;i<n;i++)
	//	cin>>a[i];
	int dp[n][w+1];
	for(int i=0;i<n;i++)
		for(int j=0;j<=w;j++)
			dp[i][j]=0;
	
	int wt[n],v[n];
	for(int i=0;i<n;i++)
		cin>>wt[i]>>v[i];
	
	
	for(int i=0;i<wt[0];i++)
		dp[0][i]=0;
	for(int i=wt[0];i<=w;i++)
		dp[0][i]=v[0];
	//for(int i=0;i<=w;i++)
	//	cout<<dp[0][i]<<' ';
	//cout<<endl;
	for(int i=1;i<n;i++)
	{
		//cout<<endl;
		for(int j=0;j<=w-wt[i];j++)
		{
			//cout<<i<<'-'<<j<<'-'<<wt[i]<<','<<v[i]+dp[i-1][j]<<endl;
			dp[i][j+wt[i]]=max(dp[i][j+wt[i]],dp[i-1][j]+v[i]);
		}
		for(int j=1;j<=w;j++)
		{
			dp[i][j]=max(dp[i][j],dp[i-1][j]);
			dp[i][j]=max(dp[i][j],dp[i][j-1]);
		}
		
	}
	//for(int i=0;i<n;i++)
//	{	for(int j=0;j<=w;j++)
	//	cout<<dp[i][j]<<' ';
	//cout<<endl;
//}
	cout<<dp[n-1][w]<<endl;
		
}

Measured memory_bytes: 78336
// C - Not so Diverse
#include <bits/stdc++.h>
using namespace std;
using vi = vector<int>;
#define allr(x) (x).rbegin(),(x).rend()
#define rp(i,s,e) for(int i=(s);i<(e);++i)

int main(){
	int N,K; cin>>N>>K;
	vi C(N+1);
	rp(i, 0, N){ int a; cin>>a; C[a]++; }
	sort(allr(C));
	int count = 0;
	rp(i, K, N+1) count += C[i];
	cout<< count <<endl;
}

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

struct Node {
	int h, pre;
	bool vis;
} nodes[233333];

struct Edge {
	int to, nex;
} edges[23333333];

struct Point {
    int x, y;
} a[233333];

int n, cnt, ans;

int read() {
    int ret, f = 1;
    char ch;
    while(!isdigit(ch = getchar())) (ch == '-') && (f = -1);
    for(ret = ch - '0'; isdigit(ch = getchar()); ret *= 10, ret += ch - '0');
    return ret * f;
}

void print(int x) {
    if(x < 0) putchar('-'), x = -x;
    if(x > 9) print(x / 10);
    putchar(x % 10 + '0');
}

void addedge(int u, int v) {
	edges[++cnt].to = v;
	edges[cnt].nex = nodes[u].h;
	nodes[u].h = cnt;
}

bool dfs(int u) {
	if(nodes[u].vis) return 0;
	nodes[u].vis = 1;
	for(int i = nodes[u].h; i; i = edges[i].nex) {
		if(!nodes[edges[i].to].pre || dfs(nodes[edges[i].to].pre)) {
			nodes[edges[i].to].pre = u;
			return 1;
		}
	}
	return 0;
}

int main() {
    n = read();
    for(int i = 1; i <= n; ++i)
        a[i].x = read(), a[i].y = read();
    for(int i = 1; i <= n; ++i)
        a[n + i].x = read(), a[n + i].y = read();
    for(int i = 1; i <= n; ++i)
        for(int j = n + 1; j <= n * 2; ++j)
            if(a[i].x < a[j].x && a[i].y < a[j].y)
                addedge(i, j);
    for(int i = 1; i <= n; ++i) {
        for(int j = 1; j <= n + cnt; ++j)
            nodes[j].vis = 0;
        if(dfs(i)) ++ans;
    }
    print(ans);
    return 0;
}

Measured memory_bytes: 2304
N = STDIN.gets.chomp.to_i
A = STDIN.gets.chomp.to_i
B = STDIN.gets.chomp.to_i
C = STDIN.gets.chomp.to_i
D = STDIN.gets.chomp.to_i
E = STDIN.gets.chomp.to_i

mini = [A, B, C, D, E].min

# 5は都市１から都市６までのステップ
puts (N.to_f / mini.to_f).ceil - 1 + 5


Measured memory_bytes: 1788
// 14/06/19 // 8:03 PM //

#include <iostream>
#include <cmath>

using  namespace std;

#define  MAXN 100010
#define INF 2000000000

int n, k;
int h[MAXN];

int memo[MAXN];

int funcao(){


    for(int i=2; i<=n; i++){

        memo[i] = INF;

        for(int j=i-1; j>=i-k; j--){
            if(j>=1)
                memo[i] = min(memo[i], abs(h[i]-h[j]) + memo[j]);
            else
                break;
        }
    }

    return memo[n];
}

int main(){

    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    cin >> n >> k;

    for(int i=1; i<=n; i++)
        cin >> h[i];

    cout << funcao() << "\n";

    return 0;
}


Measured memory_bytes: 1024
H,W=map(int,input().split())
ch,cw=map(int,input().split())
dh,dw=map(int,input().split())
S=[input() for i in range(H)]
from collections import deque
q=deque([(ch-1,cw-1,0)])
v=[[9**9]*W for i in range(H)]
x=((1,0),(-1,0),(0,-1),(0,1))
y=((2,2),(2,1),(2,0),(2,-1),(2,-2),(1,2),(1,1),(1,-1),(1,-2),(0,2),(0,-2),(-1,2),(-1,1),(-1,-1),(-1,-2),(-2,2),(-2,1),(-2,0),(-2,-1),(-2,-2))
while q:
    h,w,d=q.popleft()
    for i,j in x:
        if 0<=h+i<H and 0<=w+j<W and S[h+i][w+j]=='.' and d<v[h+i][w+j]:
            v[h+i][w+j]=d
            q.appendleft((h+i,w+j,d))
    for i,j in y:
        if 0<=h+i<H and 0<=w+j<W and S[h+i][w+j]=='.' and d+1<v[h+i][w+j]:
            v[h+i][w+j]=d+1
            q.append((h+i,w+j,d+1))
print(v[dh-1][dw-1] if v[dh-1][dw-1]<9**9 else -1)

Measured memory_bytes: 92716
#include<bits/stdc++.h>
#define ll long long
#define double long double
#define rep(i,n) for(ll i=0;i<(n);i++)
#define REP(i,n) for(int i=1;i<=(n);i++)
#define mod (ll)(1e9+7)
#define inf (ll)(3e18+7)
#define pi (double) acos(-1)
#define P pair<int,int>
#define PiP pair<int,pair<int,int>>
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
using namespace std;

int main() {
    ll n;
    cin >> n;
    vector<ll> a(n);
    rep(i, n) cin >> a.at(i);
    ll acu = accumulate(all(a), 0LL), sum = 0, ans = inf;
    for(int i = 0; i < n-1; i++){
        sum += a.at(i);
        ans = min(ans, abs(sum-(acu-sum)));
    }
    cout << ans << endl;
}


Measured memory_bytes: 1792
import java.util.Scanner;

public class Main {
    public static void main(String args[]){
        Scanner scanner= new Scanner(System.in);
        int A,B,C,X,Y;
        A=scanner.nextInt();
        B=scanner.nextInt();
        C=scanner.nextInt();
        X=scanner.nextInt();
        Y=scanner.nextInt();
        int ans=(int)1e9;//1e9=10^9
        for(int i=0;i<2*(X+Y)+1;i++){
            int ABpizza=i;
            int Apizza=Math.max(0,X-ABpizza/2);
            int Bpizza=Math.max(0,Y-ABpizza/2);
            ans=Math.min(ans,Apizza*A+Bpizza*B+ABpizza*C);
        }
        System.out.println(ans);
    }
}


Measured memory_bytes: 23380
import java.util.Scanner;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        char[] s = sc.next().toCharArray();
        boolean Judge = false;
        for (int i = 1; i < s.length; i++) {
            if (s[i-1] == s[i]) {
                Judge = !Judge;
                break;
            }
        }

        if (Judge) {
            System.out.println("Bad");
        }else{
            System.out.println("Good");
        }
    }
}


Measured memory_bytes: 35708
def inpl():
    return input().split()

n = int(input())
a = list(map(int, inpl()))
a = sorted(a, reverse=True)

ans = 1
cnt = 0
bf = a[0]
i = 1
while (i < n) and (cnt < 2):
    a_i = a[i]
    if bf == a_i:
        ans *= a_i
        bf = -1
        cnt += 1
    else:
        bf = a_i
    i += 1
print(ans if cnt == 2 else 0)

Measured memory_bytes: 14252
#include <bits/stdc++.h>
#define rep(i, x, y) for (int i = x; i <= y; i++)
#define per(i, x, y) for (int i = x; i >= y; i--)
using namespace std;

const int mod = 1e9 + 7, N = 2e3 + 10;
typedef long long ll;
int n, K, f[N][N], sum, ans;

int main() {
    cin >> n >> K;
    per(i, n, 2) f[1][i] = 1;
    rep(i, 1, K - 2) {
        sum = f[i][n - i + 1];
        per(j, n - i, 2) {
            sum = (sum + f[i][j]) % mod;
            f[i + 1][j] = (f[i + 1][j] + sum) % mod;
        }
    }
    rep(i, 2, n - (K - 1) + 1) ans = (ans + f[K - 1][i]) % mod;
    if (K == 1) ans = 1;
    if (n - K - 1 > 0)
        rep(i, 1, n - K - 1) ans = (ans << 1) % mod;
        
    printf("%d\n", ans);
    return 0;
}


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

int main(){
  int N,K;
  cin >> N >> K;
  vector<int> p(N);
  for(int i=0;i<N;i++){
    cin >> p.at(i);
  }
  sort(p.begin(),p.end());
  int ans=0;
  for(int i=0;i<K;i++){
    ans+=p.at(i);
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3620
#include<stdio.h>
#include<stdlib.h>
#include<math.h>

int main()
{
int n;
long long int x,y;
x=0;

scanf("%d",&n);

for(int i=1;i<=n;i++)
{
    if(i%3!=0&&i%5!=0)
    {
        x += i;
    }
}

printf("%lld",x);

return 0;
}

Measured memory_bytes: 1732
#include <bits/stdc++.h>
 using namespace std;
 
 int main() {
 int A;
 int B;
 int C;
 int D;
 cin>>A;
 cin>>B;
 cin>>C;
 cin>>D;
  
  if  (A+B>C+D){
  cout<<"Left"<<endl;
  }
  else if (A+B<C+D){
  cout<<"Right"<<endl;
  }
  else{
  cout<<"Balanced"<<endl;
  }
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
using data=pair<int,int>;
#define rep(i,N) for(i=0;i<N;i++)
#define rep1(i,N) for(i=1;i<N;i++)
#define mod 1000000007

long mmid(long a,long b,long c){return a<b?(b<c?b:max(a,c)):(b>c?b:min(a,c));}

ll modinv(ll a) {
  ll b=mod,u=1,v=0,t;
  while(b){
    t=a/b;
    a-=t*b; swap(a,b);
    u-=t*v; swap(u,v);
  }
  return (u+mod)%mod;
}

ll moddevide(ll a,ll b){return (a*modinv(b))%mod;}
 
ll modncr(ll n,ll r){
  ll i,plus=1;
  rep(i,r){
    plus=(plus*(n-i))%mod;
    plus=moddevide(plus,i+1);
  }
  return plus;
}

ll euclidean_gcd(ll a, ll b) {
  if(a<b) return euclidean_gcd(b, a);
  ll r;
  while ((r=a%b)){a=b;b=r;}
  return b;
}

int main(){
  int i,j,k,N,K,cnt,ans=0,rout;
  cin>>N>>K;
  vector<vector<int>> v(N,vector<int>(K,0));
  rep(i,N){
    rep(j,K){
      cin>>v[i][j];
    }
  }
  rep(i,N-1){
    for(j=i+1;j<N;j++){
      cnt=0;
      rep(k,K){
        cnt+=(v[i][k]-v[j][k])*(v[i][k]-v[j][k]);
      }
      rout=sqrt(cnt);
      if(rout*rout==cnt)ans++;
    }
  }
  cout <<ans<<endl;
  return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<string>
using namespace std;
int main()
{
    int n,m;
    while(cin>>n>>m)
    {
        if(n%3==0||m%3==0)
        {
             cout<<"Possible"<<endl;break;
        }

       else if((n+m)%3==0)
           {
               cout<<"Possible"<<endl;break;
           }
       else
           {
               cout<<"Impossible"<<endl;break;
           }
    }
}


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

int main(){
        int i,cnt_0=0,cnt_1=0;
        string s;
        cin >> s;
        for(i=0;i<s.length();++i){
                if(s[i]=='0') ++cnt_0;
                else ++cnt_1;
        }
        cout << 2*min(cnt_0,cnt_1) << endl;
        return 0;
}

Measured memory_bytes: 3768
//"BISMILLAHIR RAHMANIR RAHIM"
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define pb push_back
const long long M = 1e9+7 ;
ll fact(ll x, ll y){
    ll f=1,i=1;
    while(i<=y){
        f=( (f%M) * (x%M) )%M;
        i++;
    }
    return f;
}
int main()
{
    string s;
    ll a;

    cin>>s;
     a= s.length();
    if(s[a-1]=='s')
        s= s+'e'+'s';
    else
        s=s+'s';
    cout<<s<<endl;
    return 0;
}




Measured memory_bytes: 3628
a,b,c,d=map(int,input().split())

def gcd(a,b):
    if a==0:
        return b
    else:
        return gcd(b%a,a)

cdlcm=c*d//gcd(c,d)

cd=b//c-(a-1)//c
dd=b//d-(a-1)//d
cdd=b//(cdlcm)-(a-1)//(cdlcm)

print(b-a+1-(cd+dd-cdd))

Measured memory_bytes: 3064
#include <iostream>
using namespace std;
const int maxn = 2e5 + 10;
int ans[maxn];
int main()
{
	int n;
	cin >> n;
	for (int i = 1; i < n; i++)
	{
		int a;
		cin >> a;
		ans[a]++;
	}
	for (int i = 1; i <= n; i++)
	{
		cout << ans[i] << endl;
	}
	return 0;
}

Measured memory_bytes: 4348
#include <bits/stdc++.h>
#define rep(i, a, n) for(int i = a; i < n; i++)
#define int long long
using namespace std;
typedef pair<int, int> P;
const int mod = 1000000007;
const int INF = 1e18;

signed main(){
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	int a, b;
	cin >> a >> b;
	if(a < 10 && b < 10) cout << a * b << endl;
	else cout << -1 << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
using namespace std;
 
int main() {
    // 入力
    int N, C; cin >> N >> C;
    vector<vector<int> > D(C, vector<int>(C, 0));
    for (int i = 0; i < C; ++i) for (int j = 0; j < C; ++j) cin >> D[i][j];
    vector<vector<int> > fi(N, vector<int>(N, 0));
    for (int i = 0; i < N; ++i) for (int j = 0; j < N; ++j) cin >> fi[i][j], --fi[i][j];
    
    // 前処理
    vector<vector<int> > cost(3, vector<int>(C, 0));
    for (int c = 0; c < C; ++c) {
        for (int i = 0; i < N; ++i) {
            for (int j = 0; j < N; ++j) {
                cost[(i+j)%3][c] += D[fi[i][j]][c];
            }
        }
    }
    
    // 求める
    int res = 1<<30;
    int c[3];
    for (c[0] = 0; c[0] < C; ++c[0]) {
        for (c[1] = 0; c[1] < C; ++c[1]) {
            if (c[1] == c[0]) continue;
            for (c[2] = 0; c[2] < C; ++c[2]) {
                if (c[2] == c[0] || c[2] == c[1]) continue;
                int tmp = 0;
                for (int it = 0; it < 3; ++it) tmp += cost[it][c[it]];
                res = min(res, tmp);
            }
        }
    }
    cout << res << endl;
}

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

int main() {
    ll N, M; cin >> N >> M;
    vector<ll> dp(N + 2);
    dp.assign(N + 1, 0);
    vector<ll> m(M + 1); for (int i = 0; i < M; ++i) cin >> m[i];
    int idx = 0;

    dp[0] = 1;
    dp[1] = 1;
    if (m[idx] == 1) {
        dp[1] = 0;
        idx++;
    }

    for (int i = 2; i < N + 1; ++i) {
        if (m[idx] == i) {
            idx++;
            dp[i] = 0;
            continue;
        }
        dp[i] = dp[i - 1] + dp[i - 2];
        dp[i] %= MOD;
    }
    cout << dp[N] << endl;
}

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

const int A[33] = { -1, 1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51 };

int main(void) {
	int K;
	cin >> K;

	cout << A[K] << '\n';
	return 0;
}


Measured memory_bytes: 256
import os
import sys
from atexit import register
from io import BytesIO
sys.stdin = BytesIO(os.read(0, os.fstat(0).st_size))
sys.stdout = BytesIO()
register(lambda: os.write(1, sys.stdout.getvalue()))
input = lambda: sys.stdin.readline().rstrip('\r\n')
raw_input = lambda: sys.stdin.readline().rstrip('\r\n')

n = int(input())
seq = [int(x) for x in input().split()]
a = 0
ans = [0 for _ in range(n)]
for i in range(2*n-2):
    a = a ^ seq[i % n]
    # print(i,a ,i>=n-2)
    if i >= n-2:
        ans[(i+1)%n] = str(a)
        a = a ^ seq[(i-(n-2)) % n]
# ans.append(str(a))
print(' '.join(ans))

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


int main() {
	
	string s;
	cin >> s;
	for(int i='a'; i<='z'; i++){
		bool flag = 0;
		for(auto j : s){
			if(j==i) {
				flag = 1;
				continue;
			}
		}
		if (!flag) {
			cout << (char)i << endl;
			break;
		}
		if (i=='z') cout << "None" << endl; 
	}
	
	return 0;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
#define rep(X,N) for(ll X = 0; X < (N); X++)
#define PI (acos(-1.0))
#define pback push_back
#define mpair make_pair
#define MODN 1000000007
#define ALL(V) (V).begin(),(V).end()

typedef long long ll;

using namespace std;

/*
  隣り合うxyの各座標の差を取って各線分の長さを取る
  各線分がカウントされる回数は各線分の左右や上下の
  左、右の他の線分の数の積のはず
*/

class ModInt{
public:
    long long n;
    int p;

    ModInt(){
    }

    //値と割る値を受け取って、オブジェクトを返す
    ModInt(long long _n, int _p){
        p = _p;
        n = _n % _p;

        //負の値を受け取ったときには正の値に戻す
        if(n < 0){
            n += p;
        }
    }

    ModInt operator+(ModInt a){

        ModInt tmp = ModInt(*this);

        tmp.n += a.n;

        if(tmp.n > tmp.p){
            tmp.n -= tmp.p;
        }
        
        return tmp;
    }

    ModInt operator-(ModInt a){

        ModInt tmp = ModInt(*this);

        tmp.n -= a.n;

        if(tmp.n < 0){
            tmp.n += tmp.p;
        }

        return tmp;
    }

    ModInt operator*(ModInt a){

        ModInt tmp = ModInt(*this);

        tmp.n = (tmp.n * a.n) % tmp.p;

        return tmp;
    }

    int modpow(int b, int k){
        if(k == 0){
            return 1;
        }else if(k % 2 == 1){
            long long tmp = b;
            tmp = tmp * modpow(b, k - 1) % p;
            
            return tmp;
        }else{
            long long tmp = modpow(b, k / 2);
            return tmp * tmp % p;
        }
    }

    int modinv(int b){
        return modpow(b, p - 2);
    }

    ModInt operator/(ModInt a){

        ModInt tmp = ModInt(*this);

        tmp.n = tmp.n * modinv(a.n) % tmp.p;
        return tmp;
    }
};

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

    vector<ModInt> x;
    vector<ModInt> y;

    ll tmp1,tmp2;

    cin >> tmp1;

    rep(i,n - 1){
        cin >> tmp2;
        x.pback(ModInt(tmp2 - tmp1, MODN));

        tmp1 = tmp2;
    }

    cin >> tmp1;

    rep(i,m - 1){
        cin >> tmp2;
        y.pback(ModInt(tmp2 - tmp1, MODN));

        tmp1 = tmp2;
    }

    vector<ModInt> xcount;
    vector<ModInt> ycount;

    rep(i, n - 1){
        xcount.pback(ModInt((i + 1) * (n - 1 - i), MODN));
    }

    rep(i, m - 1){
        ycount.pback(ModInt((i + 1) * (m - 1 - i), MODN));
    }

    assert(x.size() == n - 1);
    assert(y.size() == m - 1);
    assert(xcount.size() == n - 1);
    assert(ycount.size() == m - 1);

    ModInt xsum(0, MODN);
    ModInt ysum(0, MODN);

    rep(i, n - 1){
        xsum = xsum + x[i] * xcount[i];
    }

    rep(i, m - 1){
        ysum = ysum + y[i] * ycount[i];
    }

    cout << (xsum * ysum).n << endl;

    return 0;
}

Measured memory_bytes: 8048
#include <bits/stdc++.h>
#include <iomanip>
using namespace std;
#define ll long long int
#define vi vector<int>
#define vii vector<int,int>
#define pii pair<int,int>
#define mp make_pair
#define pb push_back
#define ff first
#define ss second
#define all(a) a.begin(),a.end()
const int mod=1e9+7;
#define fast ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
double pi=acos(-1);
int main(){
    fast;
    int k;
    cin>>k;
    int a,b;
    cin>>a>>b;
    bool m=0;
    for(int i=a;i<=b;i++){
        if(i%k==0){
            cout<<"OK";
            m=1;
            break;
        }
    }
    if(!m) cout<<"NG";
}

Measured memory_bytes: 3640
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <sstream>
#include <cstring>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <numeric>
#include <cctype>
#include <tuple>
#include <array>
#include <cassert>

// BEGIN CUT HERE
#ifdef _MSC_VER
#include <agents.h>
#endif
// END CUT HERE 

#define FOR(i, a, b) for(int i = (int)(a); i < (int)(b); ++i)
#define rep(i, n) FOR(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define REV(v) v.rbegin(), v.rend()
#define MEMSET(v, s) memset(v, s, sizeof(v))
#define MP make_pair
#define MT make_tuple

using namespace std;

typedef long long ll;
typedef pair<int, int> P;
typedef unsigned long long ull;

struct dat{
	string value;
	map<string, dat> p;
};

string buf[100000];

int i;
dat mapping(){
	string s;
	dat res;
	int prv = -1;
	while (!buf[i].empty()){
		string &s = buf[i];
		int l = 0;
		while (s[l] == ' ') ++l;
		if (prv < 0) prv = l;
		if (prv != l) break;
		i++;
		int idx = s.find(':');
		string t = s.substr(idx);
		dat d;
		if (t.size() > 2) d.value = t.substr(2);
		else d = mapping();

		res.p[s.substr(l, idx-l)] = d;
	}
	return res;
}

int main(){
	string query;
	cin >> query;
	cin.ignore();
	int len = 0;
	while (getline(cin, buf[len++]));

	dat d = mapping();

	for (auto &c : query) if (c == '.') c = ' ';

	stringstream ss(query);
	string s;
	dat *p = &d;
	while (ss >> s){
		if (!p->p.count(s)) goto NG;
		p = &(p->p[s]);
	}

	if (p->value.empty()) cout << "object" << endl;
	else cout << "string \"" << p->value << "\"" << endl;

	return 0;
NG:
	cout << "no such property" << endl;

	return 0;
}

Measured memory_bytes: 2276
/*

  "With age, comes wisdom. With travel, comes understanding.
   Remember that happiness is a way of travel – not a destination"

*/

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;

#define int            long long int
#define ld             long double
#define F              first
#define S              second
#define pb             push_back
#define si             set <int>
#define vi             vector <int>
#define pii            pair <int, int>
#define vpi            vector <pii>
#define vpp            vector <pair<int, pii>>
#define mii            map <int, int>
#define mpi            map <pii, int>
#define spi            set <pii>
#define endl           "\n"
#define sz(x)          ((int) x.size())
#define all(p)         p.begin(), p.end()
#define que_max        priority_queue <int>
#define que_min        priority_queue <int, vi, greater<int>>
#define bug(...)       __f (#__VA_ARGS__, __VA_ARGS__)
#define print(a)       for(auto x : a) cout << x << " "; cout << endl
#define print1(a)      for(auto x : a) cout << x.F << " " << x.S << endl
#define print2(a,x,y)  for(int i = x; i < y; i++) cout<< a[i]<< " "; cout << endl

inline int power(int a, int b)
{
	int x = 1;
	while (b)
	{
		if (b & 1) x *= a;
		a *= a;
		b >>= 1;
	}
	return x;
}

typedef tree<pii, null_type, less<pii>, rb_tree_tag, tree_order_statistics_node_update> Set;

template <typename Arg1>
void __f (const char* name, Arg1&& arg1) { cout << name << " : " << arg1 << endl; }
template <typename Arg1, typename... Args>
void __f (const char* names, Arg1&& arg1, Args&&... args)
{
	const char* comma = strchr (names + 1, ',');
	cout.write (names, comma - names) << " : " << arg1 << " | "; __f (comma + 1, args...);
}

const int N = 2000005;
int r1, c1, r2, c2;

const int mod = 1000000007;
int fact[N], invfact[N];
inline int add(int x, int y) { x += y; return x % mod;}
inline int sub(int x, int y) { x -= y; x %= mod; x += mod; return x % mod;}
inline int mul(int x, int y) { return  (x * y) % mod;}
inline int powr(int a, int b) {
	int x = 1 % mod;
	b %= (mod - 1);
	while (b) {
		if (b & 1) x = mul(x, a);
		a = mul(a, a);
		b >>= 1;
	}
	return x;
}
inline int inv(int a) { return powr(a, mod - 2);}
void pre() {
	fact[0] = invfact[0] = 1;
	for (int i = 1; i < N; i++) fact[i] = mul(i, fact[i - 1]);
	invfact[N - 1] = inv(fact[N - 1]);
	for (int i = N - 2; i >= 1; i--) invfact[i] = mul(invfact[i + 1], i + 1);
	assert(invfact[1] == 1);
}
inline int C(int n, int k) {
	if (n < k || k < 0) return 0;
	return mul(fact[n], mul(invfact[k], invfact[n - k]));
}

void solve()
{
	pre();
	cin >> r1 >> c1 >> r2 >> c2;
	int ans = 0;

	for (int i = r1; i <= r2; i++)
	{
		int x = sub(C(i + c2 + 1, c2) , C(i + c1, c1 - 1));
		ans = add(ans, x);
	}
	cout << ans;
}

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

	cout << setprecision(9) << fixed;
	clock_t z = clock();
	solve();
	cerr << "Run Time : " << ((double)(clock() - z) / CLOCKS_PER_SEC);

	return 0;
}

Measured memory_bytes: 31616
#define _CRT_SECURE_NO_WARNINGS

#include <stdio.h>
#include <stdlib.h>
#include <algorithm>

int main() {

	int c[10][10];
	int H, W;

	scanf("%d %d", &H, &W);
	for (int i = 0; i < 10; i++) {
		for (int j = 0; j < 10; j++) {
			scanf("%d", &c[i][j]);
		}
	}

	for (int k = 0; k < 10; k++) {
		for (int i = 0; i < 10; i++) {
			for (int j = 0; j < 10; j++) {
				c[i][j] = std::min(c[i][j], c[i][k] + c[k][j]);
			}
		}
	}

	int ans = 0;

	for (int h = 0; h < H; h++) {
		for (int w = 0; w < W; w++) {
			int a;
			scanf("%d", &a);
			if (a >= 0) ans += c[a][1];
		}
	}

	printf("%d\n", ans);

	return 0;
}

Measured memory_bytes: 128
#include <cstdio>
#include <vector>
#include <algorithm>
#include <string>

using namespace std;

template <class T, class Comp=less<T>>
struct BinarySearchTree {
    struct Node {
        T value;
        Node *parent, *left, *right;
        Node(T v=T()): value(v), parent(NULL), left(NULL), right(NULL) {}
    };
    Node *root;
    Comp comp;
    BinarySearchTree(): root(NULL) {}
    void insert(T key) {
        Node *z=new Node(key);
        Node *x=root;
        while (x != NULL) {
            z->parent = x;
            x = (comp(z->value, x->value)? x->left : x->right);
        }

        if (z->parent == NULL) {
            root = z;
        } else if (comp(z->value, z->parent->value)) {
            z->parent->left = z;
        } else {
            z->parent->right = z;
        }
    }
    template <class Functor>
    void walk_inorder(Functor F, Node *x) {
        if (x == NULL) return;

        walk_inorder(F, x->left);
        F(x);
        walk_inorder(F, x->right);
    }
    template <class Functor>
    void walk_preorder(Functor F, Node *x) {
        if (x == NULL) return;

        F(x);
        walk_preorder(F, x->left);
        walk_preorder(F, x->right);
    }
    template <class Functor>
    void walk_postorder(Functor F, Node *x) {
        if (x == NULL) return;

        walk_postorder(F, x->left);
        walk_postorder(F, x->right);
        F(x);
    }
    ~BinarySearchTree() {
        auto del=[](Node *x) {
            delete x;
        };
        walk_postorder(del, root);
    }
};

int main() {
    size_t m;
    scanf("%zu", &m);

    auto output=[](BinarySearchTree<int>::Node *x)->int {
        return printf(" %d", x->value);
    };

    BinarySearchTree<int> tree;
    for (size_t i=0; i<m; ++i) {
        char buf[1<<3];
        scanf("%s", buf);
        string instr(buf);

        if (instr == "insert") {
            int key;
            scanf("%d", &key);
            tree.insert(key);
        } else if (instr == "print") {
            tree.walk_inorder(output, tree.root);
            printf("\n");
            tree.walk_preorder(output, tree.root);
            printf("\n");
        }
    }

    return 0;
}

Measured memory_bytes: 26200
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <assert.h>
#define REP(i,n) for(int i=0;i<n;i++)
using namespace std;

void vector_dump(std::vector<vector<bool> > vec) {
    std::cout << "[ ";
    for (auto j:vec) {
        std::cout << "[ ";
        for (auto i:j) {
            std::cout << (int)i << " ";
        }
        std::cout << "] ";
    }
    std::cout << "]" << std::endl;
}

void vector_dump(std::vector<int> vec) {
    std::cout << "[ ";
    for (int i:vec) {
        std::cout << i << " ";
    }
    std::cout << "]" << std::endl;
}

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

    string s;
	int x, y; 
	cin >> s >> x >> y;
    vector<vector<bool> > dpx(s.length(), vector<bool>(s.length(), false));
    vector<vector<bool> > dpy(s.length(), vector<bool>(s.length(), false));
    
    int X = 0, Y = 0;
    int cnt = 0;
    
    
    
    for (auto c:s) {
        if (c == 'T') cnt++;
    } 
    if (cnt % 2 == 0) {
        X = cnt / 2 + 1;
        Y = cnt / 2;
    } else {
        X = Y = cnt / 2 + 1; 
    }
    vector<int> xi(X);
    vector<int> yi(Y);

    cnt = 0;
    
    for (auto c:s) {
        if (c == 'T') {
            cnt++;
        } else {
            cnt % 2 == 0 ? xi[cnt / 2] += 1 : yi[cnt / 2] += 1;
        }
    }

    dpx[0][xi[0]] = true;
    for (int i = 0; i < X-1; i++) {
        for (int e = 0; e < dpx[i].size(); e++) {
            if (dpx[i][e]) {
                if (xi[0] < e - xi[i+1]) dpx[i+1][e-xi[i+1]] = true;
                dpx[i+1][e+xi[i+1]] = true;
            }
        }
    }
    
    dpy[0][0] = true;
    for (int i = 0; i < Y; i++) {

        for (int e = 0; e < dpy[i].size(); e++) {

            if (dpy[i][e]) { 

                if (0 <= e - yi[i]) dpy[i+1][e-yi[i]] = true;
                dpy[i+1][e+yi[i]] = true;
                
                
            }
        }
    }
    

    if (xi[0] > x) x = xi[0] + (xi[0] - x);
    if (0 > y) y = -y;
    if (dpx[X-1][x] && dpy[Y][y]) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
    
    
    return 0;
}

Measured memory_bytes: 16640
#include <iostream>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <ctime>
using namespace std;

#define rep(i,a,n) for(int i=a; i<n; i++)
#define repr(i,a,n) for(int i=a; i>=n; i--)
#define pb(a) push_back(a)
#define fr first
#define sc second
#define INF 999999999

#define X real()
#define Y imag()
#define EPS (1e-10)
#define EQ(a,b) (abs((a) - (b)) < EPS)
#define EQV(a,b) ( EQ((a).X, (b).X) && EQ((a).Y, (b).Y) )
#define LE(n, m) ((n) < (m) + EPS)
#define GE(n, m) ((n) + EPS > (m))

typedef vector<int> VI;
typedef vector<VI> MAT;
typedef pair<int, int> pii;
typedef long long int ll;

typedef complex<double> P;
typedef pair<P, P> L;
typedef pair<P, double> C;

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

namespace std {
    bool operator<(const P a, const P b) {
        return a.X != b.X ? a.X < b.X : a.Y < b.Y;
    }
}

vector<string> split(string s, char c) {
    vector<string> ret;
    string temp;
    int i;
    replace(s.begin(), s.end(), c, ' ');
    replace(s.begin(), s.end(), '.', ' ');
    stringstream ss(s);
    while(ss >> temp) ret.pb(temp);
    return ret;
}

int main() {
    string s;
    getline(cin, s);
    vector<string> v = split(s, ',');

    bool first = true;
    rep(i,0,v.size()) {
        if(3 <= v[i].length() && v[i].length() <= 6) {
            if(first) {cout << v[i]; first = false;}
            else cout << " " <<  v[i];
        }
    }
    cout << endl;
    return 0;
}

Measured memory_bytes: 1200
#include<cstdio>
#include<cmath>

int main(){
	int n;
	double x[4], y[4];
	int xi[4], yi[4];
	scanf("%d", &n);
	for(int i = 0; i < n; i++){
		scanf("%lf %lf %lf %lf %lf %lf %lf %lf", &x[0],&y[0],&x[1],&y[1],&x[2],&y[2],&x[3],&y[3]);

		for(int i = 0; i < 4; i++){
			xi[i] = (int)(x[i] * 1000000);
			yi[i] = (int)(y[i] * 1000000);
		}
		
		if((yi[0] - yi[1])*(xi[2] - xi[3]) == (xi[0] - xi[1])*(yi[2] - yi[3])){
			printf("YES\n");
		}else{
			printf("NO\n");
		}
	}
	return 0;
}

Measured memory_bytes: 1048
import java.util.*;

public class Main{
      public static void main(String[] args) {
            Scanner sc = new Scanner(System.in);
            int HP = sc.nextInt();
            int N = sc.nextInt();
            for(int i = 0; i < N; i++){
              int n = sc.nextInt();
              HP -= n;
            }
            if(HP <= 0){
              System.out.println("Yes");
            } else {
              System.out.println("No");
            }
      }
}

Measured memory_bytes: 48548
#!/usr/bin/env python3
import collections
import itertools as it
import math
#import numpy as np
 
#  = input()
n = int(input())
#  = map(int, input().split())
a  = list(map(int, input().split()))
#  = [int(input()) for i in range(N)]
#
# c = collections.Counter()

if n == 1:
    print(1)
else:
    ans = 1
    state = lambda n1, n2: 0 if n1 == n2 else (1 if n2 > n1 else -1)
    diff = [state(a1, a2) for a1, a2 in zip(a[:-1], a[1:]) if state(a1, a2) != 0]

    p = 1
    while p < len(diff):
        if abs(diff[p] - diff[p-1]) == 2:
            ans += 1
            p += 1

        p += 1

    print(ans)


Measured memory_bytes: 14636
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<map>
#include<cstddef>
#include<queue>
#include<math.h>
#include<iomanip>
using namespace std;

int main()
{
    int a, b, c;
    cin >> a >> b >> c;
    string ans = "No";
    if(a == b && b != c) ans = "Yes";
    else if(b == c && c != a) ans = "Yes";
    else if(c == a && a != b) ans = "Yes";
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3600
#include <iostream>
#include <string>
#include <cstring>
#include <algorithm>
#include <vector>
#include <map>

using namespace std;

int main() {
  int a;
  string s;
  while (cin >> a >> s) {
    if (a >= 3200) {
      cout << s << endl;
    } else {
      cout << "red" << endl;
    }
  }
}


Measured memory_bytes: 256
#include <stdio.h>

/*  選択ソート(0オリジン) */
int selectionSort(int A[], int N) {
    int i, j, t, sw =0, minj;
    for(i=0;i<N-1;i++) {
        minj = i;
        for(j=i;j<N;j++) {
            if(A[j]<A[minj]) minj = j;
        }
        t=A[i]; A[i]=A[minj]; A[minj]=t;
        if(i!=minj) sw++;
    }
    return sw;
}

int main(void) {
    int A[100], N, i, sw;

    scanf("%d",&N);
    for(i=0;i<N;i++) scanf("%d",&A[i]);

    sw = selectionSort(A,N);

    for(i=0;i<N;i++) {
        if(i>0) printf(" ");
        printf("%d",A[i]);
    }
    printf("\n");
    printf("%d\n",sw);

    return 0;
}


Measured memory_bytes: 2104
import math
import math
a, b, h, m = map(int, input().split())

x = 360*(h/12)+30*(m/60)
y = 360*(m/60)

d = math.cos(math.radians(abs(x-y)))
z = a**2 + b**2 -2*a*b*d
print (math.sqrt(z))

Measured memory_bytes: 9572
N = int(input())
p = [int(i) for i in input().split()]
Nres=0
for i in range(1,N-1):
    if p[i-1]<p[i] and p[i+1]>=p[i]:
        Nres+=1
    elif p[i+1]<p[i] and p[i-1]>=p[i]:
        Nres+=1

print(Nres)


Measured memory_bytes: 3060