akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <string>
using namespace std;

int main()
{
	//A, C, G, T
	string str;
	int ans = 0;
	int len = 0;
	cin >> str;
	for (int i = 0; i < str.length(); i++) {
		if (str[i] == 'A' ||
			str[i] == 'C' ||
			str[i] == 'G' ||
			str[i] == 'T' 
			) {
			len++;
		}
		else {
			if (ans <= len) {
				ans = len;
				len = 0;
			}
		}
	}
	if (len >= ans) {
		std::cout << len << endl;
	}
	else {
		std::cout << ans << endl;
	}
	return 0;
}



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

#define ll long long
#define vi vector<int>
#define vl vector<ll>
#define pii pair<int,int>
#define pll pair<ll,ll>
// pll pp; -> (pp.first,pp.second)
// vector<vl> pp(n,vl(2)); sort(pp.begin(),pp.end(),[](vl a,vl b){return a[0]<b[0];});

#define REP(i,n) for(ll (i)=0;(i)<(n);(i)++)
#define RREP(i,n) for(ll (i)=(n)-1;(i)>=0;(i)--)
#define FOR(i,a,b) for(ll (i)=(a);(i)<(b);(i)++)
#define FORR(i,a,b) for(ll (i)=(b)-1;(i)>=(a);(i)--)
#define DEBUG(x) cout << #x << ": " << x << endl
#define CHMAX(a,b) a=max((a),(b))
#define CHMIN(a,b) a=min((a),(b))
/*}}}*/
int main() {
  ll N,c;
  vl p,q;
  cin >> N;
  REP(i,N){
		int x;
		cin >> x;
		p.push_back(x);
    q.push_back(x);
	}
  sort(q.begin(),q.end());
  c=0;
  REP(i,N){
    if(p[i] != q[i]){
      c = c+1;
    }
  }
  if(c<=2){
    cout << "YES" << endl;
  }else{
    cout << "NO" << endl;
  }
  return 0;
}

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

typedef long long ll;
typedef long double ld;
typedef vector<vector<int>> Graph;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
#define pi 3.14159265359
#define inf 2147483647
#define INF 9223372036854775807
#define mod 1000000007
#define mod2 998244353

int main() {
    string s; cin >> s;
    cout << s[0] << s.size() - 2 << s.back() << endl;
    return 0;
}

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

using ll=long long; 

void solve(){
	vector<ll> a(100);
	int n;
	cin>>n;
	a[0]=2;
	a[1]=1;
	for(int i=2; i<100; i++){
		a[i]=a[i-1]+a[i-2];
	}
	cout<<a[n]<<endl;
}

signed main(){
	//while(1)
	solve();
}


Measured memory_bytes: 256
import sys
sys.setrecursionlimit(4100000)

from itertools import permutations


def resolve():
    N_vertex, M_edge = [int(x) for x in sys.stdin.readline().split()]
    edge_set = set([
        tuple(int(x) for x in sys.stdin.readline().split())
        for _ in range(M_edge)
    ])
    # print(edge_set)

    count = 0
    for p in permutations(range(1, N_vertex + 1)):
        # print(p)
        if p[0] != 1:
            continue
        is_broken = False
        for i in range(N_vertex - 1):
            if (p[i], p[i + 1]) in edge_set or (p[i + 1], p[i]) in edge_set:
                pass
            else:
                is_broken = True
                break
        if not is_broken:
            count += 1

    print(count)


if __name__ == "__main__":
    resolve()

# AtCoder Unit Test で自動生成できる, 最後のunittest.main は消す
# python -m unittest template/template.py で実行できる
# pypy3 -m unittest template/template.py で実行できる

import sys
from io import StringIO
import unittest


class TestClass(unittest.TestCase):
    def assertIO(self, input, output):
        stdout, stdin = sys.stdout, sys.stdin
        sys.stdout, sys.stdin = StringIO(), StringIO(input)
        resolve()
        sys.stdout.seek(0)
        out = sys.stdout.read()[:-1]
        sys.stdout, sys.stdin = stdout, stdin
        self.assertEqual(out, output)

    def test_入力例_1(self):
        input = """3 3
1 2
1 3
2 3"""
        output = """2"""
        self.assertIO(input, output)

    def test_入力例_2(self):
        input = """7 7
1 3
2 7
3 4
4 5
4 6
5 6
6 7"""
        output = """1"""
        self.assertIO(input, output)


Measured memory_bytes: 5676
#!/usr/bin/env python3
N, K = map(int, input().split())
a = list(map(int, input().split()))

sa = [0]
sb = [0]
for i in range(N):
    sa.append(sa[-1] + a[i])
    sb.append(sb[-1] + max(0, a[i]))

ans = 0
if any((x > 0 for x in a)):
    for i in range(N - K + 1):
        a = sa[i + K] - sa[i]
        b = sb[i + K] - sb[i]
        ans = max(ans, sb[N] - b + max(a, 0))

print(ans)


Measured memory_bytes: 17660
#include<iostream>
#include<cstring>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<set>
#include<bitset>
#include<map>

#define fo(i,a,b) for(int i=a;i<=b;i++)
#define fd(i,a,b) for(int i=a;i>=b;i--)

using namespace std;

typedef long long LL;
typedef double db;

int get(){
	char ch;
	while(ch=getchar(),(ch<'0'||ch>'9')&&ch!='-');
	if (ch=='-'){
		int s=0;
		while(ch=getchar(),ch>='0'&&ch<='9')s=s*10+ch-'0';
		return -s;
	}
	int s=ch-'0';
	while(ch=getchar(),ch>='0'&&ch<='9')s=s*10+ch-'0';
	return s;
}

const int N = 100010;

int nxt[N];
int fa[N];
int n,m;
struct edge{
	int x,nxt;
}e[N*4];
int h[N],tot;
int s[N];
int label[N];
bool bz[N];

int getfather(int x){
	if (fa[x]==x)return x;
	return fa[x]=getfather(fa[x]);
}

void inse(int x,int y){
	e[++tot].x=y;
	e[tot].nxt=h[x];
	h[x]=tot;
}

bool dfs(int x,int lab){
	bool pd=1;
	s[x]=1;
	if (label[x]&&lab!=label[x])pd=0;
	else label[x]=lab;
	for(int p=h[x];p;p=e[p].nxt)
	if (!s[e[p].x]){
		pd&=dfs(e[p].x,lab%2+1);
		s[x]+=s[e[p].x];
	}
	else pd&=(label[e[p].x]!=lab);
	return pd;
}

int main(){
	n=get();m=get();
	fo(i,1,n)fa[i]=i;
	fo(i,1,m){
		int x=get(),y=get();
		inse(x,y);inse(y,x);
		x=getfather(x),y=getfather(y);
		if (x<y)fa[y]=x;else fa[x]=y;
	}
	LL ans=0;
	int cnt=0,cnt_single=0,cnt_bit=0;
	fo(i,1,n)
	if (getfather(i)==i){
		bz[i]=dfs(i,1);
		cnt++;
		if (s[i]==1)cnt_single++;
		else if (bz[i])cnt_bit++;
	}
	fo(i,1,n)
	if (fa[i]==i){
		if (s[i]==1)ans=ans+n;
		else{
			if (!bz[i])ans=ans+1ll*cnt_single*s[i]+cnt-cnt_single;
			else ans=ans+1ll*cnt_single*s[i]+cnt-cnt_single+cnt_bit;
		}
	}
	printf("%lld\n",ans);
	return 0;
}

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

