akhauriyash/Code-Regression huggingface dataset:
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <string>
#include <cmath>
#include <stack>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <list>
#include <iostream>
#include <sstream>
#include <climits>
#include <cfloat>
#include <complex>


typedef long long ll;
const double Eps = 1e-4;

using namespace std;

typedef complex<double> Point;

double dot(const Point& a, const Point& b)
{
	return a.real()*b.real() + a.imag()*b.imag();
}
double cross(const Point& a, const Point& b)
{
	return a.real()*b.imag() - a.imag()*b.real();
}
double distance_line_point(const Point& point, const Point& a, const Point& b)
{
	return abs(cross(a-b, point-b) / (a-b));
}
double distance_linesegment_point(const Point& point, const Point& a, const Point& b)
{
	if (dot(b-a, point-a) < 0)
		return abs(a-point);
	else if (dot(a-b, point-b) < 0)
		return abs(b-point);
	else
		return distance_line_point(point, a, b);
}
bool is_in_triangle(const Point& point, const Point* triangle)
{
	double t[3];
	for (int i = 0; i < 3; ++i)
		t[i] = cross(triangle[(i+1)%3] - triangle[i], point - triangle[i]);
	return t[0] >= 0 && t[1] >= 0 && t[2] >= 0
		|| t[0] <= 0 && t[1] <= 0 && t[2] <= 0;
}
bool is_in_triangle(const Point& point, const Point& a, const Point& b, const Point& c)
{
	Point t[3] = { a, b, c };
	return is_in_triangle(point, t);
}
bool is_circle_in_triangle(const Point& center, double radius, const Point* triangle)
{
	if (!is_in_triangle(center, triangle))
		return false;
	for (int i = 0; i < 3; ++i)
		if (distance_line_point(center, triangle[i], triangle[(i+1)%3]) < radius - Eps)
			return false;
	return true;
}
bool is_triangle_in_circle(const Point* triangle, const Point& center, double radius)
{
	for (int i = 0; i < 3; ++i)
		if (abs(triangle[i]-center) > radius + Eps)
			return false;
	return true;
}
bool interect_triangle_circle(const Point* triangle, const Point& center, double radius)
{
	for (int i = 0; i < 3; ++i)
		if (distance_linesegment_point(center, triangle[i], triangle[(i+1)%3]) < radius + Eps)
			return true;
	return false;
}

int main()
{
	int x[4], y[4], r;
	while (true)
	{
		for (int i = 0; i < 4; ++i)
			scanf("%d %d", x+i, y+i);
		scanf("%d", &r);
		if (x[0] == 0 && y[0] == 0)
			break;
		Point p[4];
		for (int i = 0; i < 4; ++i)
			p[i] = Point(x[i], y[i]);

		if (is_circle_in_triangle(p[3], r, p))
			puts("a");
		else if (is_triangle_in_circle(p, p[3], r))
			puts("b");
		else if (interect_triangle_circle(p, p[3], r))
			puts("c");
		else
			puts("d");
	}

	return 0;
}

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

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

typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;
typedef vector<double> VD;
typedef vector<VD> VVD;

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

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

const ll mod = 998244353;

ll powll(ll x, ll y){
    x %= mod;
    ll res = 1LL;
    while(y){
        if (y & 1LL)
            res *= x;
        res %= mod;
        x = (x*x) % mod;
        y >>= 1LL;
    }
    return res;
}

ll divll(ll x, ll y){
    x %= mod;
    return (x * powll(y,mod-2)) % mod;
}

int main() {
    ll n, k, a;
    cin >> n >> k >> a;
    a = divll(a, 100);
    VL dp(k + 1);
    dp[0] = dp[1] = 1;
    ll s = 1, j = 1;
    FOR(i,2,k){
        if (j < i - n){
            s = (s - dp[j] + mod) % mod;
            j++;
        }
        ll t = s;
        dp[i] = divll(s * a, n);
        if (i <= n) dp[i] = (dp[i] + divll(n - i + 1, n)) % mod;
        s = (s + dp[i]) % mod;
    }
    cout << dp[k] << endl;
    return 0;
}



Measured memory_bytes: 3564
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) begin(v),end(v)
#define fi first
#define se second
template<typename A, typename B> inline bool chmax(A &a, B b) { if (a<b) { a=b; return 1; } return 0; }
template<typename A, typename B> inline bool chmin(A &a, B b) { if (a>b) { a=b; return 1; } return 0; }
using ll = long long;
using pii = pair<int, int>;
constexpr ll INF = 1ll<<30;
constexpr ll longINF = 1ll<<60;
constexpr ll MOD = 1000000007;
constexpr bool debug = 0;
//---------------------------------//

