akhauriyash/Code-Regression huggingface dataset:
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.InputMismatchException;
import java.io.IOException;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        FastReader in = new FastReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        AWeLoveGolf solver = new AWeLoveGolf();
        solver.solve(1, in, out);
        out.close();
    }

    static class AWeLoveGolf {
        public void solve(int testNumber, FastReader s, PrintWriter out) {
            int n = s.nextInt();
            int a = s.nextInt();
            int b = s.nextInt();
            boolean bool = false;
            for (int i = a; i <= b; i++) {
                if (i % n == 0) {
                    bool = true;
                    out.println("OK");
                    break;
                }
            }

            if (!bool) {
                out.println("NG");
            }
        }

    }

    static class FastReader {
        private InputStream stream;
        private byte[] buf = new byte[1024];
        private int curChar;
        private int numChars;
        private FastReader.SpaceCharFilter filter;

        public FastReader(InputStream stream) {
            this.stream = stream;
        }

        public int read() {
            if (numChars == -1) {
                throw new InputMismatchException();
            }
            if (curChar >= numChars) {
                curChar = 0;
                try {
                    numChars = stream.read(buf);
                } catch (IOException e) {
                    throw new InputMismatchException();
                }
                if (numChars <= 0) {
                    return -1;
                }
            }
            return buf[curChar++];
        }

        public int nextInt() {
            int c = read();
            while (isSpaceChar(c)) {
                c = read();
            }
            int sgn = 1;
            if (c == '-') {
                sgn = -1;
                c = read();
            }
            int res = 0;
            do {
                if (c < '0' || c > '9') {
                    throw new InputMismatchException();
                }
                res *= 10;
                res += c - '0';
                c = read();
            } while (!isSpaceChar(c));
            return res * sgn;
        }

        public boolean isSpaceChar(int c) {
            if (filter != null) {
                return filter.isSpaceChar(c);
            }
            return isWhitespace(c);
        }

        public static boolean isWhitespace(int c) {
            return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        }

        public interface SpaceCharFilter {
            public boolean isSpaceChar(int ch);

        }

    }
}



Measured memory_bytes: 32332
#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
using namespace std;
typedef long long ll;
typedef unsigned int ui;
const ll mod = 1000000007;
const ll INF = (ll)1000000007 * 1000000007;
typedef pair<int, int> P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef long double ld;
typedef complex<ld> Point;
const ld eps = 1e-11;
const ld pi = acos(-1.0);
typedef pair<ll, ll> LP;
typedef pair<ld, ld> LDP;
typedef unsigned long long ul;
int n;
ll a[1 << 17], b[1 << 17];
int main() {
	cin >> n;
	rep(i, n) {
		cin >> a[i];
	}
	rep(i, n) {
		cin >> b[i];
	}
	vector<ll> s;
	ll sum = 0; int ans = 0;
	rep(i, n) {
		if (a[i] < b[i]) {
			ans++; sum += b[i] - a[i];
		}
		else {
			s.push_back(a[i] - b[i]);
		}
	}
	sort(s.begin(), s.end(), greater<ll>());
	rep(i, s.size()) {
		if (sum <= 0)break;
		ans++;
		sum -= s[i];
	}
	if (sum > 0)cout << -1 << endl;
	else cout << ans << endl;
	//stop
		return 0;
}


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

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

#define RFOR(i, b, a) for(int(i)=(b); (i)>=(a); (i)--)
#define RREP(i, n) FOR((i), (n), 0)

#define pb push_back
#define mp make_pair 

using namespace std;

const int INF=INT_MAX/4;
const int MOD=1000000007;
const double EPS=1e-14;

const bool debug_flag=true;

void debug(string str){
	if(debug_flag){
		cout<<str<<endl;
	}
}

void debugs(string str){
	if(debug_flag){
		cout<<str;
	}
}

long n=1, a=1, b=1, c=1, d=1;

bool check(int m){
	return m*c-(n-1-m)*d<=b-a && b-a<=m*d-(n-1-m)*c;
}

int main(int argc, char* argv[]){
	cin.tie(0);
	ios::sync_with_stdio(0);
	cout.precision(10);

	cin>>n>>a>>b>>c>>d;
	cin>>n>>a>>b>>c>>d;
	for(int i=0; i<n-1; ++i){
		if(check(i)){
			cout<<"YES"<<endl;
			return 0;
		}
	}
	cout<<"NO"<<endl;

	return 0;
}



Measured memory_bytes: 256
#include <iostream>

using namespace std;

#define MAX 100005
#define NIL -1

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

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

void print(int u)
{
	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 (int i = 0, c = T[u].l; c != NIL; ++i, c = T[c].r)
	{
		if (i)
		{
			cout << ", ";
		}
		cout << c;
	}
	cout << "]" << endl;
}

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

void solve()
{
	cin >> n;
	for (int i = 0; i < n; ++i)
	{
		T[i].p = T[i].l = T[i].r = NIL;
	}
	int c, l, r;
	for (int i = 0; i < n; ++i)
	{
		int v, d;
		cin >> v >> d;
		for (int 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 (int i = 0; i < n; ++i)
	{
		if (T[i].p == NIL)
		{
			r = i;
		}
	}
	rec(r, 0);
	for (int i = 0; i < n; ++i)
	{
		print(i);
	}
}

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

Measured memory_bytes: 5840
#include<bits/stdc++.h>
#include<iostream>
#include<algorithm>
#include<numeric>
#include<string>
using namespace std;
int main(){
    int A,B,K;
    cin>>A>>B>>K;
    int cnt=0;
    for(int i=min(A,B);1<=i;i--){
        if(A%i==0 && B%i==0){
            cnt++;
            if(cnt==K){
                cout<<i<<endl;
                return 0;
            }
        }
    }
}

Measured memory_bytes: 256
import java.util.Scanner;

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

		int sen = S / 1000;
		int hyaku = (S % 1000) / 100;
		int zyu = (S % 100) / 10;
		int iti = S % 10;

//		System.out.println(sen);
//		System.out.println(hyaku);
//		System.out.println(zyu);
//		System.out.println(iti);

		int ue = sen * 10 + hyaku;
		int sita = zyu * 10 + iti;

//		System.out.println(ue);
//		System.out.println(sita);

		if (ue >= 1 && ue <= 12) {
			if (!(sita >= 1 && sita <= 12)) {
				System.out.println("MMYY");
			}
		}
		if (sita >= 1 && sita <= 12) {
			if (!(ue >= 1 && ue <= 12)) {
				System.out.println("YYMM");
			}
		}
		if (ue >= 1 && ue <= 12) {
			if (sita >= 1 && sita <= 12) {
				System.out.println("AMBIGUOUS");
			}
		}

		if (!(ue >= 1 && ue <= 12)) {
			if (!(sita >= 1 && sita <= 12 )) {
				System.out.println("NA");
			}
		}
		}
	}


