akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#define ll long long
#define pii pair<ll int,ll int>
#define PI 2*acos(0)
#define INF 1e8
#define mx 1000006
using namespace std;
const ll int p=1000000007;
//vector<ll > prime;
//bool mark[mx];
ll int mod(ll int a,ll int b)
{
    ll int m=a%b;
    if(m<0) m=(b<0)?(m-b):(m+b);
    return m;
}
ll maxpow(ll n)
{
    return (n & (~(n-1)));
}
bool isPrime(ll n)
{
    if(n<2) return false;
    if(n==2) return true;
    if(n%2==0) return false;
    for(ll i=3;i*i<=n;i+=2){
        if(n%i==0) return false;
    }
    return true;
}
/*void init()
{
    mark[1]=1;
    int i,j,limit=sqrt(mx*1.0)+2;
    prime.push_back(2);
    for(i=4;i<mx;i+=2) mark[i]=1;
    mark[2]=0;
    for(i=3;i<mx;i+=2){
        if(!mark[i]){
            prime.push_back(i);
            if(i<=limit){
                for(j=i*i;j<mx;j+=2*i){
                    mark[j]=1;
                }
            }
        }
    }
}
/*
ll maxdiv(ll n)
{
    ll i,ans=1;
    for(i=0;i<prime.size();i++){
        if(n%prime[i]==0){
            ans=n/prime[i];break;
            //return ans;
        }
    }
    return ans;
}*/
ll lcm(ll a,ll b)
{
    ll ans=a*b;
    return (ans/__gcd(a,b));
}
// ax+by and a>b
ll gcd(ll a,ll b,ll &x,ll &y)
{
    if(b==0){
        x=1;
        y=0;
        return a;
    }
    ll x1,y1;
    ll d=gcd(b,mod(a,b),x1,y1);
    x=y1;
    y=x1-y1*(a/b);
    return d;
}
ll abso(ll a)
{
    if(a>=0) return a;
    return -a;
}
int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    ll n,i,j,k,mul,sum,cnt,ans;
    cin>>n;
    ll a[n+1];
    for(i=1;i<=n;i++) cin>>a[i];
    ll s[n+1];s[0]=0;
    s[1]=a[1];
    for(i=2;i<=n;i++) s[i]=mod(s[i-1]+a[i],p);
    sum=0;
    for(i=1;i<=n;i++){
        sum+=mod(a[i],p)*mod(s[n]-s[i],p);
        sum=mod(sum,p);
    }
    cout<<sum;
    return 0;
}
//1028C


Measured memory_bytes: 6744
#include <iostream>
#include <algorithm>
#include <deque>
#include <iterator>
#include <list>
#include <map>
#include <memory>
#include <queue>
#include <set>
#include <stack>
#include <utility>
#include <vector>
#include <cmath>
#define rep(i, n) for (i = 0; i < n; i++)
using namespace std;

long long p[200000][2];

int main()
{
    int N, D, i, j;
    cin >> N >> D;
    rep(i, N) cin >> p[i][0] >> p[i][1];

    int ans = 0;
    double d;

    rep(i, N)
    {
        d = sqrt(p[i][0] * p[i][0] + p[i][1] * p[i][1]);
        if (d <= D)
            ans++;
    }
    cout << ans << endl;
    return 0;
}

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

int main(int argc, char *argv[]) {
  int a, b;
  
  while (scanf("%d%d", &a, &b) != EOF) {
    a += b;
    for (b = 1; a /= 10; ) ++b;
    printf("%d\n", b);
  }

  return EXIT_SUCCESS;
}

Measured memory_bytes: 600
// In the name of God

#include <iostream>
#include <algorithm>
#include <fstream>
#include <vector>
#include <deque>
#include <assert.h>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <stdio.h>
#include <string.h>
#include <utility>
#include <math.h>
#include <bitset>
#include <iomanip>

using namespace std;

const int N = (int) 2e5 + 5, mod = (int) 0;
int f[N], cnt[2], mat[3][N], a[2][N], o[2][N], b[N], ob[N];
void nope() {
    cout << "No" << endl;
    exit(0);
}
int query(int m, int res = 0) { m++;
    while (m > 0)
        res += f[m], m -= m & -m;
    return res;
}
void update(int m) { m++;
    while (m < N)
        f[m]++, m += m & -m;
}
int32_t main() {
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    int n;
    cin >> n;
    for (int i = 0; i < 3; ++i) {
        for (int j = 0; j < n; ++j) {
            cin >> mat[i][j];
            mat[i][j]--;
        }
    }
    for (int j = 0; j < 2; ++j)
        for (int i = j; i < n; i += 2) {
            int x = mat[1][i] / 3;
            if (x % 2 != j) {
                nope();
            }
            if (mat[1][i] != x * 3 + 1) {
                nope();
            }
            if (mat[0][i] / 3 != x || mat[2][i] / 3 != x) {
                nope();
            }
            a[j][i / 2] = x;
            o[j][i / 2] = (mat[0][i] > mat[2][i]);
            cnt[j] ^= o[j][i / 2];
        }
    for (int j = 0; j < 2; ++j) {
        memset(f, 0, sizeof f);
        int res = 0;
        for (int i = 0; i * 2 + j < n; ++i) {
            res ^= (i - query(a[j][i])) & 1;
            update(a[j][i]);
        }
        if (res != cnt[j ^ 1]) nope();
    }
    cout << "Yes" << endl;

}




Measured memory_bytes: 3200
#include <bits/stdc++.h>
using namespace std;
// (setq-default c-basic-offset 2)
int main() {
  string s;
  cin >> s;
  unordered_map<char, int> m;
  for (char& c : s) {
    m[c]++;
  }
  if (m['A'] == 3 or m['B'] == 3)
    cout << "No" << endl;
  else
    cout << "Yes" << endl;
  return 0;
}


Measured memory_bytes: 3592
#include<cstdio>
#include<vector>
#include<queue>
#include<ctime>
#include<algorithm>
#include<cstdlib>
#include<stack>
#include<cstring>
using namespace std;

typedef long long LL;

const int INF = 2147483647;
const int maxn = 1000010;

char s[maxn],t[maxn];
LL L,n,m,sn,sm,lcm;

inline LL getint()
{
	LL ret = 0,f = 1;
	char c = getchar();
	while (c < '0' || c > '9')
	{
		if (c == '-') f = -1;
		c = getchar();
	}
	while (c >= '0' && c <= '9') 
		ret = ret * 10 + c - '0',c = getchar();
	return ret * f;
}