int main(void){
    int n;
    cin >> n;
    vector<int> a(n+1);
    ll sum = 0;
    for(int i=1;i<=n;i++){cin >> a[i]; sum += a[i];}

    ll x1 = sum;
    for(int j=2;j<n;j+=2) x1 -= 2*a[j];
    cout << x1 << " ";

    vector<ll> x(n+1);
    x[1] = x1;
    for(int i=2;i<=n;i++){
        x[i] = 2*a[i-1] - x[i-1];
        if(i!=n) cout << x[i] << " ";
        else cout << x[i] << endl;
    }
}

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

signed main()
{
  int list[12] = {1, 2, 1, 3, 1, 3, 1, 1, 3, 1, 3, 1};
  int x, y;

  cin >> x >> y;
  if (list[x - 1] == list[y - 1]) {
    cout << "Yes" << endl;
  }
  else {
    cout << "No" << endl;
  }

  return (0);
}

Measured memory_bytes: 256
n=int(input())
if n<112:
    print(111)
elif n<223:
    print(222)
elif n<334:
    print(333)
elif n<445:
    print(444)
elif n<556:
    print(555)
elif n<667:
    print(666)
elif n<778:
    print(777)
elif n<889:
    print(888)
else:
    print(999)


Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> P;
typedef pair<int,int> Pi;
#define rep(i,n) for(ll i=0;i<n;i++)
#define FOR(i,a,b) for(ll i=a;i<b;i++)
#define fi first
#define se second
#define endl "\n"

template<typename T> inline bool chmax(T &a, T b){if(a<b){a=b;return true;}return false;}
template<typename T> inline bool chmin(T &a, T b){if(a>b){a=b;return true;}return false;}
template<typename T> ostream& operator<<(ostream& s,const complex<T>& d) {return s<<"("<<d.real()<<", "<<d.imag()<< ")";}
template<typename T1, typename T2> ostream& operator<<(ostream& s,const pair<T1,T2>& d) {return s<<"("<<d.first<<", "<<d.second<<")";}
template<typename T> ostream& operator<<(ostream& s, const vector<T>& d){int len=d.size();rep(i,len){s<<d[i];if(i<len-1) s<<" ";}return s;}
template<typename T> ostream& operator<<(ostream& s,const vector<vector<T>>& d){int len=d.size();rep(i,len){s<<d[i]<<endl;}return s;}
template<typename T> ostream& operator<<(ostream& s,const set<T>& v){s<<"{ ";for(auto itr=v.begin();itr!=v.end();++itr) {if (itr!=v.begin()) {s<< ", ";}s<<(*itr);}s<<" }";return s;}
template<typename T> ostream& operator<<(ostream& s,const multiset<T>& v){s<<"{ ";for(auto itr=v.begin();itr!=v.end();++itr) {if (itr!=v.begin()) {s<< ", ";}s<<(*itr);}s<<" }";return s;}
template<typename T1, typename T2> ostream& operator<<(ostream& s,const map<T1,T2>& m){s<<"{"<<endl;for(auto itr=m.begin();itr!=m.end();++itr){s<<" "<<(*itr).first<<" : "<<(*itr).second<<endl;}s<<"}"<<endl;return s;}

const ll mod=1e9+7;
const ll inf=1e17;
const int INF=1e9;
const double EPS=1e-10;
const double PI=acos(-1);

int main(){
    cin.tie(0);ios::sync_with_stdio(false);
    string s,t,u;
    int a,b;
    cin>>s>>t>>a>>b>>u;
    if(u==s) a--;
    else b--;
    cout<<a<<' '<<b<<endl;
}

Measured memory_bytes: 256
#include<stdio.h>
int main(){
    double mon;
    char name[10];
    int N;
    float sum=0.0;
    scanf("%d",&N);
    for(int i=0;i<N;i++){
        scanf("%lf",&mon);
        scanf("%s",name);
        if(name[0]=='B'){
            sum+=mon*380000.0;
        }else{
            sum+=mon;
        }
    }
    printf("%f\n",sum);
}

Measured memory_bytes: 128
from functools import reduce
def gcd(a,b):
    if b == 0:
        return a
    else:
        return gcd(b,a%b)
def gcdlist(A):
    if len(A) == 1:
        return A[0]
    else:
        return reduce(gcd,A)

N,K = map(int,input().split())
A = list(map(int,input().split()))
ans = gcdlist(A)
if (K in A or (K%ans == 0)) and K <= max(A):
    print('POSSIBLE')
else:
    print('IMPOSSIBLE')

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

#define _overload(_1,_2,_3,name,...) name
#define _rep(i,n) _range(i,0,n)
#define _range(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload(__VA_ARGS__,_range,_rep,)(__VA_ARGS__)

#define _rrep(i,n) _rrange(i,n,0)
#define _rrange(i,a,b) for(int i=int(a)-1;i>=int(b);--i)
#define rrep(...) _overload(__VA_ARGS__,_rrange,_rrep,)(__VA_ARGS__)

#define _all(arg) begin(arg),end(arg)
#define uniq(arg) sort(_all(arg)),(arg).erase(unique(_all(arg)),end(arg))
#define getidx(ary,key) lower_bound(_all(ary),key)-begin(ary)
#define clr(a,b) memset((a),(b),sizeof(a))
#define bit(n) (1LL<<(n))
#define popcount(n) (__builtin_popcountll(n))

using namespace std;

template<class T>bool chmax(T &a, const T &b) { return (a < b) ? (a = b, 1) : 0;}
template<class T>bool chmin(T &a, const T &b) { return (b < a) ? (a = b, 1) : 0;}

using ll = long long;
using R = long double;
const R EPS = 1e-9L; // [-1000,1000]->EPS=1e-8 [-10000,10000]->EPS=1e-7
inline int sgn(const R& r) {return (r > EPS) - (r < -EPS);}
inline R sq(R x) {return sqrt(max(x, 0.0L));}

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

// Problem Specific Parameter:

int a[110], b[110];
int c[110], d[110];

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

	rep(i, n) cin >> a[i] >> b[i];
	rep(i, n) cin >> c[i] >> d[i];

	using state = tuple<int, int, int>;
	vector<state> ary;

	rep(i, n) {
		ary.push_back(state(a[i], b[i], 0));
		ary.push_back(state(c[i], d[i], 1));
	}

	sort(rbegin(ary), rend(ary));

	int ans = 0;
	vector<int> used(2 * n, 0);

	for (auto &it : ary) {
		int x, y, idx;
		tie(x, y, idx) = it;
		if (idx == 0) {
			bool ok = false;

			for (int ny = y + 1; ny < 2 * n; ++ny) {
				if (used[ny]) {
					ok = true;
					used[ny]--;
					break;
				}
			}

			if (ok) ans++;
		} else {
			used[y]++;
		}
	}

	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;

typedef long long ll;
typedef pair<int,int> ii;
typedef tree<ii,null_type,less<ii>,rb_tree_tag,tree_order_statistics_node_update> indexed_set;

const int mx=1e5+777;