Measured memory_bytes: 21716
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <cmath>
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
using namespace std;

int main(){
  int X,Y;
  int asi;
  int judge = 0;
  cin >> X >> Y;
  for(int i = 0;i <=X;i++){
    asi = 2*i + 4*(X-i);
    if(asi == Y){
      judge = 1;
      break;
    }
  }
  if(judge == 1){
    cout << "Yes" << endl;
  }else{
    cout << "No" << endl;
  }
}


Measured memory_bytes: 3620
#include <iostream>
#include <string>
#include <algorithm>

using namespace std;

int main(){
    int count = 0;
    string s,rs;
    cin >> s;
    rs = s;

    reverse(rs.begin(),rs.end());

    for(int i = 0;i < s.size();i++)
        if(s[i] != rs[i])count++;

    cout << count/2 << endl;
    return 0;
}

Measured memory_bytes: 256
import numpy as np

N = int(input())
a_str = input().split()
a = np.zeros(N)

for i in range(N):
  a[i] = int(a_str[i])

mu = np.average(a)
diff = a - mu
abs_diff = np.abs(diff)

min = np.amin(abs_diff)
index = np.where(abs_diff == min)

print(index[0][0])

Measured memory_bytes: 18216
import math  # noqa
import bisect  # noqa
import queue  # noqa


if __name__ == '__main__':
    N, K = map(int, input().split())

    cumsum = [0 for _ in range(N + 1)]
    cumsum[0] = 0
    for i in range(1, N + 1):
        cumsum[i] = i + cumsum[i - 1]

    MOD = 1_000_000_007
    ans = 1
    for k in range(K, N + 1):
        ans += (cumsum[N] - cumsum[-(k + 1)]) - cumsum[k - 1] + 1
        ans %= MOD

    print(ans)


Measured memory_bytes: 85796
#include<iostream>
#include<map>
#include<cmath>
typedef long long ll;
using namespace std;
ll n, cnt00 = 0,cnta0=0,cntb0=0,a,b;
const ll p = 1000000007;
ll gcd(ll a, ll b) {
	return b == 0 ? a : gcd(b, a % b);
}
void ins(map<pair<ll,ll>,pair<ll,ll>>& m, ll a,ll b) {
	ll g = gcd(abs(a), abs(b));
	a = a / g;
	b = b / g;
	if (a < 0) {
		a = -a;
		b = -b;
	}
	pair<ll, ll> p1(a, b);
	if (b > 0) {
		a = -a;
		b = -b;
	}
	pair<ll, ll> p2(-b, a);
	if (m.find(p1) == m.end()) {
		if (m.find(p2) == m.end()) {
			m[p1].first = 1;
			m[p1].second = 0;
		}
		else m[p2].second++;
	}
	else m[p1].first++;
}
ll pow2(ll k) {
	ll c = 2;
	ll f = 1;
	for (ll bit = 1; bit <= k; bit <<= 1) {
		if (k & bit)f = f * c % p;
		c = c * c % p;
	}
	return f;
}
int main() {
	cin >> n;
	map<pair<ll,ll>, pair<ll, ll>> line_map;
	for (int i = 0; i < n; i++) {
		cin >> a >> b;
		if (b == 0) {
			if (a == 0)cnt00++;
			else cntb0++;
		}
		else if (a == 0) {
			cnta0++;
		}
		else ins(line_map, a, b);
	}
	ll ans = 1;
	for (auto i = line_map.begin(); i != line_map.end(); ++i) {
		ll& cnt1 = i->second.first;
		ll& cnt2 = i->second.second;
		ans = (ans * (pow2(cnt1)+pow2(cnt2) - 1)+ p) % p;
	}
	ans = (ans * (pow2(cnta0) + pow2(cntb0) - 1)-1 +cnt00+ p) % p;
	cout << ans;
}

Measured memory_bytes: 19100
//Himanshu Shukla
#pragma GCC optimize("O2")
#include <bits/stdc++.h>
using namespace std;
#define FASTIO ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0)
//#define file_input
//#define multitest
//#define measure_time
#define ll long long
#define v32 vector<int>
#define v64 vector<ll>
#define s32 set<int>
#define s64 set<ll>
#define graph vector<v32>
#define p32 pair<int, int>
#define p64 pair<ll, ll>
#define sz(v) (ll)(v).size()
#define fi first
#define se second
#define ln '\n'
#define debug(x) cerr << (#x) << ": " << (x) << ln
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
inline ll add(ll a, ll b, ll m) { return (((a % m + b % m) % m + m) % m); }
inline ll mul(ll a, ll b, ll m) { return (((a % m * b % m) % m + m) % m); }
const double EPS = 1e-6;
const ll MOD = 1e9 + 7;
template <typename T, typename U>
ostream &operator<<(ostream &out, const pair<T, U> &p)
{
	out << '[' << p.fi << ", " << p.se << ']';
	return out;
}
template <template <typename, typename...> class ContainerType, typename ValueType, typename... Args>
void print_container(const ContainerType<ValueType, Args...> &c)
{
	cout << "{ ";
	for (const auto &v : c)
		cout << v << ' ';
	cout << '}' << ln;
}

void solve()
{
	ll k;
	cin >> k;
	ll sum = 0;
	for (int i = 1; i < k + 1; i++)
	{
		for (int j = 1; j < k + 1; j++)
		{
			for (int l = 1; l < k + 1; l++)
			{
				sum += __gcd(i, __gcd(j, l));
			}
		}
	}
	cout << sum << ln;
	return;
}

int main()
{
	FASTIO;
#ifdef file_input
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	clock_t start, stop;
	int t = 1;
#ifdef multitest
	cin >> t;
#endif
#ifdef measure_time
	start = clock();
#endif
	for (int tc = 1; tc < t + 1; tc++)
		solve();
#ifdef measure_time
	stop = clock();
	cerr << "Time :" << fixed << setprecision(5) << double(stop - start) / double(CLOCKS_PER_SEC) << "s" << ln;
#endif
	return 0;
}


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

int main(){
  int N,X,count=0,sum=0;
  cin >> N >> X;
  vector<int> M(N);
  for(int i=0;i<N;i++){
    cin >> M.at(i);
    sum+=M.at(i);
    count++;
  }
  sort(M.begin(),M.end());
  while(sum+M.at(0)<=X){
    sum+=M.at(0);
    count++;
  }
  cout << count << endl;
}
  

Measured memory_bytes: 3628
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;