inline LL gcd(LL a,LL b)
{
	return !b ? a : gcd(b,a % b);
}

int main()
{
	#ifdef AMC
		freopen("AMC1.txt","r",stdin);
		// freopen("AMC2.txt","w",stdout);
	#endif
	n = getint(); m = getint();
	scanf("%s",s + 1); scanf("%s",t + 1);
//	n = strlen(s + 1); m = strlen(t + 1);
	
	L = n * m / gcd(n,m);
	sn = L / n; sm = L / m;
//	printf("%lld %lld\n",L,sm);
	
	lcm = sn * sm / gcd(sn,sm); 
	sn = lcm / sn; sm = lcm / sm;
	
//	printf("%lld %lld\n",sn,sm);
	
	int j = 1;
	for (int i = 1; i <= n; i += sn)
	{
		if (s[i] != t[j]) {puts("-1"); return 0;}
		j += sm;
	}
	
	printf("%lld\n",L);
	return 0;
}

Measured memory_bytes: 384
#include <iostream>
#include "bits/stdc++.h"

using namespace std;
#define print(x) cout<<x<<endl;
#define rep(i, a, b) for(ll i=a;i<b;i++)
#define REP(i, a) for(ll i=0;i<a;i++)
#define jkl ll debug = 0;
#define RREP(i, a) for(ll i=a;i>0;i--)
#define rrep(i, a, b) for(ll i=a-1;i>=b;i--)
#define printall(n, array) {for(ll i=0;i<n;i++){cout<<array[i]<<" ";}cout<<endl;}
#define U() cout<<endl;
#define mp make_pair
typedef long long ll;
typedef pair<ll, ll> Pi;
typedef pair<ll, Pi> V;
typedef vector<ll> VE;
typedef vector<vector<ll>> VVE;
const ll mod = 1e9 + 7; //10^9+7

int main () {
    ll a[5];
    ll k;
    REP(i, 5) cin >> a[i];
    cin >> k;
    REP(i, 5) {
        rep(j, i, 5) {
            if(abs(a[i] - a[j]) <= k)continue;
            print(":(");
            return 0;
        }
    }
    print("Yay!");
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
#include <iomanip>
#include <cstring>
#define rep(i, N) for (int i = 0; i < (int)N; i++)
using namespace std;
typedef long long ll;
const ll LLINF = 9223372036854775807;
const int MOD = 1000000007;

int main() {
  int N, K; cin >> N >> K;
  int l[N]; rep(i, N) cin >> l[i];
  sort(l, l+N); reverse(l, l+N);

  int result = 0;
  rep(i, K) result += l[i];
  cout << result << endl;
  return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <cstring>
#include <cstdio>

int u[100005], v[100005];

int fa[100005];
long long size[100005];

inline void init(int n) {
    for (register int i = 0; i <= n; ++i) {
        fa[i] = i;
        size[i] = 1;
    }
}

int find(int x) { return fa[x] == x ? x : find(fa[x]); }

void join(int x, int y) {
    int fax = find(x);
    int fay = find(y);
    if (fax == fay) return;
    if (size[fax] > size[fay]) {
        size[fax] = size[fax] + size[fay];
        size[fay] = size[fax];
        fa[fay] = fax;
    } else {
        size[fay] = size[fax] + size[fay];
        fa[fax] = fay;
        size[fax] = size[fay];
    }
}

long long res[100005];

int main() {
    long long n, m;
    scanf("%lld%lld", &n, &m);
    init(n);
    for (int i = 1; i <= m; ++i) scanf("%d%d", &u[i], &v[i]);
    res[m + 1] = n * (n - 1) / 2;
    for (int i = m; i >= 1; --i) {
        long long s1 = size[find(u[i])];
        long long s2 = size[find(v[i])];
        if (find(u[i]) == find(v[i])) {
            res[i] = res[i + 1];
        } else {
            res[i] = res[i + 1] - s1 * s2;
            join(u[i], v[i]);
        }
    }
    for (int i = 2; i <= m + 1; i++) {
        printf("%lld\n", res[i]);
    }
}


Measured memory_bytes: 4096
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
template <class T> using vec = vector<T>;
template <class T> using vvec = vector<vec<T>>;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N;
    string S;
    cin >> S;
    N = S.size();
    int s = 0;
    for(int i=0;i<N;i++){
        s += S[i]-'0';
    }
    cout << (s%9==0? "Yes\n":"No\n");
}

Measured memory_bytes: 3776
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <queue>
#include <map>
#include <cmath>
#include <numeric>
#include <iomanip>
#include <set>
#include <string.h>

using namespace std;

typedef long long ll;

#define REP(i,n) for(ll (i)=0;(i)<(n);(i)++)
#define REP3(i,st,en) for(ll (i)=(st);(i)<(en);(i)++)

using P = pair<ll, ll>;
const int MOD = 1e9+7;
const ll INF = 1e+14;
const double PI = 3.14159265349;



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

  char c;
  cin >> c;

  cout << (char)(c+1) << "\n";
  return 0;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
#define int ll
#define double long double
#define YES {cout<<"YES"<<'\n';}
#define NO {cout<<"NO"<<'\n';}
#define Yes {cout<<"Yes"<<'\n';}
#define No {cout<<"No"<<'\n';}
#define yes {cout<<"yes"<<'\n';}
#define no {cout<<"no"<<'\n';}
void YN(bool flg){cout<<(flg?"YES":"NO")<<'\n';}
void Yn(bool flg){cout<<(flg?"Yes":"No")<<'\n';}
void yn(bool flg){cout<<(flg?"yes":"no")<<'\n';}
#define SORT(a) sort(a.begin(),a.end())
#define REVERSE(a) reverse(a.begin(),a.end())
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define out(n) {cout << n << '\n';}
typedef vector<int> VI;
typedef vector<string> VS;
typedef vector<bool> VB;
typedef vector<VI> VVI;
const int MOD = 1000000007;
const long long INF = 10e10;
const double PI = acos(-1.0);
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; }
template<class T>auto MAX(const T& a) { return *max_element(a.begin(),a.end()); }
template<class T>auto MIN(const T& a) { return *min_element(a.begin(),a.end()); }
int ABS(int a) {if(a<0) a = -a; return a;}
template<class T, class U>U SUM(const T& a, const U& v) { return accumulate(a.begin(),a.end(), v); }
template<class T, class U>U COUNT(const T& a, const U& v) { return count(a.begin(),a.end(), v); }
template<class T, class U>int LOWER(const T& a, const U& v) { return lower_bound(a.begin(),a.end(), v) - a.begin(); }
template<class T, class U>int UPPER(const T& a, const U& v) { return upper_bound(a.begin(),a.end(), v) - a.begin(); }
int GCD(int a, int b) { return b ? GCD(b, a%b) : a; }
int LCM(int a, int b) { int g = GCD(a, b); return a / g * b; }
int POW(int a, int n) { int r = 1; while (n > 0) { if (n & 1)r *= a; a *= a; n /= 2; }return r; }
int isPrime(int n){if(n<2){return 0;}for(int i=2; i*i<=n; i++){if(n%i==0){return 0;}}return 1;}
/*素因数分解*/map< int, int >prime_factor(int n){map< int, int > ret;for(int i = 2; i * i <= n; i++) {while(n % i == 0) {ret[i]++;n /= i;}}if(n != 1) ret[n] = 1;return ret;}
/*約数の個数*/int divisor_number(int n){auto p = prime_factor(n); int res = 1; for(auto x:p)res*=(x.second+1); return res;}
/*約数列挙*/vector<int> divisor(int n){vector<int> v; for(int i=1; i*i<=n; i++){if(n%i==0){v.push_back(i);if(i!=n/i){v.push_back(n/i);}}}sort(v.begin(),v.end()); return v;}
//----------------ライブラリとか----------------

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

    int a,b; cin >> a >> b;
    printf("%d\n",a%b!=0);

    return 0;
}

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