int main() {
	cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(0);
	vector<bool> flag(mx,true);
	flag[0]=flag[1]=false;
	for (int i=2; i*i<mx; i++)
		if(flag[i])
			for (int j=i; j*i<mx; j++)
				flag[i*j]=false;
	int x; cin>>x;

	for (int i=x; i<mx; i++)
		if(flag[i]) {
			cout<<i<<"\n";
			return 0;
		}

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
 
#define _overload(_1,_2,_3,name,...) name
#define _rep(i,n) _range(i,0,n)
#define _range(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define rep(...) _overload(__VA_ARGS__,_range,_rep,)(__VA_ARGS__)
 
#define _rrep(i,n) _rrange(i,n,0)
#define _rrange(i,a,b) for(int i=(int)(a)-1;i>=(int)(b);--i)
#define rrep(...) _overload(__VA_ARGS__,_rrange,_rrep,)(__VA_ARGS__)
 
#define _all(arg) begin(arg),end(arg)
#define uniq(arg) sort(_all(arg)),(arg).erase(unique(_all(arg)),end(arg))
#define getidx(ary,key) lower_bound(_all(ary),key)-begin(ary)
#define clr(a,b) memset((a),(b),sizeof(a))
#define bit(n) (1LL<<(n))
 
// #define DEBUG
 
#ifdef DEBUG
    #define dump(...) fprintf(stderr, __VA_ARGS__)
#else
    #define dump(...)
#endif
 
template<class T>bool chmax(T &a, const T &b) { return (a<b)?(a=b,1):0;}
template<class T>bool chmin(T &a, const T &b) { return (b<a)?(a=b,1):0;}
 
using namespace std;
using ll=long long;
using vi=vector<int>;
using vll=vector<ll>;
 
const double EPS = 1e-10;
const double PI = acos(-1.0);
const ll inf =1LL << 62;
const ll mod=1000000007LL;
const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};
 
 
ll extgcd(ll a,ll b,ll& x,ll& y){x=1,y=0;ll g=a;if(b!=0) g=extgcd(b,a%b,y,x),y-=a/b*x;return g;}
ll ADD(const ll &a, const ll &b,const ll &mod) { return (a+b)%mod;}
ll SUB(const ll &a, const ll &b,const ll &mod) { return (a-b+mod)%mod;}
ll MUL(const ll &a, const ll &b,const ll &mod) { return (1LL*a*b)%mod;}
ll DIV(const ll &a, const ll &b,const ll &mod) {ll x,y; extgcd(b,mod,x,y);return MUL(a,(x+mod)%mod,mod);}
 
random_device rd;
mt19937 mt(rd());
uniform_int_distribution<int> dice(1,6);
uniform_real_distribution<double> score(0.0,10.0);

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

    ll n; int Q; cin >> n >> Q;
    rep(loop, Q){
        ll a, b; cin >> a >> b;
        if(n == 1){
            cout << min(a, b) << endl;
            continue;
        }
        a--, b--;
        while(a != b){
            if(a < b) swap(a, b);
            a = (a - 1) / n;
        }
        cout << a+1 << endl;
    }

    return 0;
}


Measured memory_bytes: 1280
#include <iostream>
#include <algorithm>
#include <cstring>
#include <string>
#include <cmath>
#define ll long long
using namespace std;
ll a[100005];
int main(){
	ll n,A,B;
	cin>>n>>A>>B;
	for(ll i=0;i<n;i++){
		cin>>a[i];
	}
	ll sum=0;
	for(ll i=1;i<n;i++){
		ll ans1=(a[i]-a[i-1])*A;
		ll ans2=B;
		if(ans1<ans2)
			sum+=ans1;
		else
			sum+=ans2;
	}
	cout<<sum<<endl;
	return 0;
} 

Measured memory_bytes: 1024
import math


def solve_cos(star, telescope):
    inner = sum([i * j for i, j in zip(star, telescope)])
    dis_star = (sum(map(lambda a: a * a, star)))**(1 / 2)
    dis_telescope = (sum(map(lambda a: a * a, telescope)))**(1 / 2)
    return inner / (dis_star * dis_telescope)


while True:
    n = int(input())
    if n == 0:
        break
    stars = [list(map(float, input().split())) for i in range(n)]
    m = int(input())
    telescopes = [list(map(float, input().split())) for i in range(m)]

    count = 0
    for star in stars:
        for telescope in telescopes:
            cos1 = solve_cos(star, telescope[:-1])
            cos2 = math.cos(telescope[-1])
            if cos2 <= cos1:
                count += 1
                break

    print(count)


Measured memory_bytes: 5804
#include<iostream>
#include<string.h>
using namespace std;
unsigned long long tomod = 1000000007, dp[4][4][4], tmp[4][4][4];
unsigned long long ans(int len){
	for(int i = 0;i < 4;++i){
		for(int j = 0;j < 4;++j){
			for(int k = 0;k < 4;++k){
				if(i == 0 and j == 1 and k == 2)continue;
				if(i == 1 and j == 0 and k == 2)continue;
				if(i == 0 and j == 2 and k == 1)continue;
				dp[i][j][k] = 1;
			}
		}
	}
	unsigned res = 0;
	for(int t = 4;t <= len;++t){
		for(int i = 0;i < 4;++i){
			for(int j = 0;j < 4;++j){
				for(int k = 0;k < 4;++k){
					for(int l = 0;l < 4;++l){
						if(k == 1 and l == 2 and(i == 0 || j == 0))continue;
						if(i == 0 and l == 2 and(j == 1 || k == 1))continue;
						if(i == 0 and j == 1 and(k == 2 || l == 2))continue;
						if(i == 0 and j == 1 and k == 2)continue;
						if(j == 0 and k == 1 and l == 2)continue;
						if(i == 0 and j == 1 and k == 2)continue;
						if(i == 1 and j == 0 and k == 2)continue;
						if(i == 0 and j == 2 and k == 1)continue;
						tmp[j][k][l] = (tmp[j][k][l] + dp[i][j][k]) % tomod;
					}
				}
			}
		}
		memmove(dp, tmp, sizeof(tmp));
		memset(tmp, 0, sizeof(tmp));
	}
	for(int i = 0;i < 4;++i){
		for(int j = 0;j < 4;++j){
			for(int k = 0;k < 4;++k){
				if(i == 0 and j == 1 and k == 2)continue;
				if(i == 1 and j == 0 and k == 2)continue;
				if(i == 0 and j == 2 and k == 1)continue;
				res = (res + dp[i][j][k]) % tomod;
			}
		}
	}
	return res;
}
int main(){
	int len;
	cin >> len;
	cout << ans(len);

}


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

int main() {
	int n, k;
	cin >> n >> k;
	vector<long long> a(n);
	int sumall = 0;
	for (int i = 0; i < n; i++) {
		cin >> a[i];
		sumall += a[i];
	}

	set<long long> yakusuu;
	for (int i = 1; i < sqrt(sumall); i++) {
		if (sumall % i == 0) {
			yakusuu.insert(i);
			yakusuu.insert(sumall / i);
		}
	}

	long long ans = 1;

	for (auto e : yakusuu) {
		if (e == 1) continue;
		multiset<long long> pos;
		for (auto f : a) {
			int m = f % e;
			pos.insert(m);
		}
		int sum = 0;
		for (auto f : pos) {
			sum += f;
		}

		if (sum % e == 0) {
			int aa = sum / e;
			int b = 0;
			int count = 0;
			for (auto itr = pos.begin(); itr != pos.end() && count < (n - aa); itr++, count++) {
				b += *itr;
			}
			if (b <= k) ans = max(ans, e);
		}
	}

	cout << ans << endl;

	return 0;
}

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

int main() {
	string x; cin >> x;
	bool ok = 0;
	int sz = (int)x.size();
	for(int i = 0 ; i + 2 < sz ; ++i)
	{
		if(x[i] == x[i + 1] && x[i + 1] == x[i + 2])
		{ok = 1; break;}
	}
	cout << (ok ? "Yes" : "No");
	return 0;
}