int main() {
	int N;
	cin >> N;
	vector<int> A(N);
	REP(i, N) scanf("%d", &A[i]);
	
	vector<int> ord(N);
	iota(ALL(ord), 0);
	sort(ALL(ord), [&](int x, int y) {
		return A[x] > A[y];
	});
	
	vector<vector<ll>> dp(N + 1, vector<ll>(N + 1, -1));
	dp[0][0] = 0;
	
	REP(i, N) {
		int idx = ord[i];
		ll a = A[idx];
		REP(j, i + 1) {
			if (dp[i][j] == -1) continue;
			// i 番目までで合計 j 人左採用
			ll cur = a * (idx - j) + dp[i][j];
			chmax(dp[i + 1][j + 1], cur);
			
			int k = i - j;
			cur = a * (N - 1 - k - idx) + dp[i][j];
			chmax(dp[i + 1][j], cur);
		}
	}
	
	ll ans = 0;
	REP(i, N + 1) chmax(ans, dp[N][i]);
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 34736
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG //これつけるとA[N]でもいいらしい
//for文のマクロ
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define big 1000000007
int main(){
  char b;
  cin>>b;
  if(b=='A')cout<<'T'<<endl;
  if(b=='G')cout<<'C'<<endl;
  if(b=='C')cout<<'G'<<endl;
  if(b=='T')cout<<'A'<<endl;
}

Measured memory_bytes: 256
fn main() {
    let mut line = String::new();
    std::io::stdin().read_line(&mut line).unwrap();
    let b: Vec<u8> = line.trim().as_bytes().iter().map(|a| *a).collect();
    let mut revb = b.clone();
    revb.reverse();
    let n = b.len();
    if revb == b {
        revb[0..n/2].reverse();
        if revb[0..n/2] == b[0..n/2] {
            revb[n/2+1..].reverse();
            if revb[n/2+1..] == b[n/2+1..] { // 不要そう
                println!("Yes");
                return;
            }
        }
    }
    println!("No");
}


Measured memory_bytes: 4352
#include <iostream>
using namespace std;
#define MAX 100005
#define NIL -1

struct Node {
    int p, l, r; 
};

Node T[MAX];
int n, D[MAX];

void print(int u) {
    int i, c;
    cout << "node " << u << ": ";
    cout << "parent = " << T[u].p << ", ";
    cout << "depth = " << D[u] << ", ";

    if (T[u].p == NIL) cout << "root, ";
    else if (T[u].l == NIL) cout << "leaf, ";
    else cout << "internal node, ";

    cout << "[";
    for (i = 0, c = T[u].l; c != NIL; i++, c = T[c].r) {
        if (i) cout << ", ";
        cout << c;
    }
    cout << "]" << endl;
}

//再帰的に深さを求める
int rec(int u, int p) {
    D[u] = p;
    if (T[u].r != NIL) rec(T[u].r, p); //右の兄弟に同じ深さを設定
    if (T[u].l != NIL) rec(T[u].l, p + 1); //最も左の子に自分の深さ+1を設定
}

int main() {
    int i, j, d, v, c, l, r;
    cin >> n;
    for (i = 0; i < n; i++) T[i].p = T[i].l = T[i].r = NIL;

    for (i = 0; i < n; i++) {
        cin >> v >> d;
        for (j = 0; j < d; j++) {
            cin >> c;
            if (j == 0) T[v].l = c;
            else T[l].r = c;
            l = c;
            T[c].p = v;
        }
    }
    for (i = 0; i < n; i++) {
        if (T[i].p == NIL) r = i;
    }

    rec(r, 0);

    for (i = 0; i < n; i++) print(i);

    return 0;
}


Measured memory_bytes: 7760
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <cmath>
#include <iomanip>
#include <stack>
#include <queue>
#include <numeric>
#include <map>
#include <unordered_map>
#include <set>
#include <fstream>
#include <chrono>
#include <random>
#include <bitset>
#define rep(i,n) for(int i=0;i<(n);i++)
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define sz(x) ((int)(x).size())
#define pb push_back
using ll = long long;
using namespace std;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
ll gcd(ll a, ll b) {return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) {return a/gcd(a,b)*b;}

int main(){
  int N; cin >> N;
  vector<int> A(N); rep(i,N) cin >> A[i];
  map<int,int> mp;
  ll ans = 0;
  rep(i,N){
    ans += mp[-A[i]+i+1];
    mp[A[i]+i+1]++;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 20944
x, y = map(int, input().split())
n = (2*y - x)//3 
m = (2*x - y)//3
mod = 10**9+7
def inv(x):
        return pow(x, mod-2, mod)
def fact(x):
        f = 1 
        for i in range(1, x + 1): 
                f *= i
                f %= mod    
        return f
def comb(n, r): 
        return (fact(n) * inv(fact(n-r)) * inv(fact(r))) % mod 
res = comb(n+m, m)
if (x + y) % 3 == 0 and n >= 0 and m >= 0:
        print(res)
else:
        print(0)

Measured memory_bytes: 3064
#include<stdio.h>

int main(){

	int a=0,b=0,c=0,k=0;
	int count=0;
	int i;

	scanf("%d %d %d %d",&a,&b,&c,&k);

	for(i=0;i<a;i++){
		if(k==0)
			break;
		count+=1;
                k-=1;

	}
	for(i=0;i<b;i++){
		if(k==0)
			break;
		k-=1;
	}
	for(i=0;i<c;i++){
		if(k==0)
			break;
		count-=1;
		k-=1;
	}

	printf("%d",count);

	return 0;
}




Measured memory_bytes: 1728
#include <bits/stdc++.h>
#define INF 1e9
#define MAX_V 1010
#define MAX_N 1001
using namespace std;

/*?????§?????¢?????´?????????(Ford_Fulerson????????¨)???O(F|E|)*/

//????????¨????§???????(???????????????????????????)
struct edge{int to, cap, rev;};

vector<edge> G[MAX_V]; //??°???????????£??\?????????
bool used[MAX_V];      //DFS??§?????§??????????????????????????°

//from??????to??????????????????cap???????????°?????????????????????
void add_edge(int from,int to,int cap){
  G[from].push_back((edge){to,cap,G[to].size()});
  G[to].push_back((edge){from,0,G[from].size()-1});  
}


//?¢?????????????DFS??§??¢???
int dfs(int v,int t,int f){
  if(v == t)return f;
  used[v]=true;
  for(int i=0; i<G[v].size() ;i++){
    edge &e = G[v][i];
    if(!used[e.to] && e.cap > 0){
      int d = dfs(e.to ,t , min(f,e.cap));
      if(d > 0){
	e.cap -= d;
	G[e.to][e.rev].cap += d;
	return d;
      }
    }
  }
  return 0;
}

//s??????t???????????§???????±???????
int max_flow(int s,int t){
  int flow = 0;
  for(;;){
    memset(used,0,sizeof(used));
    int f = dfs(s, t, INF);
    if(f == 0)return flow;
    flow += f;
  }
}

int N,K;
bool can[MAX_N][MAX_N]; //can[i][j]:=???????????\??????i?????????j??????????????????
int Biparite_Matching(){
  //0??????N-1: ???????????\???????????????????????????
  //N??????N+K-1: ???????????????????????????
  int s = N+K, t = s+1;
  
  //s??¨???????????\??????????????¶
  for(int i=0; i<N; i++) add_edge(s,i,1);
  
  //????????¨t?????????
  for(int i=0; i<K; i++) add_edge(N+i,t,1);
  
  //???????????\????????¨??????????????¶
  for(int i=0;i<N;i++)
    for(int j=0;j<K;j++)
      if(can[i][j]) add_edge(i, N+j , 1);

  return max_flow(s,t);
}

int main(){
  while(1){
  int b,r,B[501],R[501];
  cin>>b>>r;
  if(!b&&!r)break;
  for(int i=0;i<b;i++) cin>>B[i];
  for(int i=0;i<r;i++) cin>>R[i];

  memset(can,0,sizeof(can));
  for(int i=0;i<MAX_V;i++) G[i].clear();
  N=b,K=r;
  for(int i=0;i<b;i++)
    for(int j=0;j<r;j++)
      if(__gcd(B[i],R[j])>1) can[i][j]=1;

  cout<<Biparite_Matching()<<endl;
  }
  
  return 0;
}

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

using namespace std;


int main(){
	int N, X;
	cin >> N >> X;
	vector <int> m(100,10000);
	for(int i = 0; i < N; i++) {
		cin >> m[i];
	}
	int sum = X;
	for (int i = 0; i < N; i++) {
		sum -= m[i];
	}
	int count = 0;
	sort(m.begin(), m.end());
	int a = m[0];
	while (sum >= a) {
		count++;
		sum -= a;
	}


		cout << count + N << endl;
}



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

int main()
{
  int i,l;
  int x[5];
  
  for(i =0; i<=4;i++)
  {
        cin >> l;
        x[i] = l;
  }
   for(i=0; i<=4; i++)
   {
    if(x[i] == 0)
      {
       break;
      }
    else
      {
       continue;
      }
   }
  cout << i+1;

  return(0);
}



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

// #include <atcoder/all>

using namespace std;
// using namespace atcoder;
 
#define DEBUG(x) cerr<<#x<<": "<<x<<endl;
#define DEBUG_VEC(v) cerr<<#v<<":";for(int i=0;i<v.size();i++) cerr<<" "<<v[i]; cerr<<endl;
#define DEBUG_MAT(v) cerr<<#v<<endl;for(int i=0;i<v.size();i++){for(int j=0;j<v[i].size();j++) {cerr<<v[i][j]<<" ";}cerr<<endl;}
typedef long long ll;
// #define int ll
 
#define vi vector<int>
#define vl vector<ll>
#define vii vector< vector<int> >
#define vll vector< vector<ll> >
#define vs vector<string>
#define pii pair<int,int>
#define pis pair<int,string>
#define psi pair<string,int>
#define pll pair<ll,ll>
template<class S, class T> pair<S, T> operator+(const pair<S, T> &s, const pair<S, T> &t) { return pair<S, T>(s.first + t.first, s.second + t.second); }
template<class S, class T> pair<S, T> operator-(const pair<S, T> &s, const pair<S, T> &t) { return pair<S, T>(s.first - t.first, s.second - t.second); }
template<class S, class T> ostream& operator<<(ostream& os, pair<S, T> p) { os << "(" << p.first << ", " << p.second << ")"; return os; }
#define X first
#define Y second
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)
#define rrep(i,n) for(int i=(int)(n)-1;i>=0;i--)
#define rrep1(i,n) for(int i=(int)(n);i>0;i--)
#define REP(i,a,b) for(int i=a;i<b;i++)
#define in(x, a, b) (a <= x && x < b)
#define all(c) c.begin(),c.end()
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a = b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a = b; return 1; } return 0; }
#define UNIQUE(v) v.erase(std::unique(v.begin(), v.end()), v.end());
const ll inf = 1000000001;
const ll INF = (ll)1e18 + 1;
const long double pi = 3.1415926535897932384626433832795028841971L;
#define Sp(p) cout<<setprecision(25)<< fixed<<p<<endl;
// int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
// int dx2[8] = { 1,1,0,-1,-1,-1,0,1 }, dy2[8] = { 0,1,1,1,0,-1,-1,-1 };
vi dx = {1, 0, -1, 0}, dy = {0, 1, 0, -1};
// vi dx2 = { 1,1,0,-1,-1,-1,0,1 }, dy2 = { 0,1,1,1,0,-1,-1,-1 };
#define fio() cin.tie(0); ios::sync_with_stdio(false);
const ll MOD = 1000000007;
// const ll MOD = 998244353;
// #define mp make_pair
//#define endl '\n'