int main()
{
    ll N, M;
    cin >> N >> M;
    if(2>N || N>100000){
        return 0;
    }
    if(1>M || M>100000){
        return 0;
    }

    ll H[N], t[N];
    REP(i, N){
        cin >> H[i];
        if(1>H[i] || H[i]>1000000000){
            return 0;
        }
        t[i] = 1;
    }

    ll A[M], B[M];
    REP(i, M){
        cin >> A[i] >> B[i];
        if(1>A[i] || A[i]>N || 1>B[i] || B[i]>N){
            return 0;
        }
        if(A[i]==B[i]){
            return 0;
        }
    }

    int ans=0, tmp=0;
    /*REP(i, N){
        tmp = 0;
        if(C[i]==1){
            REP(j, M){
                if(A[j]==i+1){
                    if(H[B[j]-1] >= H[i]){
                        tmp = 1;
                        break;
                    }
                }
                if(B[j]==i+1){
                    if(H[A[j]-1] >= H[i]){
                        tmp = 1;
                        break;
                    }
                }
            }
            if(tmp==0){
                //cout << i+1 << "\n";
                ans++;
            }
        }
        else{
            ans++;
        }
    }*/

    REP(i, M){
       if(H[A[i]-1] > H[B[i]-1]){
           t[B[i]-1] = 0;
           //cout << B[i] << H[B[i]-1] << "\n";
       }
       else if(H[A[i]-1] < H[B[i]-1]){
           t[A[i]-1] = 0;
           //cout << A[i] << H[A[i]-1] << "\n";
       }
       else if(H[A[i]-1]==H[B[i]-1]){
           t[A[i]-1] = 0;
           t[B[i]-1] = 0;
           //cout << A[i] << H[A[i]-1] << B[i] << H[B[i]-1] << "\n";
       }
    }

    REP(i, N){
        ans += t[i];
    }

    cout << ans;

    
    return 0;

}

Measured memory_bytes: 6644
#include<stdio.h>
int gcd(int a, int b){
	if(!b) return a;
	return gcd(b, a%b);
}
int main(void){
	int big, small, kyk, kbi, tmp;
	while(scanf("%d %d", &small, &big) != EOF){
		if(small>big){
			tmp=big;
			big=small;
			small=tmp;
		}
		kyk = gcd(big, small);
		kbi = big / kyk * small;
		printf("%d %d\n", kyk, kbi);
	}
	return 0;
}

Measured memory_bytes: 596
#include<iostream>
#include<math.h>
#include<algorithm>
#include<string.h>
using namespace std;
main(){
    int x,y;
    cin>>x;
    cin>>y;
    int a[53][53]={};
    int count=0;
    for(int i=1;i<=x;i++){
        string b;
        cin>>b;
        for(int j=0;j<y;j++){
            if(b[j]=='.') {
                a[i][j+1]=1;
                count++;
            }
        }   
    }
    a[1][1]=3;

    for(int k=1;k++;k<x*y){
        int flag=0;
        for(int i=1;i<=x;i++){
            for(int j=1;j<=y;j++){
                if(a[i][j]==1){
                    if(a[i-1][j]==3) a[i][j]=2;
                    else if(a[i+1][j]==3) a[i][j]=2;
                    else if(a[i][j-1]==3) a[i][j]=2;
                    else if(a[i][j+1]==3) a[i][j]=2;
                }
            }
        }
        
        for(int i=1;i<=x;i++){
            for(int j=1;j<=y;j++){
                if(a[i][j]==2) {
                    a[i][j]=3;
                    flag=1;
                }
            }
            
        }
       
        if(a[x][y]==3) {
            count-=k;
            break;
            
        }
        if(flag==0) break;
    }
    if(a[x][y]==3){
        cout<<count;
    }
else cout<<-1;
    
    return 0;
 
}

Measured memory_bytes: 256
#include <iostream>
#define REP(i, n) for(int (i) = 0; (i) < (n); (i)++)
#define BIGNUM 999
using namespace std;

int main()
{
  typedef pair<int, int> pii;
  int n, m;
  while(1){
    cin >> n >> m;
    if(n == 0 && m == 0){
      break;
    }else{
      pii ans;
      int t[n], h[m];
      int ts, hs, anss;
      ts = hs = 0;
      ans.first = ans.second = 0;
      anss = BIGNUM;
      REP(i, n){
        cin >> t[i];
        ts += t[i];
      }
      REP(i, m){
        cin >> h[i];
        hs += h[i];
      }
      if(ts < hs){
        int sub = hs - ts;
        REP(i, n){
          REP(j, m){
            if(t[i] <= h[j] && (h[j] - t[i]) * 2 == sub)
              if(t[i] + h[j] < anss){
                ans.first = t[i];
                ans.second = h[j];
                anss = ans.first + ans.second;
              }
          }
        }
      }else if(ts == hs){
        REP(i, n){
          REP(j, m){
            if(t[i] == h[j])
              if(t[i] + h[j] < anss){
                ans.first = t[i];
                ans.second = h[j];
                anss = ans.first + ans.second;
              }
          }
        }
      }else{
        int sub = ts - hs;
        REP(i, m){
          REP(j, n){
            if(h[i] <= t[j] && (t[j] - h[i]) * 2 == sub)
              if(t[i] + h[i] < anss){
                ans.first = t[j];
                ans.second = h[i];
                anss = ans.first + ans.second;
              }
          }
        }
      }
      if(ans.first == 0)
        cout << "-1" << endl;
      else
        cout << ans.first << " " << ans.second << endl;
    }
  }
}

