akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define SIZE 710
#define PB push_back
#define MP make_pair
#define X first
#define Y second

using namespace std;
typedef vector<int> vi;
typedef pair<int, int> pii;


class Node {
public:
    Node *nxt;
    int idx;

    /*
    Node() {
        this = new Node;
        this->nxt = nullptr;
        idx = 0;
    }
    */
};


class Graph {
    int N;

public:
    Node **adj;

    Graph() {
        adj = nullptr;
    }

    Graph(const int N) {
        adj = new Node*[N + 1];
        for (int i = 0 ; i <= N ; ++i) adj[i] = nullptr;
        this->N = N;
    }

    void add_edge(int u, int v) {
        Node *new_node = new Node;
        new_node->nxt = adj[u];
        new_node->idx = v;
        adj[u] = new_node;
    }

    bool get_next(Node *curr) {
        if (curr->nxt != nullptr) {
            curr = curr->nxt;
            return true;
        }
        return false;
    }

    ~Graph() {
        for (int i = 0 ; i <= N ; ++i) {
            while (adj[i] != nullptr) {
                Node *curr = adj[i];
                adj[i] = adj[i]->nxt;
                delete curr;
            }
        }
    }
};

Graph G;
int edge[SIZE][SIZE], vis[SIZE], col[SIZE];
int cnt[2];

bool dfs1(int v) {
    ++cnt[col[v]];
    for (Node *curr = G.adj[v] ; curr != nullptr ; curr = curr->nxt) {
        int t = curr->idx;
        if (col[t] == -1) {
            col[t] = col[v] ^ 1;
            if (!dfs1(t)) return false;
        }
        if (col[t] != (col[v] ^ 1)) return false;
    }
    return true;
}

vector<pii> num;

bool bipartite(int n) {
    for (int i = 1 ; i <= n ; ++i) {
        cnt[0] = cnt[1] = 0;
        if (col[i] != -1) continue;
        col[i] = 0;
        if (!dfs1(i)) return false;
        num.PB(MP(cnt[0], cnt[1]));
    }
    return true;
}

int dp[SIZE][SIZE];

int main() {
    int n, m;
    scanf("%d %d", &n, &m);
    G = Graph(n);
    for (int i = 1 ; i <= n ; ++i) for (int j = 1 ; j <= n ; ++j) edge[i][j] = 0;

    for (int i = 0 ; i < m ; ++i) {
        int u, v;
        scanf("%d %d", &u, &v);
        edge[u][v] = edge[v][u] = 1;
    }   
    for (int i = 1 ; i <= n ; ++i) {
        col[i] = -1;
        for (int j = 1 ; j <= n ; ++j) {
            if (edge[i][j] || j == i) continue;
            G.add_edge(i, j);
        }
    }

    if (!bipartite(n)) {
        printf("-1\n");
        return 0;
    }

    int sz = num.size();
    dp[0][num[0].X] = dp[0][num[0].Y] = 1;
    for (int i = 1 ; i < sz ; ++i) {
        for (int j = 0 ; j <= n ; ++j) {
            if (j >= num[i].X && dp[i - 1][j - num[i].X]) dp[i][j] = 1;
            if (j >= num[i].Y && dp[i - 1][j - num[i].Y]) dp[i][j] = 1;
        }
    }

    for (int i = n / 2 ; i <= n ; ++i) {
        if (dp[sz - 1][i]) {
            int j = n - i;
            printf("%d\n", i * (i - 1) / 2 + j * (j - 1) / 2); 
            return 0;
        }
    }
    

}


Measured memory_bytes: 17536
#include<bits/stdc++.h>
#define rep(i, a, b)    for(int i = (a); i <= (int)(b); ++i)
#define per(i, a, b)    for(int i = (a); i >= (int)(b); --i)
#define debug(x)    cerr << #x << ' ' << x << endl;
using namespace std;
 
typedef long long ll;
const int MAXN = 2e5 + 7;

int main() {
    int a, b;
    scanf("%d %d", &a, &b);
    printf("%d\n", max(max(a+b, a-b), a*b));
    return 0;
}

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

void print_vec(vector<int> vec) {
  cout << "[";
  for (int i = 0; i < vec.size(); i++) {
    if (i) {
      cout << ", ";
    }
    cout << vec.at(i);
  }
  cout << "]...size: " << vec.size() << endl;
}

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

  int minv = 1001001001;
  int max_diff = -1001001001;

  rep(i, n) {
    int r;
    cin >> r;

    if (i) {
      max_diff = max(max_diff, r - minv);
    }

    minv = min(minv, r);
  }

  printf("%d\n", max_diff);
}



Measured memory_bytes: 3220
#include<bits/stdc++.h>
#define me(a,x) memset(a,x,sizeof(a))
#define sc scanf
#define itn int
#define IN freopen("in.txt","r",stdin);
#define OUT freopen("out.txt","w",stdout);
#define STR clock_t startTime = clock();
#define END clock_t endTime = clock();cout << double(endTime - startTime) / CLOCKS_PER_SEC *1000<< "ms" << endl;
using namespace std;
const int N=1e6;
const long long mod=1e9+7;
const long long mod2=998244353;
const int oo=0x7fffffff;
const int sup=0x80000000;
typedef long long ll;
typedef unsigned long long ull;
template <typename it>void db(it *begin,it *end){while(begin!=end)cout<<(*begin++)<<" ";puts("");}
template <typename it>
string to_str(it n){string s="";while(n)s+=n%10+'0',n/=10;reverse(s.begin(),s.end());return s;}
template <typename it>int o(it a){cout<<a<<endl;return 0;}
inline ll mul_64(ll x,ll y,ll c){return (x*y-(ll)((long double)x/c*y)*c+c)%c;}
ll ksm(ll a,ll b,ll c){ll ans=1;for(;b;b>>=1,a=a*a%c)if(b&1)ans=ans*a%c;return ans;}
void exgcd(ll a,ll b,ll &x,ll &y){if(!b)x=1,y=0;else exgcd(b,a%b,y,x),y-=(a/b)*x;}
int n;
ll A[N],F[N],need[N],K;
bool qin(ll mid){
    for(int i=1;i<=n;i++)need[i]=mid/F[i];
    ll ans=0;
    sort(need+1,need+1+n);
    for(int i=1;i<=n;i++){
        if(A[i]<=need[i])continue;
        ans+=A[i]-need[i];
    }
    return ans<=K;
}
int main(){
    cin>>n>>K;
    for(int i=1;i<=n;i++)scanf("%lld",&A[i]);
    for(int i=1;i<=n;i++)scanf("%lld",&F[i]);
    sort(A+1,A+1+n);
    ll ans=0,l=0,r=1e13+2434;
    while(r>=l){
        ll mid=(l+r)/2;
        if(qin(mid))ans=mid,r=mid-1;
        else l=mid+1;
    }
    o(ans);
}