signed main() {
    fio();
    int n;
    cin >> n;
    
    ll ans = 0;
    for (ll a = 1; a <= n; a++) {
        for (int b = 1; a * b <= n; b++) {
            int c = n - a * b;
            if (c > 0) ans++;
        }
    }
    cout << ans << endl;
}

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

//定数
const long long MOD1=1000000007;
const long long MOD2=998244353;
const long double PI=3.1415926535897932;
const long long MAXLL=9223372036854775807;
const long long INF=2305843009213693951;
const long long dx[]={0,1,0,-1,1,-1,1,-1};
const long long dy[]={1,0,-1,0,1,1,-1,-1};

//型名省略
#define ll long long
#define ull unsigned long long
#define ld long double
#define uld unsigned long double
#define pll pair<long long,long long>
#define tll(n) array<long long,(int)(n)>
#define pcc pair<char,char>
#define vl vector<long long>
#define vvl vector<vector<long long>>
#define vc vector<char>
#define vvc vector<vector<char>>
#define vb vector<bool>
#define vvb vector<vector<bool>>
#define vp vector<pair<long long,long long>>
#define vt(n) vector<array<long long,(int)(n)>>
#define umap unordered_map
#define uset unordered_set
#define Lqueue priority_queue<long long>
#define Squeue priority_queue<long long,vector<long long>,greater<long long>>
#define Fi first
#define Se second
#define mp make_pair
#define eb emplace_back

//マクロ
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define rbf(a,x) for(auto& a:x)
#define rep(i,n) for(long long i=0;i<(long long)(n);i++)
#define rep2(i,s,n) for(long long i=(s);i<(long long)(n);i++)
#define bitrep(i,s,n) for(long long i=(s);i<(1LL<<(n));i++)
#define Maxe(x) *max_element((x).begin(),(x).end())
#define Mine(x) *min_element((x).begin(),(x).end())
#define Size(x) ((long long)(x).size())
#define lin(s) getline(cin,(s))

//Yes,No
void Yes(bool a){cout<<(a?"Yes":"No")<<endl;}
//YES.NO
void YES(bool a){cout<<(a?"YES":"NO")<<endl;}

//MAX,MIN
template<class T,class U> auto max(T a,U b){return a>b?a:b;}
template<class T,class U> auto min(T a,U b){return a<b?a:b;}

//最大公約数,最小公倍数
long long gcd(long long a,long long b){return b?gcd(b,a%b):a;}
long long lcm(long long a,long long b){return a/gcd(a,b)*b;}

//累乗
template<typename t>
constexpr t mypow(t a,long long b){
    if(b==0)return 1;
    if(a==0)return 0;
    t x=1;
    while(b>0){
        if(b&1LL)x*=a;
        a*=a;
        b>>=1LL;
        }
    return x;
}
#define pow mypow

//chmin,chmax
template<class T> inline bool chmin(T& a,T b){if(a>b){a=b;return true;}return false;}
template<class T> inline bool chmax(T& a,T b){if(a<b){a=b;return true;}return false;}

//組み合わせ O(r)
template<typename t>
constexpr t nCr(t n,long long r){
    if(r==0)return 1;
    if(n==0)return 0;
    if(n<r)return 0;
    t x=1;
    for(long long i=1;i<=r;i++){
        x*=n-i+1;
        x/=i;
    }
    return x;
}

//main関数
signed main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout<<fixed<<setprecision(12);
    ld a,b,c,d;
    cin>>a>>b>>c>>d;
    cout<<a*b/2<<" ";
    if(a/2==c&&b/2==d)cout<<1<<endl;
    else cout<<0<<endl;
}

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

int main() {
  int xx;
  double a,b,x;
  cin >> a >> b;
  x = (a+b)/2;
  xx = (a+b)/2;
  if(x-xx == 0){
    cout << x << endl;
  }
  else{
    cout << xx+1 << endl;
  }
}


Measured memory_bytes: 256
#include <stdio.h>
#include <iostream>
#include <vector>
#include <cstdint>
#include <algorithm>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