const long long MOD = 1000000007;
const long long MAX = 2000000;

template <typename T> T gcd(T a, T b) { return b != 0 ? gcd(b, a % b) : a; }

template <typename T> T lcm(T a, T b) { return a * b / gcd(a, b); }



int main() {
	long long N,D;
	cin>>N>>D;
	long long X[N],Y[N];
	long long cnt=0;
	for(int i=0;i<N;i++){
		cin>>X[i]>>Y[i];
		if(sqrt(X[i]*X[i]+Y[i]*Y[i])<=D){
			cnt++;
		}
	}
	cout<<cnt<<endl;


}


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

int main(void)
{
	int n;
	int data[40];
	
	for (int i = 0; i < 40; i++) data[i] = 0;
	data[0] = data[1] = 1;
	data[2] = 2;
	
	for (int i = 3; i <= 30; i++){
		data[i] = (data[i - 1] + data[i - 2] + data[i - 3]);
//		cout << i << " " << data[i] << endl;
	}
	
	while (cin >> n, n){
		cout << ((data[n] / 10) + 365) / 365 << endl;
	}
	
	return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int R, G, B, N;
    cin >> R >> G >> B >> N;

    int ans = 0;
    for (int r = 0; r * R <= N; r++)
    {
        for (int g = 0; r * R + g * G <= N; g++)
        {
            if (0 <= N - r * R - g * G && (N - r * R - g * G) % B == 0)
            {
                ans++;
            }
        }
    }
    cout << ans << endl;
}


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

int main(){
  int N;
  cin >> N;
  int A[N];
  int64_t ans = 0;
  for(int i=0;i<N;i++){
    cin >> A[i];
    A[i] -=  i;
  }
  sort(A, A+N);
  int M = A[N/2];
  for(int i=0;i<N;i++){
    ans += abs(A[i]-M);
  }
  cout << ans << endl;
}

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

using namespace std;

#define size(x) ((int) x.size())

const int MAXN = 2e5 + 5;

string s;

vector <int> adj[MAXN];

bool mark[MAXN];

int n, m;
int u, v;
int deg_a[MAXN];
int deg_b[MAXN];
int cnt;

queue <int> Q;

int main() {
	ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
	cin >> n >> m >> s;
	for (int i = 0; i < m; i++) {
		cin >> u >> v;
		u--, v--;
		adj[u].push_back(v);
		adj[v].push_back(u);
		/*if (s[u] == 'A')
			deg_a[v]++;
		else
			deg_b[u]++;
		if (s[v] == 'A')
			deg_a[u]++;
		else
			deg_b[u]++;*/
		(s[u] == 'A' ? deg_a[v]++ : deg_b[v]++);
		(s[v] == 'A' ? deg_a[u]++ : deg_b[u]++);
	}
//	for (int i = 0; i < n; i++) 
//		cout << i << " : " << deg_a[i] << " " << deg_b[i] << endl;
	cnt = n;
	for (int i = 0; i < n; i++) 
		if (!deg_a[i] || !deg_b[i]) {
			Q.push(i);
			mark[i] = true;
		}
	while (!Q.empty()) {
		int u = Q.front();
		Q.pop();
		cnt--;
		for (int i = 0; i < size(adj[u]); i++) {
			int v = adj[u][i];
			(s[u] == 'A') ? deg_a[v]-- : deg_b[v]--;
			if ((!deg_a[v] || !deg_b[v]) && !mark[v]) {
				Q.push(v);
				mark[v] = true;
			}
		}
	}
	if (cnt)
		cout << "Yes";
	else
		cout << "No";
	cout << endl;
	return 0;
}

Measured memory_bytes: 12624
#include <bits/stdc++.h>
  
using namespace std;
  
#define rep(i,n) REP(i,0,n)
#define REP(i,s,e) for(int i=(s); i<(int)(e); i++)
#define repr(i, n) REPR(i, n, 0)
#define REPR(i, s, e) for(int i=(int)(s-1); i>=(int)(e); i--)
#define pb push_back
#define all(r) (r).begin(),(r).end()
#define rall(r) (r).rbegin(),(r).rend()
#define fi first
#define se second
  
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
 
const int INF = 1e9;
const ll MOD = 1e9 + 7;
double EPS = 1e-8;

int main(){
#ifdef LOCAL_TEST
    freopen("in", "r", stdin);
    freopen("out", "w", stdout);
#endif
    string s;
    cin >> s;
    string t;
    vi idx;
    rep(i, s.size()) if(s[i] != 'x') t += s[i], idx.pb(i);
    if(t.size() == 0) {
        cout << 0 << endl;
        return 0;
    }
    bool f = true;
    rep(i, t.size()) if(t[i] != t[t.size() - i -1]) f = false;
    if(!f) {
        cout << -1 << endl;
        return 0;
    }
    int cnt = 0;
    int a, b;
    if(t.size()&1) {
        a = idx[t.size()/2], b = idx[t.size()/2];
    }
    else {
        a = idx[t.size()/2-1], b = idx[t.size()/2];
    }
    while(a >= 0 || b <= s.size()-1) {
        if(s[a] == s[b]) {
            a--;
            b++;
        }
        else if(s[a] == 'x') {
            cnt++;
            a--;
        }
        else {
            cnt++;
            b++;
        }
    }
    cout << cnt << endl;
    return 0;
}