Measured memory_bytes: 1160
import math
lis = []
n,m = map(int,input().split())
for i in range(1,math.ceil(math.sqrt(m))+1):
  if m % i == 0:
    lis.append(i)
    lis.append(m//i)
lis.sort()
cou = 0
ans = 0
for i in range(len(lis)):
  if m % lis[i] == 0 and m // lis[i] >= n:
    ans = max(ans,lis[i])
print(ans)

Measured memory_bytes: 3064
import java.util.*;


 
public class Main {

    public static void main(String args[])  {
    	Scanner sc = new Scanner(System.in);
    	int a=sc.nextInt();
    	String c =sc.next();
       //System.out.print(c);
    	if(c.length() <=a) {
    		System.out.print(c);
    	}else {
    	 String b =c.substring(0,a);
    	 b=b+"...";
    	 System.out.print(b);
    	}


    }
}

Measured memory_bytes: 38660
#include <stdio.h>
int main()
{
  int dice[6],q,ins[2],p0,p1,p2,p3;
  int vector[6][4]={{4,2,1,3},{0,2,5,3},{0,4,5,1},{0,1,5,4},{0,3,5,2},{1,2,4,3}};
  int i,j;
  for(i=0;i<6;i++)
  {
    scanf(" %d",&dice[i]);
  }
  scanf(" %d",&q);
  for(i=0;i<q;i++)
  {
    for(j=0;j<2;j++)
    {
      scanf(" %d",&ins[j]);
    }
    for(j=0;j<6;j++)
    {
      if(dice[j]==ins[0])p0=j;
    }
    for(j=0;j<6;j++)
    {
      if(dice[j]==ins[1])p1=j;
    }
    for(j=0;j<4;j++)
    {
      if(vector[p0][j]==p1)p2=j;
    }
    if(p2==0)printf("%d\n",dice[vector[p0][3]]);
    else printf("%d\n",dice[vector[p0][p2-1]]);
  }
  return 0;
}

Measured memory_bytes: 596
# まさかの
# 問題文をちゃんと読もう 文ってか制約
n = int(input())
arr = list(map(int, input().split()))
ans = 10e9
for t in range(-100, 101):
    ans_tmp = 0
    for v in arr:
        ans_tmp += abs(t - v)**2
    ans = min(ans, ans_tmp)

print(ans)


Measured memory_bytes: 38896
#include<stdio.h>
int main(void){
	int N=0,i=0,a=0,pal=0;
	char mozi[1001];
	scanf("%d",&N);
	while(N!=0){
		N--;
		scanf("%s",mozi);
		for(i=0;i<1000;i++){
			a=mozi[i]-39;//??°???+9
			if(a<9||a>18){break;}//0<=??°???<=9
			pal+=a;
		}
		pal%=18;
			if(9<pal||pal==0){printf("Audrey wins.\n");}else{printf("Fabre wins.\n");}
		pal=0;
	}
	return 0;
}

Measured memory_bytes: 2608
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <stdbool.h>
#include <math.h>

long long x[900000][2];

int l(long long x1, long long x2, long long y1, long long y2){
    if(x1 == y1){
        return x2 < y2;
    }else{
        return x1 < y1;
    }
}

void func(long long s, long long t){
    long long c[2];
    long long i = s, j = t;

    c[0] = x[s][0];
    c[1] = x[s][1];

    if(s < t){
        while(1){
            while(l(x[i][0], x[i][1], c[0], c[1])){
                i++;
            }
            while(l(c[0], c[1], x[j][0], x[j][1])){
                j--;
            }
            if(i >= j){
                break;
            }
            x[i][0] ^= x[j][0] ^= x[i][0] ^= x[j][0];
            x[i][1] ^= x[j][1] ^= x[i][1] ^= x[j][1];
            i++;
            j--;
        }
        func(s, i-1);
        func(j+1, t);
    }
}

int main(void){

    long long H, W, N;

    scanf("%lld%lld%lld", &H, &W, &N);

    long long a[N], b[N];
    long long a2, b2;
    long long n2 = 0;

    for(long long i = 0; i < N; i++){
        scanf("%lld%lld", &a[i], &b[i]);
        for(long long j = 0; j < 3; j++){
            for(long long k = 0; k < 3; k++){
                a2 = a[i] - j;
                b2 = b[i] - k;
                if(a2 > 0 && a2 < H - 1 && b2 > 0 && b2 < W - 1){
                    x[n2][0] = b2;
                    x[n2][1] = a2;
                    n2++;
                }
            }
        }
    }

    long long d[2], z[10];

    for(long long i = 0; i < 10; i++){
        z[i] = 0;
    }

    func(0, n2-1);

    d[0] = x[0][0];
    d[1] = x[0][1];

    long long m = 0;

    for(long long i = 1; i < n2; i++){
        m++;
        if(x[i-1][0] != x[i][0] || x[i-1][1] != x[i][1]){
            z[m]++;
            m = 0;
        }
    }

    if(n2){
        z[m+1]++;
    }
    z[0] = (H-2)*(W-2);

    for(long long i = 1; i < 10; i++){
        z[0] -= z[i];
    }

    for(long long i = 0; i < 10; i++){
        printf("%lld\n", z[i]);
    }

    return 0;
}

Measured memory_bytes: 17348
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner sc = new Scanner(System.in);
		int[][] c = new int[3][3];
		for(int i=0;i<3;i++) {
			for(int j=0;j<3;j++) {
				c[i][j]=sc.nextInt();
			}
		}
		int kari=c[0][0]+c[1][1]+c[2][2];
		boolean hanbetsu = true;

		for(int i=0;i<3;i++) {
			for(int j=0;j<3;j++) {
				if((c[i][j]+c[(i+1)%3][(j+1)%3]+c[(i+2)%3][(j+2)%3]!=kari)) {

					hanbetsu=false;
					break;
					}
				}
			}
		if(hanbetsu)
			System.out.print("Yes");
		else
			System.out.print("No");

	}

}


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

int main() {
	int n;
	cin >> n;
	int a, b;
	a = n / 10;//10の位
	b = n % 10;//1の位
	if (a == 9 || b == 9)cout << "Yes";
	else cout << "No";
}

Measured memory_bytes: 256
#include <vector>
#include <iostream>
#include <cmath>
#include <map>
#include <unordered_map>
#include <algorithm>
#include <fstream>
#include <unistd.h>
#include <string.h>
#include <string>
#include <numeric>
#include <queue>
#include <deque>
#include <sstream>
#include <iomanip>
#include <set>
#include <stack>
#include <cassert>
#include <functional>
#include <random>
using namespace std;
typedef int64_t ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<vvl> vvvl;
typedef vector<vvvl> vvvvl;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;
typedef vector<bool> vb;
typedef vector<vector<bool>> vvb;
typedef vector<vvb> vvvb;
typedef vector<vvvb> vvvvb;
typedef vector<string> vs;
typedef vector<vs> vvs;
typedef vector<vvs> vvvs;
typedef vector<char> vc;
typedef vector<vector<char>> vvc;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<vvd> vvvd;
typedef pair<ll, ll> PL;
typedef vector<PL> vpl;
typedef vector<vector<PL>> vvpl;
typedef vector<vvpl> vvvpl;
typedef pair<ll, PL> TL;
typedef vector<TL> vtl;
typedef vector<vtl> vvtl;
typedef long double ld;
typedef vector<ld> vld;
const int INF = 1001001001;
const ll LINF = 1e18;
const double pi = 3.1415926535897932;
const string endstr = "\n";
#define FOR(i, a, b) for(ll i = (a); i < b; i++)
#define RFOR(i, a, b) for(ll i = (a); i > b; i--)
#define rep(i, n) for(ll i = 0; i < n; i++)
#define rrep(i, n) for(ll i = n-1; i > -1; i--)
#define FORMAP(it, m) for(auto it = m.begin(); it != m.end(); it++)
#define ff first
#define ss second
#define pb push_back
#define epb emplace_back
#define ALL(X) (X).begin(),(X).end()

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