int main(){
  int N; cin >> N;
  vector<int> a(N);
  rep(i,N){
    cin >> a[i];
  }
  int count = 1;
  rep(i,N){
    if(a[i] == count){
      count++;
    }
  }
  if(count==1){
    cout << -1 << endl;
  }
  else{
    cout << N - count + 1 << endl;
  }
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
typedef long long ll;
typedef unsigned long long ull;
#define reps(i,s,n) for(ll (i)=(s);(i)<(n);++(i))
#define rep(i,n) reps(i,0,n)
#define reptr(i,n) for(ll (i)=(n);(i)>=0;--(i))
#define All(x) (x).begin(),(x).end()
#define Rall(a) (a).rbegin(), (a).rend()
#define vll vector<ll>
#define vi vector<int>
#define pll pair<ll,ll>
#define pi pair<int,int>
#define mp make_pair
#define pb push_back
const ll MOD=1e9+7;
const ll INF=1e10+1;
using namespace std;
#define NOT_EXIST -1

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

int main(){
	ll N,M;
	cin >> N >> M;
	vector<ll> a(N);
	vector<pll> cb(M);

	rep(i,N){
		cin >> a[i];
	}
	rep(i,M){
		ll b,c;
		cin >> b >> c;
		cb[i] = make_pair(c,b);

	}
	sort(All(a));
	sort(All(cb));
	ll max_c = cb[M-1].first , key = -1;

	ll ans = 0;

	for(ll i=N-1;i>=0;i--){
		if(max_c<=a[i]){
			ans += a[i];
		}else{
			key = i;
			break;
		}
	}
	//cout << ans << endl;

	if(key == -1){
		cout << ans << endl;
		return 0;
	}

	ll cnt = M-1;

	ll i = 0;
	while(i <= key){
		if(a[i] < cb[cnt].first){
			ll j=0;
			while(j < cb[cnt].second && a[i+j] < cb[cnt].first){
				if(i+j > key) break;
				a[i+j] = cb[cnt].first;
				ans += cb[cnt].first;
				j++;
			}
			i += j;
			cnt--;
		}else{
			for(ll j=i;j<=key;j++){
				ans += a[j];
			}
			break;
		}
	}
	cout << ans << endl;

}

Measured memory_bytes: 2688
import numpy as np
import copy
import math
n, kk = map(int, input().split())
a = [int(x) for x in input().split()]
a2 = np.array(copy.deepcopy(a))

key = 1
p = int(math.log2(max([kk, 1])))+1
x = [1]*p
for i in range(p):
  k = np.sum(a2%2)
  if n >= 2*k:
    x[i] = 0
  a2 = a2//2

x_sum = 0
for i in range(p-1, -1, -1):
  if x[i]:
    continue
  if x_sum+pow(2, i) > kk:
    continue
  x_sum += pow(2, i)

ans = 0
for i in range(n):
  ans += (x_sum^a[i])
print(ans)

Measured memory_bytes: 23600
import sys


def exists_allow(string, not_list):
    for i in not_list:
        if string.count(str(i)) > 0:
            return True
    return False


n, k = raw_input().split()
n = int(n)
d = map(int, raw_input().split())

while True:
    if exists_allow(str(n), d):
        n = n + 1
    else:
        print(n)
        sys.exit()


Measured memory_bytes: 2568
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <cstring>
#include <functional>
#include <queue>
#include <cmath>
#include <utility>

using namespace std;

#define int long long
#define rep(i,n) for(int i=0;i<(int)n;++i)
#define rep1(i,n) for(int i=1;i<=(int)n;++i)

int N;
int counter[10][10];

int front_digit(int a)
{
	while (a >= 10) a /= 10;
	return a;
}

signed main()
{
	cin >> N;

	rep1(i, N) {
		counter[front_digit(i)][i % 10]++;
	}

	int ans = 0;
	rep1(i, N) {
		if (i % 10) ans += counter[i % 10][front_digit(i)];
	}

	cout << ans << endl;
}


Measured memory_bytes: 256
#create date: 2020-06-29 09:31

import sys
stdin = sys.stdin

def ns(): return stdin.readline().rstrip()
def ni(): return int(ns())
def na(): return list(map(int, stdin.readline().split()))

def main():
    alpha = ns()
    print("A" if alpha.isupper() else "a")

if __name__ == "__main__":
    main()

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

int main() {
  int n;
  string s;
  cin >> n >> s;
  int mx  = 0;
  int cnt = 0;
  for (int i = 0; i < n; i++) {
    if (s[i] == 'I') {
      cnt++;
    } else {
      cnt--;
    }
    mx = max(mx, cnt);
  }
  cout << mx << endl;
}

Measured memory_bytes: 256
/* 
 * ??¨????????????????????????????????£?????????
 * http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=1172&lang=jp
 */
#include<iostream>
#include<map>
#include<vector>
#include<list>
#include<algorithm>
#include<cmath>
#include<iomanip>
#include<numeric>
#include<climits>
#include<ctime>
#include<cstring>
#define REP(i,p,n) for(int i=p;i<(int)(n);i++)
#define rep(i,n) REP(i,0,n)
#define rep_split(tok,a_str,re) for(char *tok = strtok((char *)a_str.c_str(),re); tok != NULL; tok = strtok(NULL,re))
#define ALL(c) (c).begin(), (c).end()
#define dump(a) cerr << #a << "=" << (a) << endl
#define PRIME_MAX 123456*2

using namespace std;

int main() {
	int N;
	bool prime[PRIME_MAX+1];

	prime[0] = false;
	prime[1] = false;
	REP(i,2,PRIME_MAX+1) prime[i] = true;

	//??¨????????????????????????
	REP(i,2,PRIME_MAX+1) {
		if (prime[i]) {  
			for (int j=i+i; j<PRIME_MAX+1; j+=i) prime[j] = false; 
		}
	}

	while(cin >> N && N) {
		cout << count(prime+N+1, prime+2*N+1, true) << endl; //N < x <=2*N
	}

	return EXIT_SUCCESS;
}

Measured memory_bytes: 1400
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MM = 1000000000;
const int MOD = MM + 7;
const int MAX = 510000;
#define rep(i, n) for(ll i=0; i<n; i++)
#define Rep(i, j, n) for(ll i=j; i<n; i++)
#define all(vec) vec.begin(), vec.end()
template<class T> inline bool chmin(T& a, T b) {if(a > b) {a = b; return true;} return false;}
template<class T> inline bool chmax(T& a, T b) {if(a < b) {a = b; return true;} return false;}
const ll INF = 1LL << 60;
const double pi = acos(-1.0);

int dh[4] = {0, 0, -1, 1};
int dw[4] = {1, -1, 0, 0};

int main() {
    int H, W; cin >> H >> W;
    int sh, sw; cin >> sh >> sw; sh--; sw--;
    int gh, gw; cin >> gh >> gw; gh--; gw--;
    vector<vector<char>> s(H, vector<char>(W));
    rep(i, H) rep(j, W) cin >> s[i][j];
    deque<tuple<int, int, int>> q;
    q.push_back(make_tuple(0, sh, sw));
    vector<vector<int>> seen(H, vector<int>(W, -1));
    while(q.size()) {
        tuple<int, int, int> now = q.front();
        q.pop_front();
        if(seen[get<1>(now)][get<2>(now)] != -1) continue;
        seen[get<1>(now)][get<2>(now)] = get<0>(now);
        rep(i, 4) {
            int nh = get<1>(now) + dh[i];
            int nw = get<2>(now) + dw[i];
            if(nh < 0 || H <= nh || nw < 0 || W <= nw) continue;
            if(seen[nh][nw] != -1) continue;
            if(s[nh][nw] == '#') continue;
            q.push_front(make_tuple(get<0>(now), nh, nw));
        }
        Rep(i, -2, 3) {
            Rep(j, -2, 3) {
                int nh = get<1>(now) + i;
                int nw = get<2>(now) + j;
                if(nh < 0 || H <= nh || nw < 0 || W <= nw) continue;
                if(seen[nh][nw] != -1) continue;
                if(s[nh][nw] == '#') continue;
                q.push_back(make_tuple(get<0>(now) + 1, nh, nw));
            }
        }
    }
    cout << seen[gh][gw] << endl;
}


Measured memory_bytes: 9096
#include <bits/stdc++.h>
#define R register
#define MN 100005
typedef long long ll;
inline int read(){
	R int x; R bool f; R char c;
	for (f=0; (c=getchar())<'0'||c>'9'; f=c=='-');
	for (x=c^'0'; (c=getchar())>='0'&&c<='9'; x=(x<<1)+(x<<3)+(c^'0'));
	return f?-x:x;
}
int n,a[MN],b[MN],aa[MN],bb[MN],f[MN],vn;ll ans;bool ud[MN];
inline int gf(int x){return f[x]?f[x]=gf(f[x]):x;}
int main(){
	n=read();for (R int i=1; i<=n; ++i) a[n+1]^=(aa[i]=a[i]=read());
	for (R int i=1; i<=n; ++i) b[n+1]^=(bb[i]=b[i]=read());
	aa[++n]=a[n];bb[n]=b[n];std::sort(aa+1,aa+n+1);std::sort(bb+1,bb+n+1);
	for (R int i=1; i<=n; ++i) if (aa[i]!=bb[i]) return 0*puts("-1");
	vn=std::unique(aa+1,aa+n+1)-aa-1;for (R int i=1,x,y; i<=n; ++i)
		if (i==n||a[i]!=b[i]){
			if (i<n) ++ans;
			x=std::lower_bound(aa+1,aa+vn+1,a[i])-aa;
			y=std::lower_bound(aa+1,aa+vn+1,b[i])-aa;
			ud[x]=ud[y]=1;x=gf(x),y=gf(y);if (x!=y) f[x]=y;
		}
	for (R int i=1; i<=vn; ++i) if (ud[i]&&!f[i]) ++ans;
	if (!ans) return 0*puts("0");
	printf("%lld\n",ans-1);return 0;
}

Measured memory_bytes: 3328
import java.util.Scanner;

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

		int num = scan.nextInt();
		int[] numbers = new int[num];
		int count = 0;
		while (count < num) {
			numbers[count] = scan.nextInt();
			count++;
		}
		int min = Integer.MAX_VALUE;
		int max = Integer.MIN_VALUE;
		double sum = 0;
		for (int i = 0; i < num; i++) {
			if (numbers[i] < min) {
				min = numbers[i];
			}
			if (numbers[i] > max) {
				max = numbers[i];
			}
			sum += numbers[i];
		}
		System.out.format("%d %d %.0f", min, max, sum);
System.out.println();
} 
}