Measured memory_bytes: 1148
#include <bits/stdc++.h>
using namespace std;
using i64 = long long;
#define rep(i,s,e) for(int (i) = (s);(i) <= (e);(i)++)
#define all(x) x.begin(),x.end()

int main() {
  int N,H,W;
  cin >> N >> H >> W;
  cout << (N - H + 1) * (N - W + 1) << endl;
}


Measured memory_bytes: 256
import java.util.Scanner;
public class Main {
	public static void main(String[] args){
		Scanner as = new Scanner(System.in);
		//int n = Integer.parseInt(as.next());
		int a = Integer.parseInt(as.next());
		int b = Integer.parseInt(as.next());
		int c = (int)Math.ceil(a*12.5);
		int d = (int)((a+1)*12.5);
		int e = b * 10;
		int f = (b+1)*10;
		if(c<f&&e<d){
			System.out.println(Math.max(c,e));
		}else{
			System.out.println("-1");
		}
	}
}

Measured memory_bytes: 23764
#include <iostream>
#include <vector>
#include <algorithm>
#include <math.h>
#include <string>
#include <deque>
#include <tuple>
#include <map> 
#include <set>
#include <stack>
#include <functional>
#define ll long long
using namespace std;

int main() {

	int a;
	cin >> a;

	cout << a + a * a + a * a*a << endl;
}

Measured memory_bytes: 3600
/**
 *   author: Shubham Srivastava
 *   created: 12 January 2020  17:58:50
**/
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
vector <pair<ll,ll> > node[100000];
vector <ll> height(100000,-1);
vector <ll> vis(100000,0);
ll ans = 0;
void bfs(ll a, ll n) {
        vector <ll> dist(n+1,INT_MAX);
        vector <bool> vis(n+1,false);
        dist[a] = 0;
        priority_queue <pair<ll,ll>, vector <pair<ll,ll> >, greater <pair<ll,ll> > > pq;
        pq.push({0,a});
        while(!pq.empty()){
            auto tp = pq.top();
            pq.pop();
            if(vis[tp.second])
                continue;
            vis[tp.second] = true;
            for(auto i : node[tp.second]){
                if(dist[tp.second] + i.second < dist[i.first]){
                    dist[i.first] = dist[tp.second] + i.second;
                    pq.push({dist[i.first],i.first});
                }
            }
        }
        for(ll i = 0;i<n;i++){
        	if(dist[i] != INT_MAX)
        		ans = max(ans,dist[i]);
        }
}
 
int main(){
    ios_base::sync_with_stdio(false); 
    cin.tie(NULL);
    ll n,m;cin>>n>>m;
    vector <string> gp;
    for(ll i=0;i<n;i++){
    	string s;cin>>s;
    	gp.push_back(s);
    }
    for(ll i=0;i<n;i++){
    	for(ll j=0;j<m;j++){
    		if(gp[i][j] == '.'){
    			if(i+1 < n && gp[i+1][j] == '.')
    				node[i*m+j].push_back({(i+1)*m+j,1});
    			if(j+1 < m && gp[i][j+1] == '.')
    				node[i*m+j].push_back({i*m+j+1,1});
    			if(i-1 >= 0 && gp[i-1][j] == '.')
    				node[i*m+j].push_back({(i-1)*m+j,1});
    			if(j-1 >= 0 && gp[i][j-1] == '.')
    				node[i*m+j].push_back({i*m+j-1,1});
    		}
    	}
    }
    bool flag = 0;
    ll index;
    for(ll i=0;i<n;i++){
    	for(ll j=0;j<m;j++){
    		if(gp[i][j] == '.'){
    			bfs(i*m+j,n*m);
    		}
    	}
    }
    cout<<ans;
return 0;
}

Measured memory_bytes: 4224
sx,sy,tx,ty = map(int,input().split())
ans = ''
ans += 'U'*(ty-sy)+'R'*(tx-sx)+'D'*(ty-sy)+'L'*(tx-sx+1)+'U'*(ty-sy+1)+'R'*(tx-sx+1)+'DR'+'D'*(ty-sy+1)+'L'*(tx-sx+1)+'U'
print(ans)

Measured memory_bytes: 3060
#include <cstdio>
#include <algorithm>    
#include <iostream>
#include <vector>
#include <queue>
// #include <map>
#include <iomanip>
#include <cstring>
#include <cmath>
#define all(x) (x).begin(),(x).end()
using namespace std;
typedef long long LL;
typedef long double LD;
typedef unsigned int uii;
typedef pair<int,int> pii;
typedef unsigned long long uLL; 
typedef vector<int> vii; 

const int maxn = 3333;
LL d[maxn][maxn], vis[maxn][maxn], a[maxn];

LL dp(int L, int R, int h){
	if(vis[L][R]) return d[L][R];
	vis[L][R] = 1;
	if(L == R){
		return d[L][R] = h * a[L];
	}
	if(h == 1){ 
		d[L][R] = max(dp(L + 1, R, -h) + h * a[L], dp(L, R - 1, -h) + h * a[R]);
	} else {
		d[L][R] = min(dp(L + 1, R, -h) + h * a[L], dp(L, R - 1, -h) + h * a[R]);
	}
	return d[L][R];
}

int main(int argc, char const *argv[])
{
#ifndef ONLINE_JUDGE
	// freopen("in.txt", "r", stdin);
	// freopen("out.txt", "w", stdout);
#endif
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n;
	cin >> n;
	for(int i = 1; i <= n; ++i){
		cin >> a[i];
	}
	dp(1, n, 1);
	cout << d[1][n] << endl;
	return 0;
}

Measured memory_bytes: 160256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int N;
  cin >> N;
  int x[N], y[N];
  for (int i = 0; i < N; i++) {
    cin >> x[i] >> y[i];
  }
  if (N == 1) {
    cout << "1\n";
    return 0;
  }
  int ans = N;
  for (int i = 0; i < N - 1; i++) {
    for (int j = 0; j < N; j++) {
      if (i == j) continue;
      int p = x[i] - x[j];
      int q = y[i] - y[j];
      int cnt = 0;
      for (int k = 0; k < N; k++) {
        for (int l = 0; l < N; l++) {
          if (k == l) continue;
          if (x[k] - x[l] == p && y[k] - y[l] == q) {
            cnt++;
          }
        } 
      }
      ans = min(ans, N - cnt);
    }
  }
  cout << ans << "\n";
  return 0;
}