Measured memory_bytes: 3064
#include<stdio.h>
#include<vector>
#include<algorithm>
#include<set>
using namespace std;
#define SIZE 100000
class unionfind
{
public:
	int par[SIZE];
	int ran[SIZE];
	int ren[SIZE];
	int rot[SIZE];
	void init()
	{
		for (int i = 0; i<SIZE; i++)
		{
			par[i] = i;
			ran[i] = 0;
			ren[i] = 1;
			rot[i] = i;
		}
	}
	int find(int a)
	{
		if (a == par[a])return a;
		else return par[a] = find(par[a]);
	}
	void unite(int a, int b)
	{
		a = find(a);
		b = find(b);
		if (a == b)return;
		if (ran[a]>ran[b])
		{
			par[b] = a;
			ren[a] += ren[b];
		}
		else
		{
			par[a] = b;
			ren[b] += ren[a];
		}
		if (ran[a] == ran[b])ran[b]++;
	}
};
unionfind uf;
typedef pair<int, int>pii;
set<int>s1[100000], s2[100000];
bool flag[100000];
int num;
void dfs(int a, int b)
{
	a = uf.rot[uf.find(a)], b = uf.rot[uf.find(b)];
	if (uf.find(a) == uf.find(b))return;
	//printf("------------%d %d--------------\n", a + 1, b + 1);
	for (int i = 0; i < num; i++)
	{
		/*printf("%d   ", i + 1);
		set<int>::iterator it = s1[i].begin();
		for (;;)
		{
			if (it == s1[i].end())break;
			printf("%d ", (*it) + 1);
			it++;
		}
		printf("     "); 
		it = s2[i].begin();
		for (;;)
		{
			if (it == s2[i].end())break;
			printf("%d ", (*it) + 1);
			it++;
		}
		printf("\n");*/
	}
	uf.unite(a, b);
	if (s1[a].size() + s2[a].size() < s1[b].size() + s2[b].size())swap(a, b);
	set<int>::iterator it = s1[b].begin();
	vector<pii>r;
	for (;;)
	{
		if (it == s1[b].end())break;
		int z = *it;
		it++;
		if (z == a)continue;
		if (s2[a].find(z) != s2[a].end())r.push_back(make_pair(a, z));
	}
	it = s2[b].begin();
	for (;;)
	{
		if (it == s2[b].end())break;
		int z = *it;
		it++;
		if (z == a)continue;
		if (s1[a].find(z) != s1[a].end())r.push_back(make_pair(a, z));
	}
	it = s1[b].begin();
	for (;;)
	{
		if (it == s1[b].end())break;
		int z = *it;
		it++;
		if (z == a)continue;
		s1[a].insert(z);
		if (s1[z].find(b) != s1[z].end())s1[z].erase(b), s1[z].insert(a);
	}
	it = s2[b].begin();
	for (;;)
	{
		if (it == s2[b].end())break;
		int z = *it;
		it++;
		if (z == a)continue;
		s2[a].insert(z);
		if (s2[z].find(b) != s2[z].end())s2[z].erase(b), s2[z].insert(a);
	}
	s1[a].erase(b), s2[a].erase(b);
	s1[b].clear(), s2[b].clear();
	uf.rot[uf.find(a)] = a;
	for (int i = 0; i < r.size(); i++)dfs(r[i].first, r[i].second);
}
int main()
{
	scanf("%d", &num);
	for (int i = 0; i < num - 1; i++)
	{
		int za, zb;
		scanf("%d%d", &za, &zb);
		za--, zb--;
		s1[za].insert(zb);
		s1[zb].insert(za);
	}
	for (int i = 0; i < num - 1; i++)
	{
		int za, zb;
		scanf("%d%d", &za, &zb);
		za--, zb--;
		s2[za].insert(zb);
		s2[zb].insert(za);
	}
	fill(flag, flag + num, true);
	uf.init();
	vector<pii>z;
	for (int i = 0; i < num; i++)
	{
		set<int>::iterator it = s1[i].begin();
		for (;;)
		{
			if (it == s1[i].end())break;
			int t = *it;
			it++;
			if (s2[i].find(t) != s2[i].end())z.push_back(make_pair(i, t));
		}
	}
	for (int i = 0; i < z.size(); i++)dfs(z[i].first, z[i].second);
	printf(uf.ren[uf.find(0)] == num ? "YES\n" : "NO\n");
}

Measured memory_bytes: 46720
#include <bits/stdc++.h>
#include <climits>
#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
#define srep(i, begin, end) for (__typeof(end) i = begin; i != end; i++)
#define si(x) int x = scanInt();
#define sll(x) LL x = scanLong();
#define sci(x) int x; scanf("%d", &x);
#define scll(x) LL x; scanf("%lld", &x);
#define pi(x) printf("%d ", x)
#define pll(x) printf("%lld ", x)
#define nl printf("\n")
#define clr(a) memset(a, 0, sizeof(a))
#define PB push_back
#define MP make_pair
using namespace std;
typedef unsigned int UI; // 32 bit integer
typedef long int LI; // 32 bit integer
typedef unsigned long int ULI; // 32 bit unsigned integer
typedef long long int LL; // 64 bit integer
typedef unsigned long long int  ULL; // 64 bit unsigned integer
typedef long double LD;
typedef vector<int> VI;
typedef vector<LL> VLL;
typedef pair<int, int> PII;
typedef pair<LL, LL> PLL;
const LL MOD = 1e9+7;

/* Fast I/O */
inline int scanInt() {
	int n = 0;
	char ch = getchar();
	int sign = 1;
	while(ch < '0' || ch > '9') {
		if(ch == '-')	sign = -1;
		ch = getchar();
	}
	while(ch >= '0' && ch <= '9') {
		n = (n<<1)+(n<<3)+(int)(ch-'0');
		ch = getchar();
	}
	return n*sign;
}

inline LL scanLong() {
	LL n = 0;
	char ch = getchar();
	LL sign = 1;
	while(ch < '0' || ch > '9') {
		if(ch == '-')	sign = -1;
		ch = getchar();
	}
	while(ch >= '0' && ch <= '9') {
		n = (n<<1)+(n<<3)+(LL)(ch-'0');
		ch = getchar();
	}
	return n*sign;
}

const LL MAXN = 1e5+10;
VLL adj[MAXN];

bool dfs(LL curr, LL par, LL a, LL b) {
	if(curr == a || curr == b)	return (curr == b);
	rep(it, adj[curr].begin(), adj[curr].end()) {
		if(*it != par) {
			if(dfs(*it, curr, a, b))	return true;
		}
	}
	return false;
}

int main() {
	sll(n); sll(m);
	LL degrees[n+1];
	memset(degrees, 0, sizeof degrees);
	rep(i, 0, m) {
		sll(a); sll(b);
		degrees[a]++;
		degrees[b]++;
		adj[a].push_back(b);
		adj[b].push_back(a);
	}
	if(n == 1) {
		puts("No");
		return 0;
	}
	LL cnt_four = 0;
	rep(i, 1, n+1) {
		if(degrees[i]%2 == 1) {
			puts("No");
			return 0;
		}
		if(degrees[i] == 4)	cnt_four++;
	}
	LL maxDegree = *max_element(degrees+1, degrees+n+1);
	if(maxDegree >= 6)	puts("Yes");
	else if(maxDegree == 2)	puts("No");
	else if(cnt_four >= 3)	puts("Yes");
	else if(cnt_four == 2) {
		LL a = -1, b = -1;
		rep(i, 1, n+1) {
			if(degrees[i] == 4)	{
				if(a == -1)	a = i;
				else	b = i;
			}
		}
		LL cnt = 0;
		rep(it, adj[a].begin(), adj[a].end()) {
			if(dfs(*it, a, a, b))	cnt++;
		}
		if(cnt == 2)	puts("Yes");
		else	puts("No");
	}
	else puts("No");
}