Measured memory_bytes: 41580
def gcd(a,b):
    while a%b!=0:
        a,b=b,a%b
    return b
N=int(input())
A=list(map(int,input().split()))
if N==1:
    print(10**9)
    exit()
go=[0]*N
go[0]=A[0]
back=[0]*N
back[N-1]=A[N-1]
for i in range(1,N):
    go[i]=gcd(go[i-1],A[i])
for i in range(N-2,-1,-1):
    back[i]=gcd(back[i+1],A[i])
ans=max(go[-2],back[1])
for i in range(1,N-1):
    now=gcd(go[i-1],back[i+1])
    ans=max(now,ans)
print(ans)

Measured memory_bytes: 14524
n = int(input())
key = input()
x = {}
x[key] = None
s = list(key)[-1]
flag = True
for i in range(n - 1):
    xx = input()
    if xx not in x and s == list(xx)[0]:
        x[xx] = None
        s = list(xx)[-1]
    else:
        flag = False
if flag:
    print('Yes')
else:
    print('No')

Measured memory_bytes: 3064
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		long[] A = new long[N+2];

		for(int i = 1 ; i <= N ; i++){
			A[i] = sc.nextLong();
		}
		A[0] = 0;
		A[N+1] = 0;

		sc.close();

		long maxgcd = 0;
		long maxgcd2 = 0;

		long[] memo = new long[N+2];
		memo[0] = 0;
		memo[1] = A[1];
		memo[N] = A[N];
		memo[N+1] = 0;

		for(int i = N-1 ; i>=2 ; i--){
			memo[i] = gcd(memo[i+1],A[i]);
		}
/*
		for(int i = 0 ; i <= N+1 ; i++){
			System.out.println(memo[i]);
		}
*/
		long ans = 0;
		for(int i = 1 ; i <= N ; i++){
			if( i == 1){
				maxgcd = 0;
				maxgcd2 = memo[i+1];
			}
			else if(i == N){
				maxgcd = memo[i-1];
				maxgcd2 = 0;
			}
			else{
				memo[i] = gcd(memo[i-1],A[i]);
				maxgcd = memo[i-1];
				maxgcd2 = memo[i+1];

			}
			if(ans < gcd(maxgcd,maxgcd2)){
				ans = gcd(maxgcd,maxgcd2);
			}
		}
		System.out.println(ans);
	}


	static long gcd(long m, long n) {
	    if(m < n) return gcd(n, m);
	    if(n == 0) return m;
	    return gcd(n, m % n);
	}
}


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

int main() {
  int N,M,X,Y;
  cin >> N >> M >> X >> Y;
  vector<int> x(N);
  vector<int> y(M);
  for (int i = 0; i<N;i++) cin >> x.at(i);
  for (int i = 0; i<M;i++) cin >> y.at(i);
  
  sort(x.begin(),x.end());
  sort(y.begin(),y.end());
  
  int x_max = x.at(N-1);
  int y_min = y.at(0);
  
  bool ok = true;
  
  for (int i = X+1;i <= Y;i++) {
    if ((i > x_max) && (i <= y_min)) {
      ok = false;
    }
  }
  if (ok) cout << "War";
  else cout << "No War";
}
      



Measured memory_bytes: 256
#include<stdio.h>
const int N = 300;
const int M = 300;
int main()
{
	int n,m;
	while(scanf("%d %d" ,&n,&m))
	{
		if(n == 0&&m == n)
		{
			break;
		}
		for(int i = 0; i<m;i++)
		{
			printf("#");
		}
		printf("\n");
		for(int i = 0; i<n-2;i++)
		{
			printf("#");
			for(int j = 0; j < m-2; j++)
			{
			printf(".");
			}
			printf("#");
			printf("\n");
		}
		for(int i = 0; i<m;i++)
		{
			printf("#");
			
		}
		printf("\n");
		printf("\n");
	}
	return 0;
}


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

using namespace std;
#define ll long long

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);cout.tie(0);
    int k;cin>>k;
    string s;cin>>s;
    if((int)s.size()<=k) cout<<s<<endl;
    else
    {
        for(int i=0;i<k;i++) cout<<s[i];
        cout<<"..."<<endl;
    }
	return 0;
}


Measured memory_bytes: 3596
#include <bits/stdc++.h>
#define mod 1000000007
using namespace std;

typedef long long ll;

int main(){
  int N;
  ll sum=0,ans=0;
  cin >> N;
  vector<ll> A(N);
  for(int i=0; i<N; i++){
    cin >> A[i];
  }
  for(int i=1; i<N; i++){
    sum += A[i];
  }
  sum %= mod;
  for(int i=0; i<N-1; i++){
    ans += sum * A[i];
    ans %= mod;
    sum -= A[i+1];
    sum %= mod;
  }
  if(ans >= 0) cout << ans;
  else cout << ans+mod;
  return 0;
}

Measured memory_bytes: 4788
//============================================================================
// Name        : AOJ.cpp
// Author      :
// Version     :
// Copyright   : Your copyright notice
// Description : Hello World in C++, Ansi-style
//============================================================================

#include <iostream>
using namespace std;