Measured memory_bytes: 384
var  a,b,c,d:longint;
     s:string;
begin
  readln(s);
  a:=ord(s[1])-ord('0');
  b:=ord(s[2])-ord('0');
  c:=ord(s[3])-ord('0');
  d:=ord(s[4])-ord('0');
  if  a+b+c+d=7  then    begin  writeln(a,'+',b,'+',c,'+',d,'=7');  exit;  end;
  if  a+b+c-d=7  then    begin  writeln(a,'+',b,'+',c,'-',d,'=7');  exit;  end;
  if  a+b-c+d=7  then    begin  writeln(a,'+',b,'-',c,'+',d,'=7');  exit;  end;
  if  a-b+c+d=7  then    begin  writeln(a,'-',b,'+',c,'+',d,'=7');  exit;  end;
  if  a-b-c+d=7  then    begin  writeln(a,'-',b,'-',c,'+',d,'=7');  exit;  end;
  if  a-b+c-d=7  then    begin  writeln(a,'-',b,'+',c,'-',d,'=7');  exit;  end;
  if  a+b-c-d=7  then    begin  writeln(a,'+',b,'-',c,'-',d,'=7');  exit;  end;
  if  a-b-c-d=7  then    begin  writeln(a,'-',b,'-',c,'-',d,'=7');  exit;  end;
end.

Measured memory_bytes: 128
#include <iostream>
#include <string>
#include <vector>
#include <cmath>
using namespace std;

int main(){
    
    int i, N, K;
    cin >> N >> K;
    
    vector<int> p(N, 0);
    
    for (i = 0; i < N; i++){
        cin >> p[i];
    }
    
    sort(p.begin(), p.end());
    
    int ans = 0;
    
    for (i = 0; i < K; i++){
        
        ans += p[i];
    }
    
    cout << ans << "\n";
    
    return 0;
}


Measured memory_bytes: 3172
l = gets.to_i
list = []
status = []
no = 1
gets.chomp.split.map(&:to_i).each{|cat|
    ng = false
    if cat > 0
        ng = true if status[cat]
        status[cat] = true
        list.push cat
    else
        cat = -cat
        ng = true if !status[cat]
        status[cat] = false
        ng = true if cat != list.pop
    end
    break if ng
    no += 1
}
puts (no > l ? "OK" : no)


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

int main(){
  int A, B, x, t, i, m, n;
  t = 0;

  cin >> A >> B;
  x = B - A + 1;
  for(i = 0; i < x; i++){
    m = A/10000;
  	if(m==A%10 && ((A-m*10000)/1000)==(A%100/10)){
      t++;
    }
    A++;
  }

  cout << t << endl;
}

Measured memory_bytes: 256
#include<stdio.h>

int main (void){
	
	int array[4][13]={},n,i,num,mark2;
	char mark;
	scanf("%d\n",&n);
	for(i=0;i<n;i++){
	scanf("%c %d",&mark,&num);
	getchar();
	if(mark == 'S'){
		array[0][num-1] = 1;
	}else if(mark == 'H'){
		array[1][num-1] = 1;
	}else if(mark == 'C'){
		array[2][num-1] = 1;
	}else if(mark == 'D'){
		array[3][num-1] = 1;
	}
	}
	
	for(mark2=0;mark2<4;mark2++){
		for(num=0;num<13;num++){
			if(array[mark2][num] != 1){
				if(mark2 == 0){
				printf("S %d\n",num+1);
				}else if(mark2 == 1){
				printf("H %d\n",num+1);
				}else if(mark2 == 2){
				printf("C %d\n",num+1);
				}else if(mark2 == 3){	
				printf("D %d\n",num+1);
				}
			}
		}
	}
	
	return 0;
}

Measured memory_bytes: 600
N = int(input())
A1 = list(map(int, input().split()))
A2 = list(map(int, input().split()))

# どのタイミングで↓に行くか
from itertools import accumulate
acc1 = list(accumulate(A1))
acc2 = list(accumulate([0]+A2))

ans = 0
for i in range(N):

    x1 = acc1[i]
    x2 = acc2[-1]-acc2[i]
    ans = max(ans,x1+x2)

print(ans)

Measured memory_bytes: 3188
import sys
s = list(input())

for i, string in enumerate(s):
    if s[:7] == list("keyence"):
        print("YES")
        sys.exit()

    if s[i] != "keyence"[i]:
        for j in range(len(s)-i):
            if s[i+j] == "keyence"[i]:
                if s[:i]+s[i+j:] == list("keyence"):
                    print("YES")
                    sys.exit()
        break

print("NO")

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<(b);++i)
#define erep(i,a,b) for(int i=a;i<=(int)(b);++i)
#define per(i,a,b) for(int i=(b);i>(a);--i)
#define eper(i,a,b) for(int i=((int)(a));i>=b;--i)
#define pb push_back
#define mp make_pair
#define INF 2000000000
#define MOD 1000000007
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
int dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0};
int gcd(int a,int b){return b?gcd(b,a%b):a;}
int lcm(int a,int b){return a/gcd(a, b)*b;}