Measured memory_bytes: 8448
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <utility>
#include <cmath>
#include <vector>
#include <queue>
#include <set>
#include <map>
#define rep(i, n) for(int i = 0; i < n; i++)
using namespace std;
typedef long long ll;
const ll mod = 1000000007;

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

    int ans = 1;
    char now = s[0];
    rep(i, n) {
        if(now != s[i]) {
            now = s[i];
            ans++;
        }
    }

    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 512
#include<bits/stdc++.h>
#define mp make_pair
#define pb push_back
#define ii pair<int,int>
#define all(x) (x).begin(),(x).end()
#define INF 100000000000000000
#define modulo 1000000007
#define mod 998244353
#define int long long int
using namespace std;
vector<int> group(1<<16,0);
vector<int> Q(1<<16,-1);
int dp(int x){
      if(Q[x]!=-1)return Q[x];
      if(x==0)return 0;
      int mx=0;
      for(int i=1;i<=x;i++){
            if((~x)&i)continue;
            mx=max(mx,group[i]+dp(x^i));
      }
      return Q[x]=mx;
}
int32_t main(){
      ios_base::sync_with_stdio(false);
      cin.tie(NULL);
   //   freopen("q.gir","r",stdin);
   //   freopen("q.cik","w",stdout);
      int n;
      cin>>n;
      int val[n][n];
      for(int i=0;i<n;i++)for(int j=0;j<n;j++)cin>>val[i][j];

      for(int i=1;i<(1<<n);i++){
            int w=(i&-i);
            int v=0;
            while((1<<v)!=w)v++;
            int cnt=group[i-w];
            for(int q=0;q<n;q++){
                  if((1<<q)&(i-w)){
                        cnt+=val[v][q];
                  }
            }
            group[i]=cnt;
      }
      cout<<dp((1<<n)-1);
}


Measured memory_bytes: 1280
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

int main(void){
	int w,h,n;
	cin >> w >> h >> n;

	vector<int> x(n);
	vector<int> y(n);
	vector<int> a(n);

	for (int i = 0; i < n; i++)
	{
		cin >> x[i] >> y[i] >> a[i];
	}

	int max_x, min_x,max_y, min_y;

	max_x = w;
	max_y = h;
	min_x = 0;
	min_y = 0;

	for (int i = 0; i < n; i++)
	{
		if(a[i] == 1)
		{
			if(min_x <= x[i])
				min_x = x[i];
		} 
		else if(a[i] == 2) 
		{
			if(max_x >= x[i])
				max_x = x[i];
		} 
		else if(a[i] == 3) 
		{
			if(min_y <= y[i])
				min_y = y[i];
		} 
		else if(a[i] == 4) 
		{
			if(max_y >= y[i])
				max_y = y[i];
		}
	}
	if(max_x <= min_x || max_y <= min_y)
	{
		cout << 0 << endl;
	}else
	{
		cout << (max_x - min_x)*(max_y - min_y) << endl;
	}

	return 0;
}

Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#include <cstdio>
#include <cstring>
#include <ctype.h>
#include <iostream>
#include <vector>
#include <bitset>
#include <algorithm>
#include <set>

#define ft first
#define sd second
#define mp make_pair
#define pb push_back

using namespace std;

typedef long long int ll;

const int MAXN = 2000000;
const int INF = 1e9 + 10;
const ll MOD = 1e9 + 7;

int N;
ll A[MAXN];
ll sm[MAXN];
pair<ll, ll> dp_pos[MAXN], dp_neg[MAXN];

int main() {
#ifdef _DEBUG
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#else
#endif

    scanf("%d", &N);
    for (int i = 0; i < N; ++i) {
        scanf("%lld", &A[i]);
        sm[i] = A[i];
        if (i) {
            sm[i] += sm[i-1];
        }
    }

    if (A[0] > 0) {
        dp_pos[0] = mp(0LL, 0LL);
        dp_neg[0] = mp(A[0] + 1LL, - A[0] - 1LL);
    } else if (A[0] < 0) {
        dp_pos[0] = mp(-A[0] + 1LL, -A[0] + 1LL);
        dp_neg[0] = mp(0LL, 0LL);
    } else {
        dp_pos[0] = mp(1LL, 1LL);
        dp_neg[0] = mp(1LL, -1LL);
    }

    ll tmp;
    for (int i = 1; i < N; ++i) {
        tmp = sm[i] + dp_neg[i-1].second;

        dp_pos[i] = dp_neg[i-1];
        if (tmp <= 0) {
            dp_pos[i].first += -tmp + 1;
            dp_pos[i].second += -tmp + 1;
        }

        tmp = sm[i] + dp_pos[i-1].second;
        dp_neg[i] = dp_pos[i-1];
        if (tmp >= 0) {
            dp_neg[i].first += tmp + 1;
            dp_neg[i].second += -tmp - 1;
        }
    }

    printf("%lld", min(dp_pos[N-1].first, dp_neg[N-1].first));

    return 0;
}

Measured memory_bytes: 9984
package main

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

func main() {
	scanner := bufio.NewScanner(os.Stdin)
	d := 0
	e := 0
	for scanner.Scan() {
		info := strings.Split(scanner.Text(), ",")
		a, _ := strconv.Atoi(info[0])
		b, _ := strconv.Atoi(info[1])
		c, _ := strconv.Atoi(info[2])
		if a*a + b*b == c*c {
			d++
		}
		if a == b {
			e++
		}
	}
	fmt.Println(d)
	fmt.Println(e)
}


Measured memory_bytes: 1072
#include<bits/stdc++.h>
using namespace std;
     
     
//#define SPEED ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define ll long long
#define sd(x) scanf("%d",&x)
#define sld(x) scanf("%lld",&x)
#define pld(x) printf("%lld\n",x)
#define pd(x) printf("%d\n",x)
     
     
int main(){

	int a,b;
	sd(a); sd(b);

	if(a>=13)pd(b);
	else if(a <= 12 && a >=6)pd(b/2);
	else printf("0\n");            
                   
    return 0;
}


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

int main(){
  map<string,int> table;
  string word;
  int k1 = 0;
  int k2 = 0;
  string answer1;
  string answer2;
  while(cin >> word){
    table[word]+=1;
    if(table[word] > k1){
      k1 = table[word];
      answer1 = word;
    }
    int len = word.length();
    if (len > k2){
      k2 = len;
      answer2 = word;
    }
  }
  cout << answer1 << " " << answer2 << endl;
}

Measured memory_bytes: 3180
#include <bits/stdc++.h>
using namespace std;
typedef long long int64;
typedef pair<int,int> P;
#define F first
#define S second
string to_str(int data){
  ostringstream os;
  os << data;
  return os.str();
}
int main(){
  int64 H,W,N;
  int y,x;
  int64 sum[10] = {0};
  map<P,int>mp;
  cin >> H >> W >> N;
  while(N--){
    scanf("%d %d",&y,&x);
    y--;x--;
    for(int i = 2;i >= 0;i--){
      for(int j = 2;j >= 0;j--){
	if(0 <= y - i && y + 2 - i < H && 0 <= x - j && x + 2 - j < W){
	  P a;a.F = y - i;a.S = x - j;
	  if(mp.find(a) != mp.end())mp[a]++;
	  else mp[a] = 1;
	}
      }
    }
  }
  int64 cnt = 0;
  for(map<P,int>::iterator itr = mp.begin();itr != mp.end();itr++){
    sum[itr->second]++;
    cnt++;
  }
  sum[0] = (H - 2) * (W - 2) - cnt;
  for(int i = 0;i < 10;i++){
    cout << sum[i] << endl;
  }
  return 0;
}