Measured memory_bytes: 9984
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <cstdlib>

using namespace std;

#define int long long

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

constexpr int TEN(int n) { return (n == 0) ? 1 : 10 * TEN(n - 1); };

const int inf = TEN(18) + 10;

int N, X, D, sum;
int a[55];

int f(int y)
{
	int sousa = 0;

	rep(i, N) sousa += max((a[i] - y) / D, 0ll);

	return sousa;
}

signed main()
{
	cin >> N;

	rep(i, N) {
		cin >> a[i];
	}

	rep(i, N) {
		sum += a[i];
	}

	// X, D を定義する
	X = max(sum - (N - 1) * N, 0ll);
	D = N + 1;

	// はじめに a[i] それぞれに X を足してしまう
	rep(i, N) a[i] += X;

	// 二分探索で f(Y) <= X となる最大の Y を求める(hi = Y となるようにしているつもり) 
	int lo = -1, hi = inf, step = -1;
	while (hi - lo > 1) {
		int mid = (hi + lo) / 2;

		if (f(mid) <= X) {
			step = f(mid); // それがf(Y) の値も念のため step に保存しておく
			hi = mid;
		} else {
			lo = mid;
		}
	}

	// わかりやすさのため hi を max_Y とする
	int max_Y = hi;

	rep(i, N) {
		a[i] = a[i] - max((a[i] - max_Y) / D, 0ll) * D;
	}

	// すべての i について a[i] <= N - 1 を満たすまで愚直にシミュレーション
	while (true) {
		bool ok = true;
		rep(i, N) {
			if (a[i] >= N) ok = false;
		}

		if (ok) break;

		int mx = -inf, idx = -1;

		rep(i, N) {
			if (mx < a[i]) {
				mx = a[i];
				idx = i;
			}
		}

		step++;

		if (step > X) {
			a[idx] -= N;

			rep(i, N) if (i != idx) a[i]++;
		} else {
			a[idx] -= D;
		}
	}

	printf("%lld\n", step);
}


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

int main(){
    char A[3];
    int a = 0;
    int b = 0;
    for(int i = 0; i < 3; i++) cin >> A[i];
    for(int i = 0;i < 3; i++){
        if(A[i] == 'A') a= 1;
        if(A[i] == 'B') b = 1;

    }
    //cout << a << b << "\n";
    if(a == 1 && b == 1){
        cout << "Yes";
    } else{
        cout << "No";
    }
    return 0;
    
}

Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <string>
#include <list>
#include <vector>
#include <queue>
#include <math.h>

using namespace std;

long long int gcd(long long int x, long long int y) {
	if (x < y){
      return gcd(y, x);
    }
	long long int r;
	while (r = x % y) {
		x = y;
		y = r;
	}
	return y;
}

int main(void){
  long long int n,i,j;
  cin >> n;
  long long int a[n];
  long long int minusCount=0;
  long long int minAbs=1000000000;
  long long int total = 0;
  long long int tmp = 0;
  for(i=0;i<n;i++){
    cin >> a[i];
    if(a[i]<0) minusCount++;
    tmp = abs(a[i]);
    if(tmp<minAbs) minAbs = tmp;
    total += tmp;
  }
  
  if(minusCount%2!=0){
    total -= minAbs*2;
  }
  cout << total << endl;
  return 0;
}




Measured memory_bytes: 1024
import java.util.*;

class Main{
	public static void main(String[] $){
		System.err.println();
		Scanner s=new Scanner(System.in);
		int n=s.nextInt();
		for(int i=0;i<50000;++i) {
			if((int)(i*1.08)==n) {
				System.out.println(i);
				return;
			}
		}
		System.out.println(":(");
	}
}


Measured memory_bytes: 21844
n,m=map(int,input().split())
oya=[set() for i in range(n)]
ko=[set() for i in range(n)]
rank=[0]*n
for i in range(n+m-1):
    a,b=map(int,input().split())
    ko[a-1].add(b-1)
    oya[b-1].add(a-1)
for s in range(n):
    if not oya[s]:break
q=[[s,ko[s]]]
ans=[0]*n
while q:
    now,nex=q.pop()
    for i in nex:
        oya[i].remove(now)
        if not oya[i]:
            ans[i]=now+1
            q.append([i,ko[i]])
for i in ans:print(i)

Measured memory_bytes: 71332
#include <iostream>
#include <algorithm>
#include <functional>
#include <cstdlib>
#include <sstream>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <complex>
#include <vector>
#include <bitset>
#include <cstdio>
#include <cmath>
#include <time.h>
#include <tuple>
#define all(c) ((c).begin(),(c).end())
#define rall(c) ((c).rbegin(),(c).rend())
//#define sort(v,n) sort(v,v+n)
#define ll long long
#define fi first
#define se second
#define inf 999999999
using namespace std;
const ll MOD = 1e9 + 7;
const double PI = acos(-1.0);
//---------------------------------------------------------------------------------------------//


int n;

int main() {
	while (cin >> n, n) {
		vector< vector <int> > vv(110);
		bool b[110];
		for (int i = 0; i < n; i++) {
			b[i] = 1;
			int m; cin >> m;
			for (int j = 0; j < m; j++) {
				int a; cin >> a;
				vv[i].push_back(a);
			}
		}
		int k; cin >> k;
		for (int i = 0; i < k; i++) {
			int a; cin >> a;
			for (int j = 0; j < n; j++) {
				auto ite = find(vv[j].begin(), vv[j].end(),a);
				if (ite != vv[j].end()) {
					vv[j].erase(ite);
				}
				else {
					b[j] = 0;
				}
			}
		}
		int mujunn = 0;
		int ans;
		for (int i = 0; i < n; i++) {
			if (b[i]) {
				ans = i + 1;
				mujunn++;
			}
		}
		if (mujunn < 1 || mujunn>1) {
			cout << -1 << endl;
		}
		else {
			cout << ans << endl;
		}
	}
	return 0;
}

Measured memory_bytes: 3172
#include <iostream>
#include <sstream>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <memory>
#include <complex>
#include <numeric>
#include <cstdio>
#include <iomanip>

#define REP(i,m,n) for(int i=int(m);i<int(n);i++)
#define RREP(i,m,n) for(int i=int(n)-1;i>=int(m);--i)
#define EACH(i,c) for (auto &(i): c)
#define all(c) begin(c),end(c)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort(begin(c),end(c))
#define pb emplace_back
#define MP make_pair
#define SZ(a) int((a).size())

#ifdef LOCAL
#define DEBUG(s) cout << (s) << endl
#define dump(x)  cerr << #x << " = " << (x) << endl
#define BR cout << endl;
#else
#define DEBUG(s) do{}while(0)
#define dump(x) do{}while(0)
#define BR 
#endif
using namespace std;