int a, b, c;
int main() {
 ios::sync_with_stdio ( false );
 cin.tie ( 0 );
    cin >> a >> b >> c;
    int dis1 = abs(c-a), dis2 = abs(b-a), dis3 = abs(b-c);
    int ans = min(dis1+dis2, dis2+dis3); ans = min(ans, dis3+dis1);
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
N, K = map(int, input().split())
X = [int(x) for x in input().split()]

md = 10**10
for i in range(N - K + 1):
    xl, xr = X[i], X[i + K - 1]
    if xl >= 0:
        d = xr
    elif xr <= 0:
        d = -xl
    else:
        d = min(-xl, xr) * 2 + max(-xl, xr)

    if d < md:
        md = d
print(md)


Measured memory_bytes: 14228
#include <cstdio>

int time[5];

int main()
{
    for (int i = 0; i < 5; i++) {
        scanf("%d", &time[i]);
    }
    int answer = 0;
    int last_dish = 0;
    for (int i = 0; i < 5; i++) {
        if (time[i] % 10 < time[last_dish] % 10 && time[i] % 10 != 0) {
            last_dish = i;
        }
    }
    for (int i = 0; i < 5; i++) {
        if (i == last_dish) {
            answer += time[i];
        } else if (time[i] % 10 == 0) {
            answer += time[i];
        } else {
            answer += time[i] / 10 * 10 + 10;
        }
    }
    printf("%d\n", answer);
}


Measured memory_bytes: 128
def solve():
    N, M = [int(i) for i in input().split()]
    ans = set()
    pen = 0
    arr = [0] * N
    for _ in range(M):
        p, s = input().split()
        if s == 'AC' and int(p) not in ans:
            ans.add(int(p))
            pen += arr[int(p) - 1]
        if s == 'WA':
            arr[int(p) - 1] += 1
    print(f'{len(ans)} {pen}')

if __name__ == "__main__":
    solve()

Measured memory_bytes: 87796
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
typedef long long ll;
typedef pair<int, int> P;
const int INF = 100100100;
const int MOD = (int)1e9 + 7;
const double EPS = 1e-9;
int main() {
  ll A, B, C, X, Y;
  cin >> A >> B >> C >> X >> Y;
  ll mn = 10e10;
  REP(i, 300000) {
    ll num = 0;
    num += C * i;
    if (i / 2 < X) {
      num += (X - i / 2) * A;
    }
    if (i / 2 < Y) {
      num += (Y - i / 2) * B;
    }
    mn = min(num, mn);
  }
  cout << mn << endl;
}

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

vector<ll> graph[200000];
vector<ll> root;
vector<bool> flag;
vector<ll> ans;
ll n,q;

void input()
{
  cin >> n >> q;
  for (ll i = 0; i < n-1; i++)
  {
    ll a,b;
    cin >> a >> b;
    graph[a-1].push_back(b-1);
    graph[b-1].push_back(a-1);
  }
  rep(n)
  {
    root.push_back(0);
    flag.push_back(0);
    ans.push_back(0);
  }
  for (ll i = 0; i < q; i++)
  {
    ll p,x;
    cin >> p >> x;
    root[p-1] += x;
  }
}

void dfs(ll s, ll sum)
{
  sum += root[s];
  ans[s] = sum;
  flag[s] = 1;
  if(!graph[s].empty())
  {
    vector<ll>::iterator itr;
    for(itr=graph[s].begin(); itr!=graph[s].end(); itr++)
    {
      if(flag[*itr]==0)
      {
        dfs(*itr,sum);
      }
    }
  }
}

int main()
{
  input();
  dfs(0,0);
  rep(n)
  {
    cout << ans[i] << " ";
  }
  cout << endl;
  return 0;
}

Measured memory_bytes: 25952
#include <algorithm>
#include <vector>
#include <array>
#include <set>
#include <map>
#include <cmath>
#include <iostream>
#include <iomanip>
#include <numeric>
#include <fstream>
#include <math.h>

using namespace std;

int main(void)
{
	int N, T;
	cin >> N >> T;
	int last_t = 0;
	int sum = 0;
	for (int i = 0; i < N; i++) {
		int t;
		cin >> t;
		if (t-last_t > T)
			sum += T;
		else
			sum += t-last_t;
		last_t = t;

	}
	sum += T;
	cout << sum << endl;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vll>;
using vc = vector<char>;
using vvc = vector<vc>;
using pll = pair<ll, ll>;
using stkll = vector<pll>;
const ll INF = 1LL << 60;
const ll MOD = 1e9 + 7;
#define rep(i, n) for (ll i = 0; i < (n); i++)
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}
#ifndef ONLINE_JUDGE
    #define debug(x) cerr << #x << ": " << x << endl;
#else
    #define debug(x)
#endif

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

    ll N;
    string S;
    cin >> N >> S;

    vll vr, vg, vb;
    rep(i, N) {
        if(S[i] == 'R') vr.push_back(i);
        if(S[i] == 'G') vg.push_back(i);
        if(S[i] == 'B') vb.push_back(i);
    }


    ll ans = 0;
    for(ll j = 1; j < N-1; j++) {
        if(S[j] == 'R') {
            ll left = vg.end() - lower_bound(vg.begin(), vg.end(), j);
            ll right = lower_bound(vb.begin(), vb.end(), j) - vb.begin();
            ans += left * right;
            left = vb.end() - lower_bound(vb.begin(), vb.end(), j);
            right = lower_bound(vg.begin(), vg.end(), j) - vg.begin();
            ans += left * right;
        }
        if(S[j] == 'G') {
            ll left = vr.end() - lower_bound(vr.begin(), vr.end(), j);
            ll right = lower_bound(vb.begin(), vb.end(), j) - vb.begin();
            ans += left * right;
            left = vb.end() - lower_bound(vb.begin(), vb.end(), j);
            right = lower_bound(vr.begin(), vr.end(), j) - vr.begin();
            ans += left * right;
        }
        if(S[j] == 'B') {
            ll left = vg.end() - lower_bound(vg.begin(), vg.end(), j);
            ll right = lower_bound(vr.begin(), vr.end(), j) - vr.begin();
            ans += left * right;
            left = vr.end() - lower_bound(vr.begin(), vr.end(), j);
            right = lower_bound(vg.begin(), vg.end(), j) - vg.begin();
            ans += left * right;
        }

        for(ll len = 1; j + len <= N-1; len++) {
            if(j - len < 0) continue;
            if(S[j-len] != S[j] && S[j-len] != S[j+len] && S[j] != S[j+len]) ans--;
        }
    }    
    cout << ans << endl;
}


Measured memory_bytes: 3724
#define _USE_MATH_DEFINES

#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <cmath>
#include <cstring>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>

using namespace std;

typedef pair<long long int, long long int> P;
typedef tuple<int, int, int> T;

long long int INF = 1e18;
long long int MOD = 1e9 + 7;

vector<int> E[110000];

int maxD[110000] = {}, vCol[110000] = {};

void func(int pos, int d, int col){
    if(maxD[pos] >= d){
        return;
    }
    if(maxD[pos] == 0){
        vCol[pos] = col;
    }
    maxD[pos] = d;
    for(int to : E[pos]){
        func(to, d - 1, col);
    }
}

int main(){
    int N, M, Q;
    cin >> N >> M;
    for(int i = 0; i < M; i++){
        int a, b;
        cin >> a >> b;
        E[a].push_back(b);
        E[b].push_back(a);
    }
    cin >> Q;
    vector<T> v;
    for(int i = 0; i < Q; i++){
        int x, d, c;
        cin >> x >> d >> c;
        v.push_back(T(x, d + 1, c));
    }
    reverse(v.begin(), v.end());
    for(T t : v){
        func(get<0>(t), get<1>(t), get<2>(t));
    }
    for(int i = 1; i <= N; i++){
        cout << vCol[i] << endl;
    }
    return 0;
}

Measured memory_bytes: 9072
from math import ceil