int main() {
  int N;
  int D[100000];
  cin>>N;
  for(int i=0;i<N;i++){
    cin>>D[i];
  }

  int R=0;
  int a1=1,a2=1,a3=1;

  for(int i=1;i<N;i++){
	  if(D[i]==D[i-1]){
		  R=max(R,a3);
		  a3=a2+1;
		  a2=a1+1;
		  a1=1;

	  }
	  if(D[i]!=D[i-1]){
		  a1+=1;
		  a2+=1;
		  a3+=1;
	  }

  }
  R=max(R,a1);
  R=max(R,a2);
  R=max(R,a3);






  cout<<R<<endl;
  return 0;
}

Measured memory_bytes: 3468
N = int(input())

evidences = [[] for _ in range(N)]
for i in range(N):
  A = int(input())
  for _ in range(A):
    x, y = map(int, input().split())
    evidences[i].append((x - 1, y))

ans = 0
for i in range(1, 2 ** N):
    consistent = True
    for j in range(N):
        if (i >> j) & 1 == 0:
            continue
        for x, y in evidences[j]:
            if (i >> x) & 1 != y:
                consistent = False
                break
        #if not consistent:
            #break
    if consistent:
        ans = max(ans, bin(i)[2:].count('1'))
print(ans)

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

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

    if (abs(a - c) <= d || (abs(b - a) <= d && abs(c - b) <= d))
        cout << "Yes" << endl;
    else
        cout << "No" << endl;
    return 0;
}


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

using LL = long long;

#define ALL(a) begin((a)), end((a))
#define FOR(i, a, b) for (int(i) = (a); (i) < (b); (i)++)
#define RFOR(i, a, b) for (int(i) = (a); (i) > (b); (i)--)
#define debug(x) cout << #x << " : " << x << '\n'

const int INF = 1e9;
const LL LINF = 1e16;

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

  LL ans;
  int N, A;
  cin >> N >> A;

  ans = N * N - A;

  cout << ans << '\n';

  return 0;
}

Measured memory_bytes: 256
def main():
    N = int(input())
    A = [int(input()) for _ in range(N)]
    sortA = sorted(A)
    #print(A,sortA)
    ans = sortA[N-1]
    ans2 = sortA[N-2]
    if ans == ans2:
        flag = 1
    else:
        flag = 0

    for i in range(N):
        if flag == 1:
            print(ans)
        else:
            if A[i] == ans:
                print(ans2)
            else:
                print(ans)

main()


Measured memory_bytes: 18972
#include <stdio.h>

int main(void){
    int n,m,l;
    int i,j,k;
    int A[101][101]={},B[101][101]={};
    long long C[101][101]={};

    scanf("%d %d %d",&n,&m,&l);
    for(i=0; i<n; i++){
        for(j=0; j<m; j++){
            scanf("%d",&A[i][j]);
        }
    }
    
    for(i=0; i<m; i++){
        for(j=0; j<l; j++){
            scanf("%d",&B[i][j]);
        }
    }

    for(i=0; i<n; i++){
        for(j=0; j<l; j++){
            for(k=0; k<m; k++){
            C[i][j] += A[i][k] * B[k][j];
        }
    }
}

    for(i=0; i<n; i++){
        for(j=0; j<l; j++){
            if(j>0) printf(" ");
            printf("%lld",C[i][j]);
        }
        printf("\n");
    }
}


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

int main(){
    int h,w,n ;
    cin >> h >> w >> n ;
    int ans = n / max(h,w) ;
    if (n % max(h,w) != 0)
    {
        ans += 1 ;
    }
    cout << ans << endl ;
}

Measured memory_bytes: 256
/*---------------Go Code GO---------------*/

#include<bits/stdc++.h>
using namespace std;

#define     PI              acos(-1.0)
#define     O_O             ios_base::sync_with_stdio(false); cin.tie(NULL)
#define     precision(a)    fixed<<setprecision(a)
#define     endl            '\n'
#define     Flush           cout<<flush
#define     LLMX            0x3fffffffffffffff
#define     PW2(a)          (long long)1<<a

long long arr[500005];

int main()
{
    long long i,j,k,l,m,n,o,p,q,r,tst,ans=0;
    cin>>m>>n;
    cout<<ceil(1.0*m/n)<<endl;


    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
using namespace std;
int n;
int a[10000];
bool input()
{
	cin >> n ; if(!n) return false;
	for(int i=0;i<n;i++) cin >> a[i];
}
int main() {
	while(input())
	{
		sort(a,a+n);
		long sum[10000]={0}; long ans=0;
		for(int i=1;i<n;i++) sum[i]+=sum[i-1]+a[i-1];
		for(int i=0;i<n;i++) ans+=sum[i];
		cout << ans << '\n' ;
	}
}

Measured memory_bytes: 1292
import java.util.Scanner;
public class Main{
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
       // 配列の数N
		 int N = sc.nextInt();
       // 対象のカウント用
		 int count = 0;
       // 配列に数値を格納
		 int P[] = new int[N];
       //　pjを初期化
		 int Pj = 0;
		 for(int i=0; i<N; i++) {
			P[i]= sc.nextInt();
        // 配列の頭の数値
			Pj = P[0];
		 }
		 //最初に[0]番目をみてカウントする
		 //その後前の数と次の数を比べるようにし条件を満たせばカウントする
		 for(int i=0; i<N; i++) {
			if(P[i]<=Pj) {
				count++;
				Pj = P[i];
				}
		 }
		 System.out.println(count);
    }
}

Measured memory_bytes: 60352
#include<iostream>
#include<algorithm>
#include<vector>
#include<map>
#include<string>
#include<set>

using namespace std;
using LLI = long long int;

//struct UnionFind {
//	vector<int> par; // par[i]:iの親の番号　(例) par[3] = 2 : 3の親が2
//
//	UnionFind(int N) : par(N) { //最初は全てが根であるとして初期化
//		for (int i = 0; i < N; i++) par[i] = i;
//	}
//
//	int root(int x) { // データxが属する木の根を再帰で得る：root(x) = {xの木の根}
//		if (par[x] == x) return x;
//		return par[x] = root(par[x]);
//	}
//
//	void unite(int x, int y) { // xとyの木を併合
//		int rx = root(x); //xの根をrx
//		int ry = root(y); //yの根をry
//		if (rx == ry) return; //xとyの根が同じ(=同じ木にある)時はそのまま
//		par[rx] = ry; //xとyの根が同じでない(=同じ木にない)時：xの根rxをyの根ryにつける
//	}
//
//	bool same(int x, int y) { // 2つのデータx, yが属する木が同じならtrueを返す
//		int rx = root(x);
//		int ry = root(y);
//		return rx == ry;
//	}
//};

int main(void) {
	LLI N;
	bool res = false;
	cin >> N;
	for (int i = 0; i < N / 4 + 1; i++) {
		if ((N - (4 * i)) % 7 == 0) {
			res = true;
		}
	}
	if (res) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}
}

Measured memory_bytes: 256
s = gets.chomp
t = gets.chomp

(s.size-t.size).downto(0) do |i|
    if /#{s[i, t.size].gsub('?','[a-z]')}/ === t
        s[i, t.size] = t
        puts s.gsub('?','a')
        exit
    end
end

puts "UNRESTORABLE"