using UI = unsigned int;
using UL = unsigned long;
using LL = int_fast64_t;
using ULL = unsigned long long;
using VI = vector<int>;
using VVI = vector<VI>;
using VLL = vector<LL>;
using VS = vector<string>;
using PII = pair<int,int>;
using VP = vector<PII>;

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

constexpr double EPS = 1e-10;
//constexpr double PI  = acos(-1.0);
//constexpr int INF = INT_MAX;

template<class T> inline T sqr(T x) {return x*x;}

void solve() {
    int n,m,x,y;
    cin >> n >> m >> x >> y;
    VI a(n), b(m);
    REP(i,0,n) cin >> a[i];
    REP(i,0,m) cin >> b[i];
    a.push_back(x);
    b.push_back(y);
    sort(all(a));
    sort(all(b));
    //if (a[n-1] < b[0] && x < b[0] && y > a[n-1]) cout << "No War" << endl;
    if (a[n] < b[0]) cout << "No War" << endl;
    else cout << "War" << endl;
}

int main() {
    solve();
    
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define all(a)  (a).begin(),(a).end()
typedef long long ll;
ll mod=1000000007;
string s;

int main() {
  int n;
  cin >> n;
  map<int, int> mp;
  for (int i=0;i<n;++i) {
    int a; cin>>a;
    if (mp.find(a)==mp.end()){
      mp[a] =1;
    } else {
      mp[a] +=1;
    }
  }
  vector<pair<int, int>> v;
  for (auto const& ele: mp) {
    v.push_back(make_pair(ele.first,ele.second));
  }
  int cnt=0;
  for (int j=0;j<v.size();++j) {
    if(v[j].first>v[j].second){
      cnt +=v[j].second;
    } else{
      cnt += v[j].second - v[j].first;
    }
  }
  cout << cnt << endl;
  return 0;
}

Measured memory_bytes: 5884
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MAXN = 1e5 + 5;
int main() {
    
    int n,x;
    cin >> n >> x;
    ll sum = 0;
    for(int i = 0 ; i < x ; i++)
      {
          int v;
          cin >> v;
          sum+=v;
      }
      
    if(n - sum <= 0)
      cout << "Yes";
     else 
      cout << "No";
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)   FOR(i,0,n)

using namespace std;
using ll = long long;

ll kiriage(ll a, ll b) {
	return (a + b - 1) / b;
}

void Main() {
	int a, b; cin >> a >> b;
	cout << kiriage(b - 1, a - 1) << endl;
}

int main() {
    cin.tie(nullptr);
	ios_base::sync_with_stdio(false);
	cout << fixed << setprecision(15);
	Main();
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)

int main() {
  int a, b, c, d;
  cin >> a >> b >> c >> d;
  int x = c - a;
  int y = d - b;
  cout << c - y << " " << d + x << " " << a - y << " " << b + x << endl;
}


Measured memory_bytes: 256
import java.util.Scanner;
class Main
{
    public static void main(String args[])
    {
	Scanner scan=new Scanner(System.in);
	while(scan.hasNext())
	    {
		double f,t;
		
		f=scan.nextDouble();
		t=scan.nextDouble();
		String str="";
		if(f>=1*60+10.0 || t>=2*60+28.0)str="NA";
		if(f<1*60+10.0 && t<2*60+28.0)
		    {
		
str="E";
		    }
		if(f<55.0 && t<1*60+56.0)str="D";
		if(f<50.0 && t<1*60+45.0)str="C";
		if(f<43.0 && t<1*60+29.0)str="B";
		if(f<40.0 && t<1*60+23.0)str="A";
		if(f<37+0.5 && t<1*60+17.0)str="AA";
		if(f<35+0.5 && t<1*60+11.0)str="AAA";
		
		System.out.println(str);
	    }
    }
}

Measured memory_bytes: 20716
#include<bits/stdc++.h>
using namespace std;
long long n=0,ans;
int main()
{
	string s;
	cin>>s;
	long long g;
	for(int i=s.size()-1;i>=0;i--)
		if(s[i]!='0')
		{
			g=i;
			break;
		}
	for(int i=0;i<=g;i++)
	{
		if(s[i]-'0'==4)
		{
			if(n%2==0)
				ans+=4;
			else
			{
				if(s[i+1]-'0'>=5)
					ans+=5;
				else if(n%2==1 && s[i+1]-'0'<5)
				{
					ans+=5;
					n++;
				}
			}	
		}
		else if((s[i]-'0'>5 && n%2==0) || (s[i]-'0'<5 && n%2==1))
		{
			n++;
			if(i!=g)
				ans+=min(s[i]-'0',9-(s[i]-'0'))+1;
			else
				ans+=min(s[i]-'0',10-(s[i]-'0'))+1;
		}
		else if((s[i]-'0'>=5 && n%2==1) || (s[i]-'0'<5 && n%2==0))
		{
			if(i!=g)
				ans+=min(s[i]-'0',9-(s[i]-'0'));
			else
				ans+=min(s[i]-'0',10-(s[i]-'0'));
		}	
		else
		{
			if(s[i+1]>='5')
				n++;
			ans+=5;
		}
	}
	cout<<ans<<endl;
} 

Measured memory_bytes: 1412
#Postal Code
A, B = map(int,input().split())
S = input()
num = [chr(ord('0') + i) for i in range(10)]
judge = 1

for i in range(len(S)):
    if i == A:
        if S[i] == "-":
            pass
        else:
            judge = 0
    else:
        if S[i] in num:
            pass
        else:
            judge = 0
            
if judge == 1:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 3060
#include <stdlib.h>
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>

using namespace std;

int main(void){
   int N, A, B;
   

   cin >> N >> A >> B;

   int sum = 0;
   int ans = 0;

   for(int i=1;i<=N;i++){
       int tmp = i;
       int sum = 0;
       for(int j=0;j<5;j++){
           sum = sum + tmp % 10;
           tmp = tmp / 10;
       }
       if((A <=sum) and (sum <=B)){
           ans = ans + i;
       }
   }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
using namespace std;
int main(){
  int n;
  cin >> n;
  vector<int> ans(n);
  int p;
  for(int i=0;i<n;i++){
    cin >> p;
    ans[p-1] = i+1;
  }
  for(int i=0;i<n;i++){
    cout << ans[i] << " ";
  }
  return 0;
}

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

int main(){
  ll n, k;
  cin >> n >> k;
  vector<ll> p(n);
  rep(i, n) cin >> p[i];
  ll ans = 0;
  rep(i, k) ans += p[i];
  ll memo = ans;
  for (int i = 0; i < n - k; i++){
    ans = ans - p[i] + p[i + k];
    memo = max(ans, memo);
  }
  double ans1 = memo;
  ans1 = (ans1 + k)/2;
  printf("%.10f\n", ans1);
  return 0;
}

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

int main() {
	int N;
	cin >> N;
	vector<string> s(N);
	for (int n = 0; n < N; n++) {
		cin >> s.at(n);
	}
	int M;
	cin >> M;
	vector<string> t(M);
	for (int m = 0; m < M; m++) {
		cin >> t.at(m);
	}
	int max_num = 0;
	for (int n = 0; n < N; n++) {
		string now_s = s.at(n);
		if (now_s == "") {
			continue;
		}
		int now_num = 1;
		for (int i = n + 1; i < N; i++) {
			if (now_s == s.at(i)) {
				now_num++;
				s.at(i) = "";	// 消しておく.
			}
		}
		for (int i = 0; i < M; i++) {
			if (now_s == t.at(i)) {
				now_num--;
			}
		}
		if (now_num > max_num) {
			max_num = now_num;
		}
	}
	cout << max_num << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <math.h>
#include <numeric>
#include <vector>
#include <map>
#include <algorithm>
#include <queue>
#include <tuple>
#include <functional>

#define PI 3.14159265359
#define INF 1e9
#define LINF 1e18
#define irep(i,n) for(int  i = 0; i < n; i++)
#define irep2(i,a,n) for(int i = a; i < n; i++)
#define lrep(i,n) for(long long  i = 0; i < n; i++)
#define lrep2(i,a,n) for(long long i = a; i < n; i++)
#define in(a) cin >> a
#define out(a) cout << a << endl
typedef long long ll;

typedef std::vector<int> v_int;
typedef std::vector<std::vector<int> > v2_int;
typedef std::vector<ll> v_ll;
typedef std::vector<std::vector<ll> > v2_ll;

using namespace std;

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

    string s = a+b; 
    int num = stoi(s);

    for(int i = 1; i <= 500; i++) {
        if(i*i == num) {
            cout << "Yes" << endl;
            return 0;
        }
    }
    cout << "No" << endl;
    return 0;
}
    



Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<cstdio>
#include<cstdlib>
#include<string>
#include<sstream>
#include<cmath>
#include<numeric>
#include<map>
#include<stack>
#include<queue>
#include<list>
#include<set>
using namespace std;
int mod = 1e9 + 7;
template <class T>
void inputV(vector<T> &x, int n){
  for(int i=0; i<n; i++) cin >> x[i];
}

int main() {

  string s; cin >> s;
  s[3] = '8';
  cout << s << endl;

  return 0;
}




//


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

struct node {
	int key;
	node *p, *l, *r;
};

node *root, *NIL;

void insert(int k)
{
	node* y = NIL;
	node* x = root;
	node* z;

	z = (node*)malloc(sizeof(node));
	z->key = k;
	z->l = NIL;
	z->r = NIL;

	while (x != NIL)
	{
		y = x;
		if (z->key < x->key) x = x->l;
		else x = x->r;
	}

	z->p = y;
	if (y == NIL) {
		root = z;
	}
	else {
		if (z->key < y->key) y->l = z;
		else y->r = z;
	}
}

void find_t(node* n, int k)
{
	node* x = n;
	while (x != NIL && k != x->key)
	{
		if (k < x->key) x = x->l;
		else x = x->r;
	}
	if (x != NIL) cout << "yes" << endl;
	else cout << "no" << endl;

	return;
}

void inorder(node *n)
{
	if (n == NIL) return;

	inorder(n->l);
	cout << " " <<  n->key;
	inorder(n->r);

	return;
}

void preorder(node *n)
{
	if (n == NIL) return;

	cout << " " << n->key;
	preorder(n->l);
	preorder(n->r);

	return;
}

int main(void)
{
	int N, k;
	string s;
	list<node> t;
	cin >> N;
	for (int i = 0; i < N; i++)
	{
		cin >> s;
		if (s == "insert"){
			cin >> k;
			insert(k);
		}
		else if (s == "print") {
			inorder(root);
			cout << endl;
			preorder(root);
			cout << endl;
		}
		else if (s == "find") {
			cin >> k;
			find_t(root, k);
		}
	}
	

	return 0;
}


Measured memory_bytes: 21920
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Numerics;
using static System.Console;
using static System.Math;
using static System.Array;

class Program
{
	public static void Main()
	{
		var n = ReadLine().Split().Select(long.Parse).ToArray();
		if(n[0] + 1 < n[1] || n[1] < n[0] - 1)
		{
			WriteLine(0);
			return;
		}
		long a = 1;
		for(int i = 1; i <= n[0]; i++)
		{
			a = (a * i) % 1000000007;
		}
		long b = 1;
		for(int i = 1; i <= n[1]; i++)
		{
			b = (b * i) % 1000000007;
		}
		long r = (a * b) % 1000000007;
		if(n[0] == n[1])
			r = (r * 2) % 1000000007;
		WriteLine(r);
	}
}


Measured memory_bytes: 18988
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<queue>
#include<iostream>
using namespace std;
const int INF=1e9;
struct node{
	int x,y;
}a[100100],d[100100],h[100100];
bool operator < (const node &A,const node &B){
	return A.x>B.x;
}
bool cmpr(const node &A,const node &B){
	return A.y<B.y;
}
priority_queue<node> q;
int top,cnt;
int b[100100],g[100100];
int c[100100],f[100100],mp[100100];
int ans;
int main(){
//	freopen("F.in","r",stdin);
	int n;
	scanf("%d",&n);
	ans=n;
	for(int i=1;i<=n;i++)
	{
		scanf("%d%d",&a[i].x,&a[i].y);
		swap(a[i].x,a[i].y);
	}

	for(int i=1;i<=n+1;i++){
		scanf("%d",&b[i]);
		c[i]=b[i];
	}
	sort(b+1,b+n+1+1);
	int num=unique(b+1,b+n+1+1)-b-1;
	for(int i=1;i<=num;i++)
		mp[i]=b[i];
	for(int i=1;i<=n+1;i++)
		c[i]=lower_bound(b+1,b+num+1,c[i])-b;
	for(int i=1;i<=n;i++){
		a[i].x=lower_bound(b+1,b+num+1,a[i].x)-b;
		a[i].y=lower_bound(b+1,b+num+1,a[i].y)-b;
	}

	memset(b,0,sizeof(b));
	for(int i=1;i<=n+1;i++)
		b[c[i]]--;
	for(int i=1;i<=n;i++){
		if(a[i].y<=a[i].x)
			b[a[i].y]++;
		else
		{
			b[a[i].y]++;
			a[++top]=a[i];
		}
	}
	for(int i=1;i<=num;i++)
		b[i]=b[i-1]+b[i];
	sort(a+1,a+top+1,cmpr);

	int l=top;
	top=0;
	bool bo=0;
	int st=0,ls;
	for(int i=num;i>=1;i--)
	{
		while(l>=1&&a[l].y>i){
			q.push(a[l]);
			l--;
		}
		st-=f[i];
		ls=st;
		for(int j=1;j<(-b[i]-ls);j++){
			if(q.empty()){
				bo=1;
				break;
			}
			d[++top]=q.top();
			q.pop();
			st++;
			f[d[top].x-1]++;
		}
		if(bo) break;
	}
	int Q,x,y;
	if(bo){
		scanf("%d",&Q);
		while(Q--)
			printf("-1\n");
		return 0;
	}

	memset(f,0,sizeof(f));
	for(int i=1;i<=top;i++)
		f[d[i].x]++,f[d[i].y]--;
	for(int i=1;i<=num;i++)
		f[i]=f[i-1]+f[i];
	for(int i=1;i<=num;i++)
		b[i]=b[i]+f[i];
	ans-=top;

	top=0;
	while(!q.empty()){
		a[++top]=q.top();
		q.pop();
	}
	sort(a+1,a+top+1,cmpr);
	l=top;
	int mn=INF;
	for(int i=num;i>=1;i--)
	{
		while(l>=1&&a[l].y>i){
			if(a[l].x<mn) mn=a[l].x;
			l--;
		}
		g[i]=mn;
	}

	memset(f,0,sizeof(f));
	for(int i=1;i<=num;i++){
		if(b[i]>=0)
			f[i]=f[i-1];
		else if(b[i]==-1){
			if(g[i]>i) f[i]=-1;
			else{
				if(f[g[i]-1]==-1) f[i]=-1;
				else f[i]=f[g[i]-1]+1;
			}
		}
		else
			return -1;
	}
	scanf("%d",&Q);
	while(Q--){
		scanf("%d%d",&x,&y);
		x=lower_bound(mp+1,mp+num+1,x)-mp;
		y=lower_bound(mp+1,mp+num+1,y)-mp;
		st=-1;
		if(x<=num&&f[x-1]>-1&&ans-f[x-1]+1>st) st=ans-f[x-1]+1;
		if(y<=num&&f[y-1]>-1&&ans-f[y-1]>st) st=ans-f[y-1];
		printf("%d\n",st);
	}
	return 0;
}


Measured memory_bytes: 6004
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace AtCorder
{
	public class Program
	{
		static void Main(string[] args)
		{
			Scanner cin = new Scanner();
			int n = cin.Int();
			int m = cin.Int();
			int l = cin.Int();
			long inf = (long)(1e9) + 1;
			var d = new long[n, n];
			for (int i = 0; i < n; i++) {
				for (int j = 0; j < n; j++) {
					if (i != j) {
						d[i, j] = inf;
					}
				}
			}

			for (int i = 0; i < m; i++) {
				int a = cin.Int() - 1;
				int b = cin.Int() - 1;
				long c = cin.Long();
				d[a, b] = c;
				d[b, a] = c;
			}

			for (int i = 0; i < n; i++) {
				for (int j = 0; j < n; j++) {
					for (int k = 0; k < n; k++) {
						d[j, k] = Math.Min(d[j, k], d[j, i] + d[i, k]);
					}
				}
			}

			var d2 = new long[n, n];
			for (int i = 0; i < n; i++) {
				for (int j = 0; j < n; j++) {
					if (d[i, j] <= l) {
						d2[i, j] = 1;
					} else {
						d2[i, j] = inf;
					}
				}
			}

			for (int i = 0; i < n; i++) {
				for (int j = 0; j < n; j++) {
					for (int k = 0; k < n; k++) {
						d2[j, k] = Math.Min(d2[j, k], d2[j, i] + d2[i, k]);
					}
				}
			}

			int q = cin.Int();
			var sb = new StringBuilder();
			for (int i = 0; i < q; i++) {
				int a = cin.Int() - 1;
				int b = cin.Int() - 1;

				if (d2[a, b] >= inf) {
					sb.AppendLine("-1");
				} else {
					sb.AppendLine((d2[a, b] - 1).ToString());
				}
			}

			Console.WriteLine(sb.ToString());
		}
	}

	public class Scanner
	{
		private readonly char[] delimiter_ = new char[] { ' ' };
		private string[] buf_;
		private int index_;

		public Scanner()
		{
			buf_ = new string[0];
			index_ = 0;
		}

		public string Next()
		{
			if (index_ < buf_.Length) {
				return buf_[index_++];
			}

			string st = Console.ReadLine();
			while (st == "") {
				st = Console.ReadLine();
			}

			buf_ = st.Split(delimiter_, StringSplitOptions.RemoveEmptyEntries);
			if (buf_.Length == 0) {
				return Next();
			}

			index_ = 0;
			return buf_[index_++];
		}

		public int Int() => int.Parse(Next());
		public long Long() => long.Parse(Next());
		public double Double() => double.Parse(Next());

		public int[] ArrayInt(int N, int add = 0)
		{
			int[] Array = new int[N];
			for (int i = 0; i < N; i++) {
				Array[i] = Int() + add;
			}
			return Array;
		}

		public long[] ArrayLong(int N, long add = 0)
		{
			long[] Array = new long[N];
			for (int i = 0; i < N; i++) {
				Array[i] = Long() + add;
			}
			return Array;
		}

		public double[] ArrayDouble(int N, double add = 0)
		{
			double[] Array = new double[N];
			for (int i = 0; i < N; i++) {
				Array[i] = Double() + add;
			}
			return Array;
		}
	}
}

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

int main()
{
  long long int n;
  long long int min = 1000000000000000;

  cin >> n;
  for(int i=0; i<5; ++i)
  {
    long long int t;
    cin >> t;
    if(t < min)
    {
      min = t;
    }
  }
  long long int bottle_neck;
  if(min == 1)
    bottle_neck = n;
  else
    bottle_neck = n / min + 1;

  long long int result = bottle_neck + 4;
  cout << result << endl;
  return 0;
}

Measured memory_bytes: 256
/* 
	Author: ankrypt
*/


#include <bits/stdc++.h>

using namespace std;

#define MOD 1000000007
#define ll long long int
#define u64 unsigned long long int

ll N;
string S = "";
ll hashCnt[30];
set<char> s, s1;

int main() {
	scanf("%lld", &N);
	cin >> S;
	ll ans = -1e9;
	for(int i = 1; i < S.size(); i++) {
		int temp = S.size() - i;
		memset(hashCnt, 0, sizeof(hashCnt));
		s.clear();
		s1.clear();
		for(int j = 0; j < temp; j++) {
			s.insert(S[j]);
		}
		for(int k = temp; k < S.size(); k++) {
			s1.insert(S[k]);
		}
		set<char>:: iterator itr, itr1;
		for(itr = s.begin(); itr != s.end(); itr++) {
			hashCnt[*itr - 'a']++;
		}
		for(itr1 = s1.begin(); itr1 != s1.end(); itr1++) {
			hashCnt[*itr1 - 'a']++;
		}
		ll cnt = 0; 
		for(int i = 0; i < 30; i++) {
			if(hashCnt[i] == 2) {
				cnt++;
			}
		}
		ans = max(ans, cnt);
	}
	printf("%lld\n", ans);
	return 0;
}
/*
	Powered by Buggy Plugin
*/


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

using namespace std;

int N, x, y, INF = 2e9 + 4;

int dist (int x, int y)
{
    if (x > y) return INF;
    return y - x;
}

int main ()
{
//freopen ("input", "r", stdin);
//freopen ("output", "w", stdout);

scanf ("%d %d", &x, &y);
int ans = dist (x, y);
ans = min (ans, dist (-x, y) + 1), ans = min (ans, dist (x, -y) + 1), ans = min (ans, dist (-x, -y) + 2);
printf ("%d\n", ans);
return 0;
}


Measured memory_bytes: 764
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=int(a);i<int(b);++i)
using namespace std;
typedef long long ll;
int INF = (1LL << 30) - 1;
int MOD = 1e9+7;
main(){
    int N,M;
    cin >> N >> M;
    vector<string> S(N);
    rep(i,0,N){
        cin >> S[i];
    }
    sort(S.begin(), S.end());
    rep(i,0,N)cout << S[i];
    cout << endl;
}

Measured memory_bytes: 256
#include <algorithm>
#include <climits>
#include <cmath>
#include <cstdio>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
#define REP(var, a, b) for (int var = (a); var < (b); var++)
#define rep(var, n) for (int var = 0; var < (n); ++var)
#define ALL(c) (c).begin(), (c).end()
#define rALL(c) (c).rbegin(), (c).rend()

int main() {
  //
  int n, k;
  cin >> n >> k;
  vl x(n);
  rep(i, n) cin >> x[i];
  ll ans = INT_MAX;
  rep(i, n - k + 1) {
    ll tmp = min(abs(x[i]), abs(x[i + k - 1])) + (x[i + k - 1] - x[i]);
    ans = min(ans, tmp);
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 1152
#include <iostream>
#include <string>
#include <math.h>
#include <iomanip>
#include <stdio.h>
#include <algorithm>
#include <ctime>
#include <vector>
#include <set>
#include <queue>
using namespace std;
typedef long long ll;

#define PI 3.14159265358979323846264338327950L

int res;

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

    int N;
    cin >> N;
    res = N % 1000;
    if (res == 0)
    {
        cout << 0 << endl;
        return 0;
    }
    else
    {
        res = 1000 - res;
    }
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 3648
import sys
input = sys.stdin.readline
from collections import deque

def main():
  h, w, k = map(int, input().split())
  x1, y1, x2, y2 = map(lambda x:int(x)-1, input().split())
  v1 = x1*(w+1)+y1
  v2 = x2*(w+1)+y2
  C = "".join(input().rstrip()+"@" for _ in range(h))
  dist = [-1 if c=="@" else 10**10 for c in C]
  ans = 0
  que = deque()
  que.append(v1)
  dist[v1] = 0
  while que:
    v = que.popleft()
    if v == v2:
      print(dist[v2])
      exit()
    d = dist[v]+1
    for dr in (-(w+1), -1, w+1, 1):
      for i in range(1, k+1):
        nv = v+dr*i
        if 0 <= nv < h*(w+1):
          if dist[nv] > d:
            dist[nv] = d
            que.append(nv)
          elif dist[nv] == d:
            continue
          else:
            break
        else:
          break
  print(-1)
if __name__ == "__main__":
  main()

Measured memory_bytes: 124588
#include <bits/stdc++.h>
using namespace std;
typedef pair<int, int> ii;

int dp[3010][3010];
ii p[3010][3010];
int main(){

    string s, t;
    cin >> s >> t;
    memset(dp, 0, sizeof(dp));
    
    for(int i = 1; i <= (int)s.length(); i++){
        for(int j = 1; j <= (int)t.length(); j++){
            if(s[i-1] == t[j-1]){
                dp[i][j] = dp[i-1][j-1] + 1;
                p[i][j] = {i-1, j-1};
            }else{
                if(dp[i-1][j] >= dp[i][j-1]){
                    p[i][j] = {i-1, j};
                }else{
                    p[i][j] = {i, j-1};
                }
                dp[i][j] = max(dp[i-1][j], dp[i][j-1]);
            }
        }
    }

    ii act = {s.length(), t.length()};
    stack<char> sk;

    while(act.first != 0 && act.second != 0){
        ii nxt = p[act.first][act.second];
        if(nxt.first != act.first && nxt.second != act.second){
            sk.push(s[act.first-1]);
        }
        act = nxt;
    }

    while(sk.size()){
        cout << sk.top();
        sk.pop();
    }
    cout << endl;


    return 0;
}



Measured memory_bytes: 106368
#include <bits/stdc++.h>
#include <unordered_map>
#define ll long long int
#define pb push_back
#define mp make_pair
#define mod 1000000007
#define rep(i,n) for(ll i=0;i<n;i++)
#define all(c) (c).begin(),(c).end()
#define max3(a,b,c) max(max(a,b),c)
#define min3(a,b,c) min(min(a,b),c)
#define vi vector <int>
#define vs vector <string>
#define vc vector <char>
#define vl vector <ll>
# define INF 0x3f3f3f3f 
using namespace std;
ll power(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll modInverse(ll a){return power(a,mod-2);}
const int N=500023;
bool vis[N];
vector <int> adj[N];
ll gcd(ll a, ll b) { if (a == 0) return b; return gcd(b % a, a); } 
ll lcm(ll a, ll b){return a*b/gcd(a, b);}

// vl sum(500001);


void solve()
{
    ll n;
    cin>>n;
    vl a(n);
    vl v;
    rep(i,n){
        cin>>a[i];
        if(i!=0){
            if(a[i]!=a[i-1]){
                v.pb(a[i]);
            }
        }
        else{
            v.pb(a[i]);
        }
    }
    ll amt = 1000;
    ll stocks = 0;
    rep(i,v.size()){
        if(i==n-1){
            amt = amt + (stocks)*v[i];
            stocks = 0;
        }
        if(v[i]>v[i+1]){
            amt = amt + (stocks)*v[i];
            stocks = 0;
        }
        else if(v[i]<v[i+1]){
            stocks += (amt/v[i]);
            amt = amt - (amt/v[i])*v[i];
        }
    }
    cout<<amt;

    
    

}

int main()
{

    #ifndef ONLINE_JUDGE
        // for getting input from input.txt
        freopen("input.txt", "r", stdin);
        // for writing output to output.txt
        freopen("output.txt", "w", stdout);
    #endif

    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    
    int T=1;
    // cin>>T;
    int t=0;
    while(t++<T)
    {
        // cout<<"Case #"<<t<<":"<<' ';
        solve();
        // cout<<'\n';
    }
    cerr << "Time : " << 1000 * ((double)clock()) / (double)CLOCKS_PER_SEC << "ms\n";
}

Measured memory_bytes: 15472
#include<iostream>
#include<algorithm>
#include<stack>
using namespace std;
 
struct Ses{
    int start, end, area;
};
 
int main(){
    string str;
    cin >> str;
    int n = str.size(), overall = 0;
    stack<Ses> S;
    stack<int> slope;
    Ses temp; 

    for(int i = 0; i < n; i++){
        if(str[i] == '\\'){
            slope.push(i);
        } else if(str[i] == '/'){
            if(!slope.empty()){
                int b = slope.top();
                slope.pop();
                temp.start = b;
                temp.end = i;
                temp.area = i-b;
                overall += temp.area;
                while( !S.empty() ){
                    if(temp.start < S.top().start){
                        temp.area += S.top().area;
                        S.pop();
                    } else {
                        break;
                    }
                }
                S.push(temp);
            }
        }
    }
    cout << overall << endl;
    int m = S.size(), A[m];
    cout << m;
    for(int i = 0; i < m; i++){
        A[m - i - 1] = S.top().area;
        S.pop();
    }
    for(int i = 0; i < m; i++)
        cout << " " << A[i];
    cout << endl;
}

Measured memory_bytes: 1312
import java.util.*;

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

Measured memory_bytes: 35664
[n, Y] = list(map(int, input().split()))
x, y, z = -1, -1, -1
for xx in range(n+1):
    for yy in range(n+1-xx):
        zz = n - xx - yy
        if Y == 10000 * xx + 5000 * yy + 1000 * zz:
            x, y, z = xx, yy, zz
            break
print(x, y, z)

Measured memory_bytes: 3060
import java.util.Scanner

object Main extends App {

  val sc = new Scanner(System.in)
  val n = sc.nextLine()
  val anStr = sc.nextLine()
  val an = anStr.split(" ")

  val res = an.map(_.toInt).map(ju)

  if (res.contains(false)) println("DENIED") else println("APPROVED")

  def ju(i: Int): Boolean = {
    if (i % 2 != 0) {
      true
    } else if ((i % 3 == 0) || (i % 5 == 0)) {
      true
    } else {
      false
    }
  }
}



Measured memory_bytes: 27204
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**6)
##############################

N = int(input())
A = []
for i in range(N):
    a = int(input())
    A.append(a)

B = list(reversed(sorted(A)))

for i in range(N):
    # 最大か二番目を出せばいい
    if A[i] == B[0]:
        print(B[1])
    else:
        print(B[0])

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

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

long long MOD = 1000000000 + 7;

// 約数列挙 O(√n)
vector<ll> divisor(ll n){
  vector<ll> res;
  for(ll i = 1; i * i <= n; i++){
    if(n % i == 0){
      res.push_back(i);
      if(i != n / i) res.push_back(n / i);
    }
  }
  return res;
}

bool solve(vector<ll> v, ll K, ll r){

  ll sum = 0;
  for(int i = 0; i < v.size(); i++){
    v[i] %= r;
    sum += v[i];
  }
  if(sum == 0) return true;

  sort(v.begin(), v.end());
  vector<ll> w(v.size());

  w[0] = v[0];
  for(int i = 1; i < w.size(); i++){
    w[i] = w[i-1] + v[i];
  }
  // cerr << w[w.size()-1] << endl;

  for(int i = 0; i < w.size() - 1; i++){
    ll before = w[i]; // マイナスして0にする分

    ll after = w[w.size()-1] - w[i]; // プラスしてrにする分 
    ll after_num = w.size() - i - 1;
    after = r * after_num - after;

    // cerr << "r: " << r << " before: " << before << " after: " << after << endl;


    if(before == after && before <= K){
      return true;
    } else {
      continue;
    }
  }

  return false;
}

int main(){
  cout << setprecision(10);
  int N; cin >> N;
  ll K; cin >> K;
  vector<ll> v(N);

  ll sum = 0;
  for(int i = 0; i < N; i++){
    cin >> v[i];
    sum += v[i];
  }

  auto list = divisor(sum);
  sort(list.begin(), list.end());

  ll ans = 1;

  for(int i = list.size()-1; i >= 0; i--){
    // K回以下で、list[i]で割れるようにできるか

    if(solve(v, K, list[i])){
      ans = list[i];
      break;
    }
  }

  cout << ans << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  int a,b;cin>>a>>b;
  int r=log10(b)+1;
  a=a*pow(10,r)+b;
  int s=sqrt(a);
  if(s*s==a)cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
}

Measured memory_bytes: 384
#include <stdio.h>
 
int main()
{
    long long int x, y, num1, num2, keep;
     
    scanf("%lld %lld", &x, &y);
    num1 = x; num2 = y;
    while(num2 != 0){
        keep = num2;
        num2 = num1 % num2;
        num1 = keep;
    }   
    printf("%lld\n", num1);
     
    return 0;
}

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

int main() {
  int H,W;
  while (cin >> H >> W, H!=0 || W!=0) {
    for (int i = 0; i < H; i++) {
      for (int j = 0; j < W; j++) {
        cout << "#";
      }
      cout << endl;
    }
    cout << endl;
  }
  return 0;
}

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

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

    if(a>=13)
    {
        cout<<b;
    }
    else if(a>=6 && a<=12)
    {
        cout<<b/2;
    }
    else if(a<6)
    {
        cout<<"0";
    }
}



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

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

using namespace std;

int main()
{
  double a, b, x;
  cin >> a >> b >> x;

  double s = x / a;
  double rad;
  if(s >= a*b/2)
  {
    double h = (a * b -s) * 2 / a;
    rad = atan2(h, a);
  }
  else
  {
    double w = s * 2 / b;
    rad = atan2(b, w);
  }
  double deg = rad/(2*M_PI) * 360;
  printf("%.10f\n", deg);
  return 0;
}


Measured memory_bytes: 384
#include <algorithm>
#include <bitset>
#include <complex>
#include <cstdio>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#if __cplusplus >= 201103L
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#endif

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 < (int)b; ++i)

typedef long long ll;

const int Inf = 1e9;
const double EPS = 1e-9;

int gcd(int a, int b) {
    if (b == 0) {
        return a;
    } else {
        return gcd(b, a % b);
    }
}

int lcm(int a, int b) {
    return a * b / gcd(a, b);
}

int bitCount(long bits) {
    bits = (bits & 0x55555555) + (bits >> 1 & 0x55555555);
    bits = (bits & 0x33333333) + (bits >> 2 & 0x33333333);
    bits = (bits & 0x0f0f0f0f) + (bits >> 4 & 0x0f0f0f0f);
    bits = (bits & 0x00ff00ff) + (bits >> 8 & 0x00ff00ff);
    return (bits & 0x0000ffff) + (bits >>16 & 0x0000ffff);
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;  cin >> n;
    vector<int> t(n + 1), x(n + 1), y(n + 1);
    t[0] = 0, x[0] = 0, y[0] = 0;
    FOR (i, 1, n + 1) {
      cin >> t[i] >> x[i] >> y[i];
    }
    FOR (i, 1, n + 1) {
      int dt, dx, dy;
      dt = t[i] - t[i - 1];
      dx = x[i] - x[i - 1];
      dy = y[i] - y[i - 1];
      if ((dt < abs(dx) + abs(dy)) || dt % 2 != (abs(dx) + abs(dy)) % 2) {
        cout << "No" << endl;
        return 0;
      }
    }
    cout << "Yes" << endl;

    return 0;
}


Measured memory_bytes: 1408
#include<bits/stdc++.h>
using namespace std;
const int inf=0x3f3f3f3f;

int d[55];
int n,minn;
vector<int> v;


int main(){
    while(scanf("%d",&n)!=EOF){
        v.clear();
        minn=inf;
        for(int i=1;i<=n;i++){
            scanf("%d",&d[i]);
        }
        sort(d+1,d+n+1);
        v.push_back(0);
        for(int i=1;i<=n;i++){
            if(i&1){
                v.push_back(d[i]);
            }else{
                v.push_back(24-d[i]);
            }
        }
        sort(v.begin(),v.end());
        for(int i=1;i<v.size();i++){
            minn=min(minn,v[i]-v[i-1]);
        }
        printf("%d\n",minn);
    }
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define pii pair<int,int>
#define pll pair<ll,ll>
#define pdd pair<double,double>
#define FILL(a,x) memset(a,x,sizeof(a))
#define foreach( gg,ii ) for( typeof(gg.begin()) ii=gg.begin();ii!=gg.end();ii++)
#define mp make_pair
#define pb push_back
#define X first
#define Y second
#define sz(a) int((a).size())
#define N 1000010
#define MAX 30
#define mod 1000000007
#define REP(i,a) for(int i=0;i<a;++i)
#define REPP(i,a,b) for(int i=a;i<b;++i)
#define all(a) a.begin(),a.end()
const ll INF = 1e18+1;

char m[502][502],a[502][502],b[502][502];

int main()
{
	ll h,w;
	scanf("%lld%lld",&h,&w);
	REP(i,h)
		scanf("%s",m[i]);
	REP(i,h)
	{
		REP(j,w)
		{
			if (i==0) printf("#");
			else if (i==h-1) printf(".");
			else if (j%2) printf("#");
			else if (m[i][j]=='#') printf("#");
			else printf(".");
		}
		printf("\n");
	}
	printf("\n");
	REP(i,h)
	{
		REP(j,w)
		{
			if (i==h-1) printf("#");
			else if (i==0) printf(".");
			else if (j%2==0) printf("#");
			else if (m[i][j]=='#') printf("#");
			else printf(".");
		}
		printf("\n");
	}
return 0;
}


Measured memory_bytes: 1024
N,A,B,C=map(int,input().split())
l=[int(input()) for i in range(N)]
inf=10**9

def dfs(cur,a,b,c):
    if cur==N:
        return abs(a-A)+abs(b-B)+abs(c-C)-30 if min(a,b,c)>0 else inf
    ret0=dfs(cur+1,a,b,c)
    ret1=dfs(cur+1,a+l[cur],b,c)+10
    ret2=dfs(cur+1,a,b+l[cur],c)+10
    ret3=dfs(cur+1,a,b,c+l[cur])+10
    return min(ret0,ret1,ret2,ret3)

print(dfs(0,0,0,0))


Measured memory_bytes: 43996
//! ----------------------------------------------
//! Framework <https://github.com/vain0x/procon>
//!
//! See the bottom of file for solution.
//! ----------------------------------------------

#![allow(unused_imports)]
#![allow(non_snake_case)]

use std::cell::RefCell;
use std::cmp::{max, min, Ordering};
use std::collections::*;
use std::fmt::{Debug, Display, Formatter, Write as FmtWrite};
use std::io::{stderr, stdin, BufRead, Write};
use std::mem::{replace, swap};
use std::ops::*;
use std::rc::Rc;

/// Print values to standard error if debug mode.
#[allow(unused_macros)]
macro_rules! debug {
    ($($e:expr),*) => {
        #[cfg(debug_assertions)]
        $({
            let (e, mut err) = (stringify!($e), stderr());
            writeln!(err, "\x1B[33m{}\x1B[0m = {:?}", e, $e).unwrap()
        })*
    };
}

/// Read from standard input and parse each word.
/// - `read!(T, U, ..)` parses a line as a tuple of words.
/// - `read![[T]]` parses a line as an array of words.
/// - `read![..; N]` parses `N` lines, using `read!(..)` repeatedly.
#[allow(unused_macros)]
macro_rules! read {
    ([$t:ty] ; $n:expr) =>
        ((0..$n).map(|_| read!([$t])).collect::<Vec<_>>());
    ($($t:ty),+ ; $n:expr) =>
        ((0..$n).map(|_| read!($($t),+)).collect::<Vec<_>>());
    ([$t:ty]) =>
        (rl().split_whitespace().map(|w| w.parse().unwrap()).collect::<Vec<$t>>());
    ($($t:ty),*) => {{
        let buf = rl();
        let mut w = buf.split_whitespace();
        ($(w.next().unwrap().parse::<$t>().unwrap()),*)
    }};
}

/// Read a line from standard input.
#[allow(dead_code)]
fn rl() -> String {
    let mut buf = String::new();
    stdin().read_line(&mut buf).unwrap();

    #[allow(deprecated)]
    buf.trim_right().to_owned()
}

// -----------------------------------------------
// Solution
// -----------------------------------------------

fn main() {
    let (D, G) = read!(usize, usize);
    let mut p = vec![];
    let mut c = vec![];

    for _ in 0..D {
        let (pi, ci) = read!(usize, usize);
        p.push(pi);
        c.push(ci);
    }

    let mut min_count = std::usize::MAX;

    for s in 0..1 << D {
        let mut total = 0;
        let mut count = 0;

        for i in 0..D {
            if ((s >> i) & 1) != 0 {
                let score = 100 * (i + 1);
                total += p[i] * score + c[i];
                count += p[i];
            }
        }

        for i in (0..D).rev() {
            if ((s >> i) & 1) == 0 {
                let score = 100 * (i + 1);
                let k = min((G.saturating_sub(total) + score - 1) / score, p[i]);
                total += k * score;
                count += k;
            }
        }

        if total >= G {
            min_count = min(min_count, count);
        }
    }

    println!("{}", min_count)
}


Measured memory_bytes: 4352
#include <iostream>
#include <string>
#include <cmath>
using namespace std;
int main()
{
	string a,b;
	cin >> a >> b;
	a = a + b;
	long long x = 0;
	for(int i = 0;i < a.size();i++)
	    {
	    	x = x * 10 + a[i] - '0';
		}
	for(int i = 1;i <= sqrt(x)+1;i++)
	    {
	    	if(i * i == x)
	    	    {
	    	    	cout << "Yes" << endl;
	    	    	return 0;
				}
		}
	cout << "No" << endl;
	return 0;
 } 

Measured memory_bytes: 256