def is_ok(m):

    tmp = h[:]

    for i in range(N):
        tmp[i] -= m*B
    
    flag = True

    for i in tmp:
        if i > 0:
            flag = False
            break

    if flag:##全部0以下
        return True
    else:
        rem = 0
        for i in tmp:
            if i > 0:
                rem += ceil(i/(A-B))

        if rem > m:
            return False

        return True

N,A,B = map(int,input().split())
h = list(int(input()) for _ in range(N))
s = sum(h)
##二分散策

r = 10**10
l = 0

while abs(l-r) > 1:

    m = (r+l)//2

    if is_ok(m):
        r = m
    else:
        l = m

print(r)

Measured memory_bytes: 18340
import java.util.*;

class Main{
  public static void main(String[] args){
    Scanner sc=new Scanner(System.in);
    int n=sc.nextInt();
    int[] h=new int[n];
    for(int i=0;i<n;i++){
      h[i]=sc.nextInt();
    }
    int hg=-1;
    int cn=0;
    for(int i=0;i<n;i++){
      if(hg<=h[i]){
        cn++;
        hg=h[i];
      }
    }
    System.out.println(cn);
  }
}

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

int main(){

    int h1,m1,h2,m2,k;
    cin>>h1>>m1>>h2>>m2>>k;

    int ans = (h2*60+m2) - (h1*60+m1) - k;

    cout<<ans;

    return 0;
}

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

using namespace std;

int calc (int x) {
    int ans = 1;
    while (x > 0) {
        ans *= (x % 10);
        if (x % 10 < 2) return 0;
        x /= 10;
    }

    return ans;
}