Measured memory_bytes: 1788
w, h, n = map(int, input().split())
xya = [list(map(int, input().split())) for _ in range(n)]

xl, xr, yb, yt = 0, w, 0, h

for i in range(n):
    if xya[i][2] == 1:
        xl = max(xl, xya[i][0])
    elif xya[i][2] == 2:
        xr = min(xr, xya[i][0])
    elif xya[i][2] == 3:
        yb = max(yb, xya[i][1])
    else:
        yt = min(yt, xya[i][1])

if xr - xl <= 0 or yt - yb <= 0:
    print(0)
else:
    print((xr - xl)*(yt - yb))

Measured memory_bytes: 3064
def main():
    _ = int(input())
    A = [int(i) for i in input().split()]
    A.sort()
    ma = A[-1]

    mi = 10**9+1
    idx = -1
    for i, v in enumerate(A):
        if ma % 2:
            if abs(ma//2 - v) < mi:
                mi = abs(ma//2 - v)
                idx = i
            if abs(0--ma//2 - v) < mi:
                mi = abs(0--ma//2 - v)
                idx = i
        else:
            if abs(ma//2 - v) < mi:
                mi = abs(ma//2 - v)
                idx = i
    print(ma, A[idx])


if __name__ == '__main__':
    main()


Measured memory_bytes: 62704
#include <stdio.h>

#define MAX 10000
#define NIL -1

typedef struct { int parent, left, right;} Node;

Node T[MAX];
int n, D[MAX], H[MAX];

void setDepth(int u,int d) {
  if(u == NIL) return;
  D[u] = d;
  setDepth(T[u].left, d+1);
  setDepth(T[u].right,d+1);
}

int setHeight(int u) {
  int h1 = 0, h2 = 0;
  if(T[u].left != NIL)
    h1 = setHeight(T[u].left) + 1;
  if(T[u].right != NIL)
    h2 = setHeight(T[u].right) + 1;
  return H[u] = (h1 > h2 ? h1 : h2);
}

// 接点 u の兄弟を返す
int getSibling(int u) {
  if( T[u].parent == NIL ) return NIL;
  if(T[T[u].parent].left != u && T[T[u].parent].left != NIL )
    return T[T[u].parent].left;
  if(T[T[u].parent].right != u && T[T[u].parent].right != NIL )
    return T[T[u].parent].right;
  return NIL;
}

void print(int u) {
  printf("node %d: ",u);
  printf("parent = %d, ",T[u].parent);
  printf("sibling = %d, ",getSibling(u));
  int deg = 0;
  if(T[u].left  != NIL) deg++;
  if(T[u].right != NIL) deg++;
  printf("degree = %d, ",deg);
  printf("depth = %d, ",D[u]);
  printf("height = %d, ",H[u]);
  
  if(T[u].parent == NIL) {
    printf("root\n");
  } else if(T[u].left == NIL && T[u].right == NIL) {
    printf("leaf\n");
  } else {
    printf("internal node\n");
  }
}

int main(void) {
  int v, l, r, root = 0;
  scanf("%d",&n);
  for(int i=0;i<n;i++) T[i].parent = NIL;
  for(int i=0;i<n;i++) {
    scanf("%d %d %d",&v,&l,&r);
    T[v].left  = l;
    T[v].right = r;
    if(l != NIL) T[l].parent = v;
    if(r != NIL) T[r].parent = v;
  }
  
  for(int i=0; i<n; i++)
  if(T[i].parent == NIL) root = i;
  
  setDepth(root,0);
  setHeight(root);
  
  for(int i=0;i<n;i++) print(i);
  
  return 0;
}


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

int mod = 1000000007;
int64_t large = 9223372036854775807;
double PI = 3.141592653589793;

int main()
{
    int N, K;
    cin >> N >> K;
    vector<int> list(N);
    for (int i = 0; i < N; i++)
        cin >> list[i];
    int64_t ans = large;
    for (int i = 0; i <= N - K; i++)
    {
        int64_t tmp = min(abs(0 - list[i]) + abs(list[i] - list[i + K - 1]), abs(0 - list[i + K - 1]) + abs(list[i + K - 1] - list[i]));
        ans = min(tmp, ans);
    }
    cout << ans;
}

Measured memory_bytes: 640
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cctype>
#define LL long long
LL in() {
    char ch; LL x = 0, f = 1;
    while(!isdigit(ch = getchar()))(ch == '-') && (f = -f);
    for(x = ch ^ 48; isdigit(ch = getchar()); x = (x << 1) + (x << 3) + (ch ^ 48));
    return x * f;
}
template<class T> bool chkmax(T &a, const T &b) { return a < b? a = b, 1 : 0; }
template<class T> bool chkmin(T &a, const T &b) { return b < a? a = b, 1 : 0; }
const int maxn = 1e6 + 10;
const int inf = 0x7fffffff;
class stack {
    protected:
        int st[maxn], tp;
    public:
        stack() { tp = 0; }
        void clear() { tp = 0; }
        int top() { return st[tp]; }
        void pop() { tp--; }
        bool empty() { return !tp; }
        void push(int x) { st[++tp] = x; }
}T;
int n;
LL ans, a[maxn];
int l[maxn], r[maxn];
int main() {
    n = in();
    for(int i = 1; i <= n; i++) a[i] = in();
    a[0] = a[n + 1] = -inf;
    T.push(0);
    for(int i = 1; i <= n; i++) {
        while(!T.empty() && a[i] <= a[T.top()]) T.pop();
        l[i] = T.top(); T.push(i);
    }
    T.clear(); T.push(n + 1);
    for(int i = n; i >= 1; i--) {
        while(!T.empty() && a[i] < a[T.top()]) T.pop();
        r[i] = T.top(); T.push(i);
    }
    for(int i = 1; i <= n; i++) ans += 1LL * (i - l[i]) * (r[i] - i) * a[i];
    printf("%lld\n", ans);
    return 0;
}

Measured memory_bytes: 13312
import sys

abc = [int(s) for s in sys.stdin.readline().strip().split(' ')]

a = abc[0]
b = abc[1]
c = abc[2]

is_kawai = False

if a == b:
    if b == c:
        pass
    else:
        is_kawai = True
elif b == c:
    is_kawai = True
elif a == c:
    is_kawai = True

if is_kawai:
    print('Yes')
else:
    print('No')




Measured memory_bytes: 38256
#include<bits/stdc++.h>
using namespace std;
int n,m,x[15005],y[15005];
bool vis[15005];
vector<int> g[15005];
long long ans;
void dfs(int x)
{
    if(vis[x])
        return;
    vis[x]=1;
    for(int i=0;i<g[x].size();i++)
        dfs(g[x][i]);
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cin>>n>>m;
    for(int i=1;i<=m;i++)
        cin>>x[i]>>y[i];
    for(int i=1;i<=m;i++)
    {
        memset(vis,0,sizeof(vis));
        for(int j=1;j<=n;j++)
            g[j].clear();
        for(int j=1;j<=m;j++)
            if(j!=i)
            {
                g[x[j]].push_back(y[j]);
                g[y[j]].push_back(x[j]);
            }
        int cnt=0;
        for(int j=1;j<=n;j++)
            if(!vis[j])
            {
                dfs(j);
                cnt++;
            }
        if(cnt>1)
            ans++;
    }
    cout<<ans;
    return 0;
}

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

template<class Type> inline bool chmax(Type& a, Type b) { if (a < b) { a = b; return 1; } return 0; }
template<class Type> inline bool chmin(Type& a, Type b) { if (a > b) { a = b; return 1; } return 0; }

template<class Type>
Type modpow(Type a, Type n, Type mod)
{
	Type res = 1;
	while (0 < n)
	{
		if (n & 1)
		{
			res = res * a % mod;
		}
		a = a * a % mod;
		n >>= 1;
	}
	return res;
}

template<class Type>
Type gcd(Type x, Type y)
{
	Type r;
	if (x < y)
	{
		swap(x, y);
	}

	while (0 < y)
	{
		r = x % y;
		x = y;
		y = r;
	}
	return x;
}

template<class Type>
Type lcm(Type x, Type y)
{
	return x * y / gcd(x, y);
}

template<class Type>
bool isPrime(Type x)
{
	if (x == 2) return true;
	if (x < 2 || x % 2 == 0) return false;

	for (Type i = 3; i <= sqrt(x); i += 2)
	{
		if (x % i == 0) return false;
	}
	return true;
}

template<class Type>
vector<bool> eratos(Type n)
{
	vector<bool> isPrime(n + 1, true);
	isPrime[0] = isPrime[1] = false;
	for (Type i = 2; i <= n; i++)
	{
		if (isPrime[i])
		{
			Type j = i + i;
			while (j <= n)
			{
				isPrime[j] = false;
				j = j + i;
			}
		}
	}
	return isPrime;
}

bool binarySearchJudge(vector<int> a, int index, int key)
{
	if (key <= a[index]) return true;
	else return false;
}

int binarySearch(vector<int> a, int key)
{
	int ng = -1;
	int ok = a.size();
	while (1 < abs(ng - ok))
	{
		int mid = (ng + ok) / 2;
		if (binarySearchJudge(a, mid, key)) ok = mid;
		else ng = mid;
	}
	return a[ok] == key;
}

int main()
{
	int n, m;
	cin >> n >> m;
	map<int, int> ac;
	map<int, int> wa;
	for (int i = 0; i < m; i++)
	{
		int p;
		string s;
		cin >> p >> s;
		if (s == "WA")
		{
			if (!ac.count(p))
			{
				wa[p]++;
			}
		}
		else //else if (s == "AC")
		{
			ac[p]++;
		}
	}
	int penalty = 0;
	for (auto item : ac)
	{
		penalty += wa[item.first];
	}
	cout << ac.size() << " " << penalty << endl;
}

Measured memory_bytes: 9600
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i, n) for(ll i=0;i<(ll)n;i++)
#define PI acos(-1)
#define fast_io ios_base::sync_with_stdio(false) ; cin.tie(0); cout.tie(0);
ll mod=1e9+7;
ll dp[200200]={};
int main(){
    fast_io
    
    int n;
    cin>>n;
    vector<ll> a(n);
    rep(i,n) {
        cin>>a.at(i);
    }
    sort(a.begin(), a.end());
    ll st=a[0];
    int i=0;
    ll ans=0;
    while(i<n){
        ll cnt=1;
        st=a[i];
        while(a[i]==a[i+1]){
            cnt++;
            i++;
        }
        if(st>cnt) ans+=cnt;
        else if(st<cnt) ans+=cnt-st;
        i++;
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 1152
#include<iostream>
#include<iomanip>
#include<algorithm>
#include<bitset>
#include<cassert>
#include<cctype>
#include<cmath>
#include<cstdio>
#include<cstring>
#include<functional>
#include<limits>
#include<list>
#include<map>
#include<numeric>
#include<set>
#include<stack>
#include<string>
#include<sstream>
#include<queue>
#include<vector>
using namespace std;

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

#define dump(o) { cerr << #o << " " << o << endl; }
#define dumpc(o) { cerr << #o; for (auto e : (o)) cerr << " " << e; cerr << endl; }
#define MOD 1000000007
#define INF 0x3f3f3f3f
#define INFL 0x3f3f3f3f3f3f3f3fLL

//??¶?´?????????£???????????? int,double:INF ll:INFL
#define INFG INF
using Weight = double;//int;
class Edge {
public:
	int s; //source
	int d; //destination
	Weight w; //weight
	Edge(int s = 0, int d = 0, Weight w = INFG) : s(s), d(d), w(w) {};
	bool operator<(const Edge &e)const { return w < e.w; }
};
using Edges = vector<Edge>;
//???????????\: g[u].push_back(Edge(u, v, c));
//????????¨???????????????????????°??????????????\?????????????????????
using Graph = vector<Edges>;
using Array = vector<Weight>;
using Matrix = vector<Array>;


vector<int> ticket;
double cost[30][1 << 8];
int n, m, p, a, b;

void solve(const Graph &g, int s) {
	fill(cost[0], cost[30], INFG);
	typedef tuple<Weight, int, int> State; //?§?????????????????°?????????? ??? used
	queue<State> Q;
	cost[s][0] = 0;
	Q.push(State(0, s, 0));//?§????
	while (!Q.empty()) {
		Weight d; int v; int used;
		tie(d, v, used) = Q.front(); Q.pop();
		if (cost[v][used] > d)continue;
		for (auto &e : g[v]) { //??£??\????????????????????¨????????????
			for (int i = 0; i < n; i++) {
				if ((used&(1 << i)) == (1 << i))continue;
				int dused = used | (1 << i);
				if (cost[e.d][dused] > cost[v][used] + e.w / ticket[i]) {
					cost[e.d][dused] = cost[v][used] + e.w / ticket[i];
					Q.push(State(cost[e.d][dused], e.d, dused));
				}
			}
		}
	}
}
int main() {
	/*

	n ??¬????????°
	m ????????°
	p ????????°
	a ????????° b ????????°

	t ??¬?????°
	x y ?????? z ?????¢

	*/
	cout << fixed << setprecision(4);
	for (; scanf("%d%d%d%d%d", &n, &m, &p, &a, &b), n;) {
		ticket.resize(n);
		--a; --b;
		for (int i = 0; i < n; i++) scanf("%d", &ticket[i]);
		Graph g(m);
		for (int i = 0; i < p; i++) {
			int x, y, z; scanf("%d%d%d", &x, &y, &z);
			--x; --y;
			g[x].push_back(Edge(x, y, z));
			g[y].push_back(Edge(y, x, z));
		}
		if (p == 0) {
			cout << "Impossible" << endl;
			continue;
		}
		solve(g, a);
		double ans = INFG;
		//dumpc(cost[b]);
		for (auto &e : cost[b]) {
			ans = min(ans, e);
		}
		if (ans == INFG)
			cout << "Impossible" << endl;
		else
			cout << ans << endl;
	}
	return 0;
}

Measured memory_bytes: 3484
N = int(input())
lsa = list(map(int,input().split()))
sunu = lsa[0]
ara = sum(lsa)- lsa[0]
ans = abs(ara-sunu)
for i in range(1,N-1):
    sunu += lsa[i]
    ara -= lsa[i]
    ans = min(ans,abs(ara-sunu))
print(ans)

Measured memory_bytes: 30584