Measured memory_bytes: 56448
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
int main() {
	int n,p[100000],count=0;
	cin >> n;
	for (int i = 0; i < n; i++)cin >> p[i];
	for (int i = 0; i < n; i++) {
		if (i+1 == p[i]) {
			swap(p[i], p[i + 1]);
			count++;
		}
	}
	cout << count << endl;
	int x;
	cin >> x;
	return 0;
}

Measured memory_bytes: 640
s=list(input())
for i in range(1<<3):
    temp=s[0]
    for j in range(3):
        if i&(1<<j):
            temp+="+"
        else:
            temp+="-"
        temp+=s[j+1]
    ans=eval(temp)
    if ans==7:
        print(temp+"=7")
        exit()

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define exrep(i, a, b) for(long long i = a; i <= b; i++)
#define rep(i,n)for(long long i=0;i<(long long)(n);i++)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> P;
typedef vector<ll> vl;
typedef vector<string> vs;
typedef vector<P> vp;
typedef vector<vector<ll> > vvl;
typedef vector<vector<P> > vvp;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
 
const ll MOD=1e9+7;
const ll INF=1e18;
const int MAX=510000;
const double pi=acos(-1);
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};


int main(){
  cin.tie(0);
  ios::sync_with_stdio(false); 
  
  string s;
  cin >> s;
  if(s[0]==s[1] && s[1] == s[2])cout << "No" << endl;
  else cout << "Yes" << endl;
  return 0;     
}


Measured memory_bytes: 256
package main

import "fmt"

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

func main() {
	var a, b, ans int
	fmt.Scan(&a, &b)
	ans = max(a+a-1, b+b-1)
	ans = max(ans, a+b)
	fmt.Println(ans)
}


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

using namespace std;

#define ll long long

const ll mod = 1e9 + 7;

int
main(void){
	int n, k; cin >> n >> k;
	vector<int> vec(n);
	for(int i = 0; i < n; i++) cin >> vec[i];
	
	vector<vector<ll> > dp(n + 1, vector<ll> (k + 1));
	vector<ll> pref(k + 1);
	pref[0] = 1;
	for(int i = 1; i < k + 1; i++){
		pref[i] += pref[i - 1];
	} 
	/*dp[0][0] = 1;
	for(int i = 1; i <= n; i++){
		for(int used = 0; used <= k; used++){
			for(int upto = 0; upto <= vec[i - 1]; upto++){
				if(used - upto >= 0) dp[i][used] += dp[i - 1][used - upto];
				dp[i][used] %= mod;
			}
		}
	}
	
	for(int i = 0; i <= n; i++){
		for(int j = 0; j <= k; j++){
			cout << dp[i][j] << " ";
		} 
		cout << endl;
	}*/
	
	 
	dp[0][0] = 1;
	for(int i = 1; i <= n; i++){
		for(int used = 0; used <= k; used++){
			if(used - vec[i - 1] > 0) dp[i][used] = (pref[used] - pref[used - vec[i - 1] - 1] + mod);
			else dp[i][used] = (pref[used]);
			dp[i][used] %= mod;
		}
		for(int j = 0; j <= k; j++) pref[j] = 0;
		for(int j = 0; j <= k; j++){
			if(j > 0) pref[j] += pref[j - 1] + dp[i][j];
			else pref[j] = dp[i][j];
			
			pref[j] %= mod;
		}
	}
	
	/*for(int i = 0; i <= n; i++){
		for(int j = 0; j <= k; j++){
			cout << dp[i][j] << " ";
		} 
		cout << endl;
	}*/
	
	cout << dp[n][k];
}

Measured memory_bytes: 80256
#include<iostream>
#include<map>
#include<cmath>
#include<vector>
using namespace std;
//  n, k;
#define loop(i, start, end) for(int i = start; i <= end; i++)
#define ll long long int
#define pb push_back
// vector<ll> weight, value;
// ll n, w;
int main(){
	int n, k;
	cin>>n >> k;
	int h[n];
	for(int i=0;i<n;i++)
	    cin>>h[i];

    vector<int> dp(n, 1e9+5);
    dp[0] = 0;
    dp[1] = abs(h[1]-h[0]);
	for(int i=2; i < n; i++){
        loop(j, 1, k){
            if(i-j < 0)
            break;
            dp[i] = min(dp[i], dp[i-j]+abs(h[i]-h[i-j]));
        }
	}
	cout<<dp[n-1];
	return 0;
}

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

int main() {
  int N;
  cin >> N;
  if ((N % 1000) % 111 == 0 || (N / 10) % 111 == 0) {
    cout << "Yes" << endl;
  }
  else {
    cout << "No" << endl;
  } 
}

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

int main(){
    int a,b; cin >> a >> b;
    int ans = 0;
    for(int i=0; i<2; i++){
        if(a > b){
            ans += a;
            a--;
        }else{
            ans += b;
            b--;
        }
    }

    cout << ans << endl;
}

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

typedef int _loop_int;
#define REP(i, n) for(_loop_int i=0;i<(_loop_int)(n);i++)
#define FOR(i,a,b) for(_loop_int i=(_loop_int)(a);i<(_loop_int)(b);++i)

int main(){
    int N, T; cin >> N >> T;
    int t[N];
    REP( i, N) cin >> t[i];
    // REP( i, N) cout << t[i] << endl;

    int time = 0;
    for( int i = 1; i < N; i++ ){
        int dif = t[i]-t[i-1];
        time += min( dif, T);
    }
    time += T; //not beautiful
    cout << time << endl;

    return 0;
}

Measured memory_bytes: 1024
#include<iostream>
#include<cmath>
#include<string>
#include<map>
#include<queue>
using namespace std;
#define N 3
#define N2 9

struct Puzzle{
  int f[N2];
  int space;
  string path;

  bool operator<(const Puzzle &p) const{
    for(int i=0;i<N2;i++){
      if(f[i]==p.f[i]) continue;
      return f[i] > p.f[i];
    }
    return false;
  }
};

static const int dx[4]={-1,0,1,0};
static const int dy[4]={0,-1,0,1};
static const char dir[4]={'u','l','d','r'};



bool isTarget(Puzzle p){
  for(int i=0;i<N2;i++){
    if(p.f[i] != (i+1)) return false;
  }
  return true;
}

string bfs(Puzzle s){
  queue<Puzzle> Q;
  map<Puzzle, bool> V;
  Puzzle u, v;
  s.path="";
  Q.push(s);
  V[s]=true;

  while(!Q.empty()){
    u=Q.front(); Q.pop();
    if(isTarget(u)) return u.path;
    int sx=u.space/N;
    int sy=u.space%N;

    for(int r=0;r<4;r++){
      int tx=sx+dx[r];
      int ty=sy+dy[r];
      if(tx<0||ty<0||tx>=N||ty>=N) continue;
      v=u;
      swap(v.f[u.space],v.f[tx*N+ty]);
      v.space=tx*N+ty;
      if(!V[v]){
	V[v]=true;
	v.path+=dir[r];
	Q.push(v);
      }
    }
  }

  return "unsolvable";
  
}