int main(){
    ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
    int m, d;
    cin >> m >> d;

    int ans = 0;
    for (int i = 1; i <= m; i++) {
        for (int j = 10; j <= d; j++) {
            if (calc(j) == i) {
                ans++;
                //cout << i << " " << j << "\n";
            }
        }
    }

    cout << ans;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int a[105];
long long n,cnt;
int main()
{
	string s,r="MARCH";
	scanf("%d",&n);
	for(int i=0;i<n;i++)
	{
		cin>>s;
		a[s[0]]++;
	}
	for(int i=0;i<3;i++)
	{
		for(int j=i+1;j<4;j++)
		{
			for(int k=j+1;k<5;k++)
			{
				cnt+=1ll*a[r[i]]*a[r[j]]*a[r[k]];	
			}	
		}	
	} 
	printf("%lld",cnt);
	return 0;
}

Measured memory_bytes: 256
from sys import exit

N, M = [int(x) for x in input().split()]

result = [-1] * N

for i in range(1, M + 1):
    s, c = [int(x) for x in input().split()]

    if s == 1 and c == 0 and N != 1:
        print(-1)
        exit()

    if result[s-1] != -1 and result[s-1] != c:
        print(-1)
        exit()

    result[s - 1] = c

if result[0] == -1:
    if len(result) > 1:
        result[0] = 1
    else:
        print(0)
        exit()

print(''.join([str(x) if x != -1 else str(0) for x in result]))


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

MOD = 10**9+7

def fact(a,MOD):
    x = 1
    ans = 1
    for i in range(a):
        ans = (ans * x)%MOD
        x += 1
    return ans

def comb(a,b,MOD):
    max = (a-b,b-a)
    return fact(a,MOD) * pow(fact(b,MOD),MOD-2,MOD) * pow(fact(max,MOD),MOD-2,MOD)
  
if abs(N-M) > 1:
    print(0)
elif abs(N-M) == 1:
    print((fact(N,MOD)*fact(M,MOD))%MOD)
else:
    print((fact(N,MOD)*fact(M,MOD)*2)%MOD)  

Measured memory_bytes: 3064
#include <iostream>
#include <vector>
#include <list>
#include <set>
#include <queue>
#include <map>
#include <algorithm>
#include <functional>
#include <string>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <tuple>
using namespace std;

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

using ll = long long int;
using pll = pair<ll, ll>;

int main()
{
    ll X;
    cin >> X;

    cout << 8 - ((X - 400) / 200) << endl;

    return 0;
}


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

int main(){
    int n,h[6] = {0};
    float temp;
    cin>>n;
    
    for(int i=0;i<n;i++){
        cin>>temp;

        if(temp < 165.0) h[0]++;
        else if(temp < 170.0) h[1]++;
        else if(temp < 175.0) h[2]++;
        else if(temp < 180.0) h[3]++;
        else if(temp < 185.0) h[4]++;
        else h[5]++;
    }

    for(int i=0;i<6;i++){
        cout<<i+1<<":";
        for(int j=0;j<h[i];j++)
            cout<<"*";
        cout<<endl;
    }

    return 0;
}

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

int main(void){
  int n,m,c;
  int ans=0;
  int count=0;
  cin >> n >> m >> c;
  int a[n][m];
  vector<int> b(m);
  for(int i=0;i<m;i++){
    cin >> b[i];
  }
  for(int i=0;i<n;i++){
    ans=0;
    for(int j=0;j<m;j++){
      cin >> a[i][j];
      ans+=a[i][j]*b[j];
    }
    if(ans+c>0) count++;
  }
  cout << count;
  return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <complex>
#include <string>
#include <sstream>
#include <algorithm>
#include <numeric>
#include <vector>
#include <queue>
#include <stack>
#include <functional>
#include <iostream>
#include <map>
#include <set>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 1000000000
#define sz(x) ((int)(x).size())
#define sq(x) ((x)*(x))
#define fi first
#define sec second
#define SORT(x) sort((x).begin(),(x).end())
#define all(x) (x).begin(),(x).end()
#define rep(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define repn(i,a,n) for(int (i)=(a);(i)<(int)(n);(i)++)
#define EQ(a,b) (abs((a)-(b))<eps)
double add(double a,double b){
    if(abs(a+b)<eps*(abs(a)+abs(b)))return 0;
    return a+b;
}
struct P{
    double x,y;
    P() {}
    P(double x,double y) : x(x),y(y){}
    P operator + (P p){
        return P(add(x,p.x),add(y,p.y));
    }
    P operator - (P p){
        return P(add(x,-p.x),add(y,-p.y));
    }
    P operator * (double d){
        return P(x*d,y*d);
    }
    double dot(P p){
        return add(x*p.x,y*p.y);
    }
    double det(P p){
        return add(x*p.y,-y*p.x);
    }
    double norm(){
        return sqrt(x*x+y*y);
    }
    double dist2(P p){
        return sq(x-p.x)+sq(y-p.y);
    }
    P vert(){
        return P(-y,x);
    }
    void dump(){
        printf("%.12f %.12f\n",x,y);
        return;
    }
};
vector<P> ans;
int max_depth;
void rec(P l,P r,int d){
    P diff = r-l;
    P a = l+diff*(1.0/3.0);
    P b = l+diff*0.5+(diff.vert())*(sqrt(3)/6);
    P c = l+diff*(2.0/3.0);
    if(d==max_depth){
        ans.pb(l);
        ans.pb(a);
        ans.pb(b);
        ans.pb(c);
        return;
    }
    rec(l,a,d+1);
    rec(a,b,d+1);
    rec(b,c,d+1);
    rec(c,r,d+1);
}
int main(){
    cin >> max_depth;
    P l = P(0.0,0.0);
    P r = P(100.0,0.0);
    if(max_depth>0)rec(l,r,1);
    else ans.pb(l);
    ans.pb(r);
    for(int i=0;i<ans.size();i++){
        ans[i].dump();
    }
    return 0;
}

Measured memory_bytes: 3188
#include<stdio.h>
#define MAX 25

void depth(int, int);
int height(int);
int sibling(int);

typedef struct{
  int p;
  int l; //left
  int r; //right
}Tree;
Tree A[MAX];

int n,B[10000],C[10000];

int main(){
  int root,deg;
  int id,l,r;
  int i,j;
  int N;

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

  for(i=0;i<N;i++){
    scanf("%d%d%d",&id,&l,&r);
    A[id].l=l;
    A[id].r=r;
    if(l!=-1) A[l].p=id;
    if(r!=-1) A[r].p=id;
  }
  for(i=0;i<N;i++){
    if(A[i].p==-1) root=i;
  }

  depth(root,0);
  height(root);

  for(i=0; i<N; i++){
    printf("node %d: ", i);
    printf("parent = %d, ", A[i].p);
    printf("sibling = %d, ",sibling(i));
    deg=0;
    if(A[i].l!=-1) deg++;
    if(A[i].r!=-1) deg++;
    printf("degree = %d, ", deg);
    printf("depth = %d, ", B[i]);
    printf("height = %d, ", C[i]);

    if(A[i].p==-1) printf("root\n");
    else if(A[i].l==-1 && A[i].r==-1) printf("leaf\n");
    else printf("internal node\n");
  }
  
  return 0;
}

void depth(int i, int j){
  if(i==-1) return;
  B[i]=j;
  depth(A[i].l,j+1);
  depth(A[i].r,j+1);
}

int height(int i){
  int a1=0,a2=0;
  if(A[i].l!=-1) a1=height(A[i].l) +1;
  if(A[i].r!=-1) a2=height(A[i].r) +1;
  return C[i]=(a1>a2 ? a1:a2);
}

int sibling(int i){
  if(A[i].p == -1) return -1;
  if(A[A[i].p].l!=i && A[A[i].p].l!=-1) return A[A[i].p].l;
  if(A[A[i].p].r!=i && A[A[i].p].r!=-1) return A[A[i].p].r;
  return -1;
}




Measured memory_bytes: 2148
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)

import itertools
from math import sqrt

n = int(readline())
xy = [list(map(int, readline().split())) for i in range(n)]
memo = [i for i in range(n)]
z = list(itertools.permutations(memo))
ans = 0
for i in range(len(z)):
    for j in range(n - 1):
        ans += sqrt((xy[z[i][j]][0] - xy[z[i][j + 1]][0]) ** 2 + (xy[z[i][j]][1] - xy[z[i][j + 1]][1]) ** 2)
print(ans / len(z))


Measured memory_bytes: 7972
#include<iostream>
#include<vector>
#include<iterator>
#include<algorithm>

int main() {

	int n;
	std::cin >> n;

	std::vector<std::vector<int>> g(n,std::vector<int>(n,0));

	for (int i{}; i < n; ++i) {
		int u, k;
		std::cin >> u >> k;
		for (int ki{}; ki < k; ++ki) {
			int vi;
			std::cin >> vi;
			g[u - 1][vi - 1] = 1;
		}
	}

	if(n>1)
	for (const auto&e : g) {
		std::copy(
			std::begin(e)
			, std::prev(std::end(e))
			, std::ostream_iterator< const std::decay_t<decltype(e)>::value_type &>{std::cout, " "}
		);
		std::cout << *( std::end(e)-1 ) << "\n";
	}
	else
		for (const auto&e : g) {
			for (const auto&ee : e)
				std::cout << ee << "\n";
		}

	return 0;
}


Measured memory_bytes: 3168
import math
N = int(input())
A = sorted(list(map(int, input().split())))

left = 0
right = N
for i in range(int(math.log(N, 2)) + 10):
    center = (left + right) // 2
    B = A[:center] + A[center+1:]
    slime = A[center]

    for b in B:
        if 2*slime >= b:
            slime += b
        else:
            left = center
            break
    else:
        right = center

print(N - right)

Measured memory_bytes: 15020
#include <stdio.h>
int main(void) {
	int n, i, c;
	int p[100];
	scanf("%d", &n);
	for (i = 0; i < n; i++) {
		scanf("%d", &p[i]);
	}
	c = 0;
	for (i = 1; i < n - 1; i++) {
		if (p[i] > p[i - 1] && p[i] < p[i + 1]) {
			c = c + 1;
		}
		else if (p[i] < p[i - 1] && p[i] > p[i + 1]) {
			c = c + 1;
		}
	}
	printf("%d", c);

	return 0;
}

Measured memory_bytes: 128
import java.util.*;

public class Main {
    public static void main (String[] args) {
        Scanner scanner = new Scanner(System.in);
        
        StringBuilder str = new StringBuilder();
        while (scanner.hasNext()) {
            String s = scanner.nextLine();
            str.append(s.toUpperCase());
            str.append("\n");
        }
        System.out.print(str);
    }
}

Measured memory_bytes: 17124
#include <bits/stdc++.h>
using namespace std;
int intinput() {
	int x;
	cin >> x;
	return x;
}
vector<int> forintinput(int n) {
	vector<int> x(200000);
	for(int i = 0;i < n;i++) cin >> x[i];
	return x;
}
int main(){
	int n;
	cin >> n;
	vector<int> a(n);
	a = forintinput(n);
	int Max = 0;
	long long cnt = 0;
	for(int i = 0;i < n;i++){
		if(a[i] > Max){
			Max = a[i];
		}
		if(a[i] < Max){
			cnt += (Max-a[i]);
		}
	}
	cout << cnt << endl;
}

Measured memory_bytes: 4756