bool p_comp_fs(const PL p1, const PL p2){ return p1.first < p2.first;};
bool p_comp_fg(const PL p1, const PL p2){ return p1.first > p2.first;};
bool p_comp_ss(const PL p1, const PL p2){ return p1.second < p2.second;};
bool p_comp_sg(const PL p1, const PL p2){ return p1.second > p2.second;};
template <typename T>
vector<T> uniquen(vector<T> vec /* copy */){
    sort(ALL(vec));
    vec.erase(unique(vec.begin(), vec.end()), vec.end());
    return vec;
}

inline ll popcnt(ll x){return __builtin_popcountll((unsigned long long)x);};
template<class T> bool chmax(T &a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> bool chmin(T &a, T b) { if (a > b) { a = b; return true; } return false; }
//friend bool operator<(const tpl& lhs, const tpl& rhs){
//    return std::tie(lhs.l, lhs.r) < std::tie(rhs.l, rhs.r);
//}



int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    ll X; cin >> X;
    ll cnt = 0;
    ll rem = X%100; ll remo = rem;
    for(ll r = 5; r >= 1; r--){
        ll q = rem / r;
        cnt += q;
        rem -= q*r;
    }
    
    bool ok = false;
    if(cnt * 100 + remo <= X){
        ok = true;
    }
    cout << (ok ? 1 : 0) << endstr;
    return 0;
}


Measured memory_bytes: 256
#! /usr/bin/env python3
# -*- coding: utf-8 -*-
N = int(input())
def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)

    # divisors.sort()
    return divisors

ls = make_divisors(N)
count =0
for i in ls:
    if N/i -1 >= 1 and i < N/i-1:
        count+= N/i -1 
    

print(int(count))

Measured memory_bytes: 3272
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<string,int> P;
int main(void){
	int n; cin>>n;
	P p[105],q[105];
	for(int i=0;i<n;i++){
		cin>>p[i].first>>p[i].second;
		p[i].second*=(-1);
		q[i].first=p[i].first;
		q[i].second=p[i].second;
	}
	sort(p,p+n);
	for(int i=0;i<n;i++){
		for(int j=0;j<n;j++){
			if(p[i]==q[j]){
				cout<<j+1<<endl;
			}
		}
	}
	
}


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

using namespace std;
typedef long long ll;

#define rep(i, N) for (int i = 0; i < (int)N; i++)
const ll MOD = pow(10,9)+7;
const ll LLINF = pow(2,61)-1;
const int INF = pow(2,30)-1;

int main() {
  int N, M; cin >> N >> M;
  map<int, int> X; rep(i,N) { int tmp; cin >> tmp; X[tmp]++; }
  int odd[M] = {}, p[M] = {};
  for (auto x: X) {
    int mo = x.first%M;
    if (x.second%2==1) odd[mo]++;
    p[mo] += x.second/2;
  }
  // rep(i,M) cout << i << ":" << odd[i] << "&" << p[i] << endl;
  ll result = 0;
  rep(i,M/2+1) {
    if (i==0||i*2==M) { result += odd[i]/2 + p[i]; continue; }
    if (odd[i]<odd[M-i]) {
      result += odd[i];
      result += p[M-i];
      int left = odd[M-i]-odd[i];
      result += (left>=p[i]*2) ? p[i]*2 : (left/2+p[i]);
    }
    else {
      result += odd[M-i];
      result += p[i];
      int left = odd[i]-odd[M-i];
      result += (left>=p[M-i]*2) ? p[M-i]*2 : (left/2+p[M-i]);
    }
  }
  cout << result << endl;
  return 0;
}

Measured memory_bytes: 5760
#include <iostream>
#include <cmath>
#include <cstdio>
using namespace std;
double N, K;

void input() {
    cin >> N >> K;
}
double solve() {
    double ans = 0;
    for(int i = 1; i <= static_cast<int>(N); i++) {
        double tmp = i;
        double cnt = 0;
        while(tmp < K) {
            cnt++;
            tmp *= 2;
        }
        ans += 1/N * pow(0.5, cnt);
    }
    return ans;
}
int main() {
    input();
    printf("%.12lf", solve());
}

Measured memory_bytes: 256
solv a b k = go (max a b) (k-1) where
  go n k
    | a`mod`n==0 && b`mod`n==0
      = if k==0 then n else go (n-1) (k-1)
    | otherwise = go (n-1) k

main = do
  [a,b,k] <- map read . words <$> getLine
  print $ solv a b k


Measured memory_bytes: 508
#include <bits/stdc++.h>
const long long INF = LLONG_MAX / 2;
const long long MOD = 1000000007;
const long double PI = 3.1415926;
#define FOR(i, r, n) for(int i=(ll)(r); i<(ll)(n); i++) 
#define REP(i, n) FOR(i, (0), n)
#define ll long long int
using namespace std;
ll ans = 0, sum = 0, n, k, counter = 0, w, h;
string s;
vector<ll> v;
vector<pair<ll, ll>> vp;
vector<vector<ll>> vv(50, vector<ll>(50, INF));

int main()
{
	cin >> s;
	FOR(i,1,s.size())
		if (s[i] != s[i - 1]) ans++;
	cout << ans << endl;
}


Measured memory_bytes: 512
#include<iostream>
#include<cmath>
#include<vector>
#include<algorithm>
#include<numeric>
using namespace std;
using uint = unsigned int;
using ull = unsigned long long;

bool judge(const ull K, const ull T, const vector<uint>& A, const vector<uint>& F) {
	
	ull sum = 0;
	for(ull i = 0; i<A.size(); i++) {
		ull d = T / F[i];
		if (A[i] > d) {
			sum += A[i] - d;
			if (sum > K) {
				return false;
			}
		}
	}
	return true;
}