int main(){
  
  Puzzle in;

  for(int i=0;i<N2;i++){
    cin >> in.f[i];
    if(in.f[i]==0){
      in.f[i]=N2;//set space
      in.space=i;
    }
  }

  string ans=bfs(in);
  cout << ans.size() << endl;

  return 0;
  
}



Measured memory_bytes: 30676
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define repr(i,n) for(int i = (int)(n); i >= 0; i--)
#define all(v) v.begin(),v.end()
typedef long long ll;

int main(){
    int N,M;
    cin >> N >> M;
    vector<int> roads(N,0);
    rep(i,M){
        int a,b;
        cin >> a >> b;
        roads[a - 1]++;
        roads[b - 1]++;
    }
    rep(i,N){
        cout << roads[i] << endl;
    }
}


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

int vis[10];
long long f(int n){
    long long ans = 1;
    for(int i = 2;i<=n;i++){
        ans*=i;
    }
    return ans;
}

int main(){
    int n,p,q;
    long long ans1 = 0,ans2 = 0;

    cin >> n;
    for(int i = 0;i < n;i++){
        cin >> p;
        vis[p] = 1;
        for(int j = 1;j < p;j++){
            if(!vis[j]) ans1+=f(n-i-1);
        }
    }
    memset(vis,0,sizeof(vis));
    for(int i = 0;i < n;i++){
        cin >> q;
        vis[q] = 1;
        for(int j = 1;j < q;j++){
            if(!vis[j]) ans2+=f(n-i-1);
        }
    }
    cout << abs(ans1-ans2);
}


Measured memory_bytes: 256
H,W = map(int,raw_input().split())
M = [map(int,list(raw_input())) for i in range(H)]
M.insert(0,[0]+[500]*(W-1))
for h in range(1,H+1):
	M[h][0] += M[h-1][0]
	for w in range(1,W):
		M[h][w] += min(M[h-1][w],M[h][w-1])
print M[H][W-1]

Measured memory_bytes: 4276
let id x = x

let print_complex { Complex.re; Complex.im } = Printf.printf "%f + i %f" re im

let rot90 { Complex.re; Complex.im } = { Complex.re = ~-.im; Complex.im = re }

let scalar_mul t { Complex.re; Complex.im } = { Complex.re = t *. re; Complex.im = t *. im }

module Circle = struct
  type t = { center : Complex.t; radius : float }
  
  let eps = 1e-8

  let contains c p = Complex.norm2 (Complex.sub c.center p) <= c.radius *. c.radius +. eps

  let intersections_of_circles { center = p1; radius = r1 } { center = p2; radius = r2 } =
    let d = Complex.sub p2 p1 in
    let e = rot90 d in
    let s = (Complex.norm2 d +. r1 *. r1 -. r2 *. r2) /. (2.0 *. Complex.norm2 d) in
    let a = scalar_mul s d in
    let t = sqrt (r1 *. r1 /. Complex.norm2 d -. s *. s) in
    let b = scalar_mul t e in
    let intersected = abs_float (r1 -. r2) <= Complex.norm d +. eps &&
                      Complex.norm d <= r1 +. r2 +. eps in
    if intersected
    then [Complex.add p1 (Complex.add a b); Complex.add p1 (Complex.sub a b)]
    else []
end

let n = Scanf.scanf "%d" id
let k = Scanf.scanf " %d" id
let a = Array.to_list @@ Array.init n (fun _ ->
  let p = Scanf.scanf " %f %f" (fun x y -> { Complex.re = x; Complex.im = y }) in
  let c = Scanf.scanf " %f" id in
  (p, c))

let can t =
  let cs = List.map (fun (p, c) -> { Circle.center = p; Circle.radius = t /. c }) a in
  let rec f cs acc = match cs with
    | [] -> acc
    | c1 :: cs -> f cs (List.fold_left (fun acc c2 -> Circle.intersections_of_circles c1 c2 @ acc) acc cs) in
  let ps = f cs (List.map fst a) in
  List.exists (fun p -> List.length (List.filter (fun c -> Circle.contains c p) cs) >= k) ps

let rec binary_search lb ub n =
  if n = 0
  then ub
  else let m = (lb +. ub) /. 2.0 in
       if can m
       then binary_search lb m (n - 1)
       else binary_search m ub (n - 1)

let () = Printf.printf "%.10f\n" @@ binary_search 0.0 1e8 100

Measured memory_bytes: 5248
N,X = map(int,input().split())
A =  [int(input()) for _ in range(N)]
A.sort()

#print(A)
count = 0
sm = 0
rem = 0
for i in A:
    sm += i
    if sm <= X:
        count += 1
    else:
        break
rem = X-sm
print(count+rem//min(A))
    

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

int main() {
  int n;
  cin >> n;
  cout << ((n+1)/2) / (n * 1.0) << endl;;
  return 0;
}


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

using namespace std;

int main()
{
    int N[32] = { 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 K;
    cin >> K;
    cout << N[K-1] << endl;
    return 0;
}

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

int main(){
	int N;
	cin >> N;
	vector<int> H(N);
	rep(i,N){
		cin >> H[i];
	}
	
	int ans = 1;
	int temp = H[0];
	
	rep(i,N-1){
		if(H[i+1] >= temp){
			ans++;
			temp = H[i+1];
		}
	}
	
	cout << ans << endl;
    return 0;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n;
  int z[]={10,50,100,500};
  int i=0;
  while(cin>>n,n){
    if(i) cout<<endl;
    int a[4]; cin>>a[0]>>a[1]>>a[2]>>a[3];
    int x=10*a[0]+50*a[1]+100*a[2]+500*a[3]-n;
    int p[4]={};
    for(i=3;i>=0;--i){
      p[i]=x/z[i];
      x-=p[i]*z[i];
    }
    for(i=0;i<4;++i)
      if(a[i]>p[i])
        cout<<z[i]<<' '<<a[i]-p[i]<<endl;
  }
  return 0;
}

Measured memory_bytes: 3124
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int a,b,c,d;
	scanf("%d%d%d%d",&a,&b,&c,&d);
	a=a+b;
	c=c+d;
	if(a>c) printf("Left");
	if(a<c) printf("Right");
	if(a==c) printf("Balanced");
	printf("\n");
    return 0;
}


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

#define eb emplace_back
#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define forn(i, n) for (int i = 0; i < (int)(n); ++i)
#define for1(i, n) for (int i = 1; i <= (int)(n); ++i)
#define ford(i, a, b) for (int i = (int)(a); i >= (int)b; --i)
#define fore(i, a, b) for (int i = (int)(a); i <= (int)(b); ++i)
#define rep(i, l, r) for (int i = (l); i <= (r); i++)
#define per(i, r, l) for (int i = (r); i >= (l); i--)
#define ms(x, y) memset(x, y, sizeof(x))
 
using namespace std;
 
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pii> vpi;
typedef vector<vi> vvi;
typedef long long i64;
typedef vector<i64> vi64;
typedef vector<vi64> vvi64;
typedef pair<i64, i64> pi64;
typedef double ld;
 
template<class T> bool uin(T &a, T b) { return a > b ? (a = b, true) : false; }
template<class T> bool uax(T &a, T b) { return a < b ? (a = b, true) : false; }

int a, b, c;
 
int main() {
	ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.precision(10);
    cout << fixed;
#ifdef LOCAL_DEFINE
    freopen("in", "r", stdin);
#endif
	
	set<int> st;
	cin >> a >> b >> c;
	st.insert(a);
	st.insert(b);
	st.insert(c);
	cout << (int(st.size()) == 2 ? "Yes" : "No") << '\n';
		
#ifdef LOCAL_DEFINE
    cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
#endif
	return 0;
}

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

XM = max(X)
Xm = min(X)
ans = []
res = 0
for x in range(Xm, XM+1):
    for i in range(n):
        res += (X[i]-x)**2
    ans.append(res)
    res = 0
    
print(min(ans))

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

#define ll long long
#define F(i,m,n) for(ll i=m;i<n;i++)
#define Fr(j,n,m) for(ll j=n;j>=m;j--)
#define vll vector<ll>
#define pll pair<ll,ll>
#define ff first
#define ss second
#define vpll vector< pll >
#define tlll tuple < ll ,ll,ll >
/*-------------------------------------*---------------------------------------*/

#define godspeed ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define deb(x) cout << #x << "=" << x << endl
#define cout_array(a) cout<<#a<<"=";for(auto x: a){ cout<<x<<" ";}cout<<endl

ll gcd(ll a,ll b){
    return (b?gcd(b,a%b):a);
}
const ll MAX_PRIME = 1e9+7;
const ll INF = 1e18;


/*I NEED YOU TO WORK FOR TWO HOURS ON THIS NO MATTER WHAT....THE RESULT DOESN'T MATTER.....ITS ALL ABOUT YOUR EFFORTS.
---------------------------------------------------------------------------------------------------------------------*/

ll fast_pow(ll x,ll y,ll z){
    if(y==0)return 1%z;
    else if(y==1)return x%z;
    if(y%2==0){
        ll res = fast_pow(x,y/2,z);
        return (res*res)%z;
    }
    else{
        ll res = fast_pow(x,y/2,z);
        ll temp = (res*res)%z;
        return ((x%z)*temp)%z;
    }
}
int main() {
    godspeed
    ll n;
    cin>>n;
    vll a(n+1,0);
    F(i,3,n+1){
        if(i<6)a[i] = 1;
        else a[i] = (a[i-1] + a[i-3])%MAX_PRIME;
    }
    cout<<a[n]<<endl;
    return 0;
}


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

#define endl '\n'
#define ALL(a)  (a).begin(),(a).end()
#define ALLR(a)  (a).rbegin(),(a).rend()
#define spa << " " <<
#define test cout<<"test"<<endl;
#define fi first
#define se second
#define MP make_pair
#define PB push_back
#define EB emplace_back
#define rep(i,n,m) for(ll i = (n); i < (ll)(m); i++)
#define rrep(i,n,m) for(ll i = (m) - 1; i >= (ll)(n); i--)
using ll = long long;
using ld = long double;
const ll MOD = 1e9+7;
//const ll MOD = 998244353;
const ll INF = 1e18;
using P = pair<ll, ll>;
template<typename T>
void chmin(T &a,T b){if(a>b)a=b;}
template<typename T>
void chmax(T &a,T b){if(a<b)a=b;}
void pmod(ll &a,ll b){a=(a+b)%MOD;}
void pmod(ll &a,ll b,ll c){a=(b+c)%MOD;}
void qmod(ll &a,ll b){a=(a*b)%MOD;}
void qmod(ll &a,ll b,ll c){a=(b*c)%MOD;}
ll median(ll a,ll b, ll c){return a+b+c-max({a,b,c})-min({a,b,c});}
void ans1(bool x){if(x) cout<<"Yes"<<endl;else cout<<"No"<<endl;}
void ans2(bool x){if(x) cout<<"YES"<<endl;else cout<<"NO"<<endl;}
void ans3(bool x){if(x) cout<<"Yay!"<<endl;else cout<<":("<<endl;}
template<typename T1,typename T2>
void ans(bool x,T1 y,T2 z){if(x)cout<<y<<endl;else cout<<z<<endl;}  
template<typename T>
void debug(vector<vector<T>>&v,ll h,ll w){for(ll i=0;i<h;i++)
{cout<<v[i][0];for(ll j=1;j<w;j++)cout spa v[i][j];cout<<endl;}};
void debug(vector<string>&v,ll h,ll w){for(ll i=0;i<h;i++)
{for(ll j=0;j<w;j++)cout<<v[i][j];cout<<endl;}};
template<typename T>
void debug(vector<T>&v,ll n){if(n!=0)cout<<v[0];
for(ll i=1;i<n;i++)cout spa v[i];cout<<endl;};
template<typename T>
vector<vector<T>>vec(ll x, ll y, T w){
  vector<vector<T>>v(x,vector<T>(y,w));return v;}
ll gcd(ll x,ll y){ll r;while(y!=0&&(r=x%y)!=0){x=y;y=r;}return y==0?x:y;}
vector<ll>dx={1,0,-1,0,1,1,-1,-1};
vector<ll>dy={0,1,0,-1,1,-1,1,-1};
template<typename T>
vector<T> make_v(size_t a,T b){return vector<T>(a,b);}
template<typename... Ts>
auto make_v(size_t a,Ts... ts){
  return vector<decltype(make_v(ts...))>(a,make_v(ts...));
}
ostream &operator<<(ostream &os, pair<ll, ll>&p){
  return os << p.first << " " << p.second;
}  
ll MAX_V = 2e5 + 5;
vector<ll>t(MAX_V);
ll cost=0;
ll lim;
ll dfs(ll k,ll par,vector<vector<ll>>&g){
  t[k]=1;
  ll maxbuf=0;
  for(ll i=0;i<g[k].size();i++){
    if(t[g[k][i]]==0){
      chmax(maxbuf,dfs(g[k][i],k,g)); 
    }
  }
  maxbuf++;
  if(maxbuf==lim&&par!=0){
    cost++;
    maxbuf=0;
  }
  return maxbuf;
}
int main(){
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  //cout<<fixed<<setprecision(10);
  ll res=0,buf=0;
  bool judge = true;
  ll n;cin>>n>>lim;
  vector<vector<ll>>g(n);
  ll a1;cin>>a1;
  if(a1!=1)cost++;
  rep(i,1,n){
    ll x;cin>>x;
    g[x-1].PB(i);
  }
  dfs(0,0,g);
  cout<<cost<<endl;
  return 0;
}

Measured memory_bytes: 13568
#include "bits/stdc++.h"
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long int ll;
typedef pair<ll, ll> P;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

char c[2][3];

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    rep(i,2)rep(j,3) cin >> c[i][j];
    if(c[0][0] == c[1][2] && c[0][1] == c[1][1] && c[0][2] == c[1][0]) cout << "YES" << endl;
    else cout << "NO" << endl;
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
int h[4],i,j;
void sw(void){
int f;
f = h[j];
h[j] = h[j+1];
h[j+1] = f;
return;
}
int main(void){
for(i = 0;i < 10;i++){
scanf("%d",h+3);
for(j = 2;j >= 0;j--)if(h[j] < h[j+1])sw();
}
printf("%d\n%d\n%d\n",h[0],h[1],h[2]);
return 0;
}

Measured memory_bytes: 600
#include<iostream>
using namespace std;
int ans(int);
int main(){
	
	
	int k;
	cin>>k;
	cout<<ans(k);
	
}
int ans(int k){
	if(k%2==0){
		return (k*k/4);
	}else{
		k=k-1;
		k=k/2;
		return k*(k+1);
	}
}


Measured memory_bytes: 256