int main() {
	ull N, K;
	cin >> N >> K;
	
	vector<uint> A(N);
	ull sum = 0;
	for (uint n=0; n<N; n++) {
		cin >> A[n];
		sum += A[n];
	}
	
	if (K >= sum) {
		cout << 0;
		return 0;
	}
	
	vector<uint> F(N);
	for (uint n=0; n<N; n++) {
		cin >> F[n];
	}
	
	sort(A.begin(), A.end());
	sort(F.begin(), F.end(), greater<uint>());
	
	ull low = 0;
	ull high = 0;
	
	for (uint n=0; n<N; n++) {
		high = max(high, ull(A[n]) * ull(F[n]));
	}
	
	while (low < high) {
		ull mid = (low + high) / 2;
 
		if (judge(K, mid, A, F)) {
			high = mid;
		} else {
			low = mid + 1;
		}
	}
	
	cout << low;
	
	return 0;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
int main(void){
    int N;
    cin>>N;
    vector<tuple<string,int,int>> a;
    for(int i=0;i<N;i++){
        string x;
        int b;
        cin>>x>>b;
        a.push_back(make_tuple(x,-b,i+1));
    }
    sort(a.begin(),a.end());

    for(int i=0;i<N;i++){
    cout<<get<2>(a.at(i))<<endl;
    }
}


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

char S[12];
int N;
long long dp[11];
int F[11];
long long eval(int i, int j){
  long long ret = 0;
  while (i <= j){
    ret = ret*10 + (S[i]-'0');
    i++;
  }
  return ret;
}
long long solve(int i){
  if (i >= N) return 0;
  long long& ret = dp[i];
  if (ret != 0) return ret;
  for (int j=i; j<N; j++){
    long long x = eval(i, j);
    ret += x*F[N-j-1] + solve(j+1);
  }
  return ret;
}
int main(){
  scanf("%s",S);
  N = strlen(S);
  F[0] = F[1] = 1;
  for (int i=2; i<N; i++){
    F[i] = 1;
    for (int j=1; j<i; j++){
      F[i] += F[j];
    }
  }
  printf("%lld\n", solve(0));
  return 0;
}

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

int main(){
	
	ll n;
	cin >> n;
	vector<ll> a(n);
	rep(i,n) cin >> a[i];
	
	rep(i,n){
		if(a[i] > i){
			cout << -1 << endl;
			return 0;
		}
		if(i-1>=0 && a[i] - a[i-1] >= 2){
			cout << -1 << endl;
			return 0;
		}
	}
	
	
	ll res = 0;
	rep(i,n){
		res += a[i];
		if(i-1>=0 && a[i] - a[i-1] == 1) res -= a[i-1];
	}

	cout << res << endl;
	return 0;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define REP(i,n) for(ll i=0, i##_len=(n); i<i##_len; ++i)
#define REPR(i,n) for(ll i = n;i >= 0;--i)
#define FOR(i,m,n) for(ll i = m, i##_len=(n);i <i##_len; ++i)
#define all(x) (x).begin(),(x).end()
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
const int INF = 1e9;
const ll LLINF = 1e16;
 
int main(void)
{
    int N,M;
    cin >> N>> M ;
    int x,y;
    x=N+M;

    y=(x-1)*x/2-N*M;

    cout<< y <<endl;



    return 0;
}


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

using namespace std;

typedef long long int ll;
const int INF = 1<<30;
const long long LINF = 1LL<<60;

int main(){
    int a, b, ans = 0;
    cin >> a >> b;
    int c = a + b;
    if(c % 2 == 1){
        cout << "IMPOSSIBLE" << endl;
    }else{
        cout << c / 2 << endl;
    }
    return 0;
}


Measured memory_bytes: 256
HANDS = {
    'one pair': [1,1,1,2],
    'two pair': [1,2,2],
    'three card': [1,1,3],
    'four card': [1,4],
    'full house': [2,3],
}

def check(key, value):
    for (k, v) in HANDS.iteritems():
        if value == v:
            return k
    if key[-1] - key[0] == 4 or key == [1, 10, 11, 12, 13]:
        return 'straight'
    else:
        return 'null'

while True:
    try:
        cards = map(int, raw_input().split(','))
        m = {}
        for n in cards:
            if m.has_key(n):
                m[n] += 1
            else:
                m[n] = 1
        print check(sorted(m.keys()), sorted(m.values()))
    except EOFError:
        break

Measured memory_bytes: 6560
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cmath>
#include <cstdlib>
#include <tuple>

using ll = long long;
using namespace std;
#define modmod 1000000007

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


int main(){
    ll N, K;
    cin >> N >> K;
    ll a[N],b[N];
    ll U[100003] = {0};
    for(int i = 0; i< N; i++){
        cin >> a[i] >> b[i];
        U[a[i]]+=b[i];
    }
    ll result = 0;
    for(int i = 1; i <= 100003; i++){
        result += U[i];
        if(result >= K){
            cout << i << endl;
            return 0;
        }
    }

    return 0;
}


Measured memory_bytes: 2560
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define len(arr) (int)(sizeof(arr)/sizeof((arr)[0]))
#define Sort(arr) sort(arr,arr+len(arr))
#define For(i,s,n) for(int i=s;i<n;i++)	
#define Rep(i,n) for(int i=0;i<n;i++)
#define Per(i,n) for(int i=n;i>=0;i--)
#define All(x) (x).begin(),(x).end()
#define in(arr,n) Rep(i,n) cin >> arr[i];
#define in2(arr1,arr2,n) Rep(i,n) cin >> arr1[i] >> arr2[i];
#define in3(arr1,arr2,arr3,n) Rep(i,n) cin >> arr1[i] >> arr2[i] >> arr3[i];
#define LL_MAX 9223372036854775807
#define LL_MIN -9223372036854775808
#define MOD 1000000007
#define MOD9 1000000009

//{ ライブラリ

// 標準出力の高速化
#define endl "\n"

// 出力
template<typename Type>
void print(Type a[],int n){
	Rep(i,n) cout << a[i] << endl;
}
template<typename Type1,typename Type2>
void print(Type1 a[],Type2 b[],int n){
	Rep(i,n) cout << a[i] << " " << b[i] << endl;
}
template<typename Type1,typename Type2,typename Type3>
void print(Type1 a[],Type2 b[],Type3 c[],int n){
	Rep(i,n) cout << a[i] << " " << b[i] << " " << c[i] << endl;
}

// 配列の最大値
template<typename Type>
Type max(Type a[],int n){
	Type ret=a[0];
	For(i,1,n) ret=max(ret,a[i]);
	return ret;
}

// 配列の最小値
template<typename Type>
Type min(Type a[],int n){
	Type ret=a[0];
	For(i,1,n) ret=min(ret,a[i]);
	return ret;
}

// 最大公約数
template<typename Type>
Type gcd(Type a,Type b){return(b==0)?a:gcd(b,a%b);}
template<typename Type>
Type gcd(Type a[],int n){
	Type ret=a[0];
	For(i,1,n) ret=gcd(ret,a[i]);
	return ret;
}

// 最小公倍数
template<typename Type>
Type lcm(Type a,Type b){return (a/gcd(a,b))*b;}
template<typename Type>
Type lcm(Type a[],int n){
	Type ret=a[0];
	For(i,1,n) ret=lcm(ret,a[i]);
	return ret;
}

// aを元にしてペアでソート
template<typename Type1,typename Type2>
void PairSort(Type1 a[],Type2 b[],int left,int right){
	int i=left,j=right;
	Type1 p=a[(left+right)/2];
	while(true){
		while(a[i]<p) i++;
		while(p<a[j]) j--;
		if(i>=j) break;
		swap(a[i],a[j]);
		swap(b[i],b[j]);
		i++;j--;
	}
	if(left<i-1) PairSort(a,b,left,i-1);
	if(j+1<right) PairSort(a,b,j+1,right);
}
template<typename Type1,typename Type2,typename Type3>
void PairSort(Type1 a[],Type2 b[],Type3 c[],int left,int right){
	int i=left,j=right;
	Type1 p=a[(left+right)/2];
	while(true){
		while(a[i]<p) i++;
		while(p<a[j]) j--;
		if(i>=j) break;
		swap(a[i],a[j]);
		swap(b[i],b[j]);
		swap(c[i],c[j]);
		i++;j--;
	}
	if(left<i-1) PairSort(a,b,c,left,i-1);
	if(j+1<right) PairSort(a,b,c,j+1,right);
}

// 配列を逆順にする
template<typename Type>
void Reverse(Type a[],int n){Rep(i,n/2) swap(a[i],a[n-i-1]);}

// 文字列を逆順にする
// reverse(All(str));

//}

int main(){
	int N;
	cin >> N;
	vector<double> v;
	Rep(i,N){
		double a;
		cin >> a;
		v.push_back(a);
	}
	
	Rep(i,N-1){
		sort(v.begin(),v.end());
		v[0]=(v[0]+v[1])/2.0;
		v.erase(v.begin()+1);
	}
	cout << v[0];
}

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

int main(){
    double v;
    double y;
    int n = 1;

    while(cin >> v){
        n = 1;
        y = 4.9 * v * v / (9.8 * 9.8);
        while(y > 5 * n - 5){
            n++;
        }
        cout << n << endl;

    }

    return 0;
}

Measured memory_bytes: 0
#include<stdio.h>
int main(void)
{
  int r;
  int d;
  int x[11];
  int i;
  int a;
  
  scanf("%d",&r);
  scanf("%d",&d);
  scanf("%d",&a);
  x[0]=a;
  for(i=1;i<=10;i++){
    x[i] = r*x[i-1]-d;
  }
  for(i=1;i<=10;i++){
    printf("%d\n",x[i]);
  }
  
  return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
int n,m;
vector<int> adj[100000+5];
int par[100000+5],lvl[100000+5];
bool visited[100000+5];

bool bfs(){
    queue<int> pq;
    par[1] = 1;
    lvl[1] = 0;
    visited[1] = true;
    pq.emplace(1);

    while(!pq.empty()){
        auto top = pq.front();pq.pop();
        for(auto x : adj[top]){
            if(!visited[x]){
                visited[x] = true;
                par[x] = top;
                pq.emplace(x);
            }
        }
    }
    for(int i = 1;i<=n;i++)
        if(visited[i] == false)
            return false;

    return true;
}
int main(){
    cin>>n>>m;
    for(int i =0;i<m;i++){
        int u,v;cin>>u>>v;
        adj[u].pb(v);
        adj[v].pb(u);
    }
    if(bfs()){
        cout<<"Yes"<<endl;
        for(int i = 2;i<=n;i++)
            cout<<par[i]<<endl;

    }else{
        cout<<"No"<<endl;
    }


    return 0;
}

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

struct node{
  struct node *right;
  struct node *left;
  struct node *parent;
  int key;
};
typedef struct node * Node;
#define NIL NULL

Node root;

Node treeMinimum(Node x){
  while(x->left != NIL){
    x = x->left;
  }
  return x;
}

Node treeMaximum(Node x){
  while(x->right != NIL){
    x = x->right;
  }
 return x;

}

Node treeSearch(Node u, int k){
  if(u==NIL || k == u->key){
    return u;
  }
  if(k<u->key){
    return treeSearch(u->left,k);
  }
  else return treeSearch(u->right,k);
}

Node treeSuccessor(Node x){
  Node y;
  if(x->right != NIL){
    return treeMinimum(x->right);
  }
  y = x->parent;
  while(y != NIL && x == y->right){
    x = y;
    y = y->parent;
  }
  return y;

}

void treeDelete(Node z){
  Node y; // node to be deleted
  Node x; // child of y

  if(z->left==NIL || z->right== NIL){
    y = z;
  }
  else y = treeSuccessor(z);

  if(y->left != NIL){
    x = y->left;
  }
  else x = y->right;

  if(x!=NIL){
    x->parent= y->parent;
  }
  if(y->parent==NIL){
    root=x;
  }
  else if(y == y->parent->left){
    y->parent->left = x;
  }
  else y->parent->right = x;

  if(y != z){
    z->key = y->key;
  }
}

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

  z = malloc(sizeof(struct node));
  z->key = k;
  z->left = NIL;
  z->right = NIL;

  while(x!=NIL){
    y = x;
    if(z->key<x->key){
      x= x->left;
    }
    else x = x->right;
  }
  z->parent = y;
  if(y == NIL){
    root = z;
  }
  else if(z->key < y->key){
    y->left = z;
  }
  else y->right = z;
}

void inorder(Node u){
  if(u==NIL){
    return;
  }
  inorder(u->left);
  printf(" %d",u->key);
  inorder(u->right);
}
void preorder(Node u){
  if(u==NIL){
    return;
  }
  printf(" %d",u->key);
  preorder(u->left);
  preorder(u->right);
}


int main(){
  int n, i, x;
  char com[20];
  scanf("%d", &n);

  for ( i = 0; i < n; i++ ){
    scanf("%s", com);
    if ( com[0] == 'f' ){
      scanf("%d", &x);
      Node t = treeSearch(root, x);
      if ( t != NIL ) printf("yes\n");
      else printf("no\n");
    } else if ( com[0] == 'i' ){
      scanf("%d", &x);
      insert(x);
    } else if ( com[0] == 'p' ){
      inorder(root);
      printf("\n");
      preorder(root);
      printf("\n");
    } else if ( com[0] == 'd' ){
      scanf("%d", &x);
      treeDelete(treeSearch(root, x));
    }
  }

  return 0;
}



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

from fractions import Fraction

MODULUS = 10**9+7

def all_negative(arr):
    for _, s in arr:
        if s != -1: return False
    return True

def has_negative(arr):
    for _, s in arr:
        if s == -1: return True
    return False

def has_positive(arr):
    for _, s in arr:
        if s == 1: return True
    return False

def largest_negative(arr):
    candidates = []
    for a, s in arr:
        if s == -1: candidates += [a]
    return max(candidates)

def largest_positive(arr):
    candidates = []
    for a, s in arr:
        if s == 1: candidates += [a]
    return max(candidates)

def smallest_negative(arr):
    candidates = []
    for a, s in arr:
        if s == -1: candidates += [a]
    return min(candidates)

def smallest_positive(arr):
    candidates = []
    for a, s in arr:
        if s == 1: candidates += [a]
    return min(candidates)

def prod(arr, MODULUS=None):
    ret = 1
    for a in arr:
        ret *= a
        if MODULUS is not None:
            ret = ret % MODULUS
    return ret

def sgn(x):
    if x == 0: return 0
    if x > 0: return 1
    if x < 0: return -1
    assert(False)

N, K = input().split(' ')
K = int(K)

A = input().split(' ')
A = list(map(int, A))

def ans(A, K):

    if K == len(A):
        return prod(A, MODULUS)

    old_A = A
    A = [(abs(a), sgn(a)) for a in A]
    A = sorted(A)[::-1]

    if prod(s for (_, s) in A[0:K]) in [0, 1]:
        return prod([a for (a, _) in A[0:K]], MODULUS)

    chosen, not_chosen = A[0:K], A[K:]

    penalty_one = float("-inf")
    if has_positive(not_chosen):
        penalty_one = Fraction(largest_positive(not_chosen), smallest_negative(chosen))

    penalty_two = float("-inf")
    if has_positive(chosen) and has_negative(not_chosen):
        penalty_two = Fraction(largest_negative(not_chosen), smallest_positive(chosen))

    if penalty_one == float("-inf") and penalty_two == float("-inf"):
        if all_negative(chosen) and all_negative(not_chosen):
            A = A[::-1]
            return prod([a*s for (a, s) in A[0:K]], MODULUS)
        else:
            # print(chosen, not_chosen)
            assert(0 in old_A)
            return 0

    start = prod([a for (a, _) in chosen], MODULUS)

    penalty = max(penalty_one, penalty_two)

    start *= penalty.numerator
    start *= pow(penalty.denominator, MODULUS-2, MODULUS)

    start = ((start % MODULUS) + MODULUS) % MODULUS
    return start

# import random

# for _ in range(1000000):
#     test_case = [random.randint(-10, 10) for _ in range(5)]
#     # print(test_case)
#     ans(test_case, random.randint(0, 5))

print(ans(A, K))

Measured memory_bytes: 118292
import math
H, W = map(int, input().split())
if(H == 1 or W == 1):
    print(1)
else:
    w_odd = math.ceil(H/2)
    w_even = H // 2
    N_odd = math.ceil(W/2)
    N_even = W // 2
    print(w_odd * N_odd + w_even * N_even)

Measured memory_bytes: 38384
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < n; i++)
#define SIZE 100000
const double PI  = 3.1415926535897932384626433832795028841971;
const long long int    INF = 10000000000;
const double EPS = 1e-10;
const int    MOD = 1000000007;
using namespace std;
typedef long long ll;
typedef pair<int,int> P;

int n;
bool p[100000];
vector<ll> pr[3];
ll s[100000];
ll ama[100000];
int counter;
ll hiku;
map<ll,ll> m, num;
map<ll,ll>::iterator it;

void prime(){
	for(int i = 2; i < SIZE; i++){
		if(p[i]) continue;
		for(int j = i*2; j < SIZE; j += i) p[j] = true;
	}
	for(ll i = 2; i < SIZE; i++){
		if(!p[i]){
			pr[0].push_back(i);
			pr[1].push_back(i*i);
			pr[2].push_back(i*i*i);
		}
	}
}

int main(){
	prime();
	int n;
	cin >> n;
	rep(i,n){
		cin >> s[i];
		ll tmp = 1, ss = s[i];
		rep(j,pr[2].size()){
			if(ss < pr[2][j]) break;
			while(ss%pr[2][j] == 0){
				s[i] /= pr[2][j];
				ss /= pr[2][j];
			}
			if(ss%pr[1][j] == 0){
				tmp *= pr[0][j];
				ss /= pr[1][j];
			}
			if(ss%pr[0][j] == 0){
				tmp *= pr[1][j];
				ss /= pr[0][j];
			}
			if(tmp > INF){
				tmp = 0;
				break;
			}
		}
		if(tmp == 0) continue;
		int st = 0, en = pr[0].size(), mid;
		while(en-st>1){
			mid = (st+en)/2;
			if(pr[1][mid] > ss){
				en = mid;
			} else{
				st = mid;
			}
		}
		if(ss == pr[1][st]){
			tmp *= pr[0][st];
		} else{
			tmp *= ss*ss;
		}
		if(tmp > INF) continue;
		m[s[i]]++;
		num[s[i]] = tmp;
		//cout << s[i] << " " << num[s[i]] << endl;
	}
	for(it = m.begin(); it != m.end(); it++){
		ama[counter] = (*it).first;
		counter++;
	}
	sort(ama,ama+counter);
	for(it = m.begin(); it != m.end(); it++){
		ll f = (*it).first;
		ll tmp = num[f];
		if(tmp == 0) continue;
		if(f == 1){
			hiku = hiku+(m[f]-1)*2;
			continue;
		}
		
		int st = 0, en = counter, mid;
		while(en-st>1){
			mid = (st+en)/2;
			if(ama[mid] > tmp) en = mid;
			else st = mid;
		}
		if(ama[st] == tmp) hiku += min(m[f],m[tmp]);
		//cout << " " << hiku << endl;
	}
	cout << n-hiku/2 << endl;
}














Measured memory_bytes: 12416
import java.util.*;
public class Main {

    public static void main(String[] args) {
        Scanner yomi = new Scanner(System.in);
        int iti = yomi.nextInt();
        int ni = yomi.nextInt();
        int san = yomi.nextInt();
        if (iti+ni+san <= 21){
            System.out.println("win");
        }else System.out.println("bust");

    }
}


Measured memory_bytes: 23764
n=int(input())
m=10
f=[list(map(int,input().split())) for _ in range(n)]
p=[list(map(int,input().split())) for _ in range(n)]
ans=-10**18
for i in range(1,2**m):
  s=0
  for j in range(n):
    cnt=0
    for k in range(m):
      if (i>>k)&1 and f[j][k]:
        cnt+=1
    s+=p[j][cnt]
  ans=max(s,ans)
print(ans)

Measured memory_bytes: 68672
#include <bits/stdc++.h>
using namespace std;
#define PI 3.141592653589793
#define MOD 1000000007
#define rep(i, n) for (ll i = 0; i < n; i++)
#define all(v) v.begin(), v.end()
typedef long long ll;
typedef long double ld;

int main(){
    ll N;
    cin >> N;
    vector<ll> A(N,0);
    rep(i,N) cin >> A[i];
    ll sum = 0;

    rep(i,N){
        sum += A[i];
        sum %= MOD;
    }

    ll ans = 0;
    rep(i,N){
        sum -= A[i];
        if(sum < 0)  sum += MOD;
        ans += (A[i] * sum);
        ans %= MOD;
    }

    cout << ans << endl;
    
}


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

int main(){
    int X;
    cin >> X;
    vector <bool> expo(X+1);

    expo[1] = 1;
    for(int b=2;b<=X;b++){
        int v = b*b;
        while(v<=X){
            expo[v] = 1;
            v *= b;
        }
    }
    for(int i=X;i>=1;i--){
        if(expo[i]){
            cout << i << endl;
            return 0;
        }
    }
}

Measured memory_bytes: 256