akhauriyash/Code-Regression huggingface dataset:
#!/usr/bin/env python3
import sys

YES = "Yes"  # type: str
NO = "No"  # type: str


def solve(N: int, a: "List[int]"):
    from collections import Counter
    ma, mi = max(a), min(a)
    if ma >= N or mi < 1:
        raise
    if ma - mi > 1:
        return False
    # 全員aloneか、全員crowd
    if ma == mi:
        return ma == N - 1 or  2 * ma <= N
    c = Counter(a)
    # pairがpairでない
    if c[ma] % 2 != 0:
        return False
    x = ma - c[ma] // 2
    # pair以外、すべてalone(crowdが0個)
    if x == c[mi]:
        return True
    # crowdを1つ以上作れるなら1以上c[mi]-2以下の好きな數を作れる
    return 1 <= x <= c[mi] - 2

# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    a = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    print(YES if solve(N, a) else NO)

if __name__ == '__main__':
    main()


Measured memory_bytes: 14256
using System;
class Program
{
  static void Main(string[] args)
  {
    string[] input = Console.ReadLine().Split(' ');
    int n = int.Parse(input[0]);
    int a = int.Parse(input[1]);
    int b = int.Parse(input[2]);
    Console.WriteLine(Math.Min(a*n, b));
  }
}

Measured memory_bytes: 11092
n = int(input())
slist = []
ans = 0
startB, endA = 0, 0
b_a = 0
for _ in range(n):
    s = list(input())
    for j in range(len(s) - 1):
        if ("".join(s[j:j + 2]) == "AB"):
            ans += 1
    startB += 1 if s[0] == "B" else 0
    endA += 1 if s[len(s) - 1] == "A" else 0
    b_a += 1 if s[0] == "B" and s[len(s) - 1] == "A" else 0

if startB == b_a and endA == b_a:
    startB -= 1

print(ans+min(max(0, startB), max(0, endA)))


Measured memory_bytes: 3064
#include <iostream>
#include <vector>
#include <cstdio>
#include <cstring>
#include <string>
#include <cmath>
#define CLR(array) memset( array, 0, sizeof array )
typedef long long int ll;
using namespace std;

#define MAXN (100000+5)
#define MAXK (100+5)



int main(){

	int n,m;
	
	ll status[ MAXN ];
	ll count[ MAXN ];

	CLR( status );
	CLR( count );

	cin >> n >> m;

	int no;
	string vdct;

	for( int i = 0; i < m; i++ ){
		cin >> no >> vdct;
		if( status[no] == 1 )
			continue;

		if( vdct == "AC" )
			status[no] = 1;
		else
			count[no]++;
	}

	ll a = 0, b = 0;
	for( int i = 1; i <= n; i++ ){
		if( status[i] == 1 ){
			a++;
			b += count[i];
		}
	}

	cout << a << " " << b << endl;
}	


Measured memory_bytes: 1792
#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() {
    int n, k;
    cin >> n >> k;
    string s;
    cin >> s;
    char pre = s[0];
    int ans = 0;
    for (int i = 1; i < n; ++i) {
        if (pre==s[i]) ans++;
        else pre = s[i];
    }
    ans += 2*k;
    ans = min(ans, n-1);
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 512
#include <iostream>

using namespace std;

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

  ab *= 2;
  ab = min(ab, a + b);
  a = min(a, ab);
  b = min(b, ab);

  int z = min(x, y);
  x -= z;
  y -= z;
  int ans = ab * z + a * x + b * y;
  cout << ans << endl;
}


Measured memory_bytes: 256
/*input
dedaded
*/

#include <bits/stdc++.h>
#define ll long long

using namespace std;

bool check(string s) {
	int i, n = s.size();
	for(i=0; i<n/2; i++) {
		if(s[i] != s[n-1-i])
			return false;
	}
	return true;
}

void run() {
	string s;
	cin >> s;
	int n = s.size();
	// cout << s.substr(0, (n-1)/2) << endl;
	// cout << s.substr((n+3)/2 -1) << endl;
	if(check(s) && check(s.substr(0, (n-1)/2)) && check(s.substr((n+3)/2 - 1)))
		cout << "Yes" << endl;
	else
		cout << "No" << endl;
}

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);		
	int t = 1;
	// cin >> t;
	while(t--) {
		run();
	}
}


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

int main() {
	int x = -1, y = -1;
	int s;
	for (;;) {
		cin >> x >> y;
		if (x == 0 && y == 0)
			break;
		if (x > y)
			s = x, x = y, y = s;

		cout << x  << " " << y << endl;

	}
	return 0;
}


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

using namespace std;
using ll = long long;
const int INF = 1e9 + 7;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  ll n, W;
  cin >> n >> W;
  vector<int> weight(n), value(n);
  for (int i = 0; i < n; i++) {
    cin >> weight[i] >> value[i];
  }
  int sum_val = 0;
  for (int& v : value) sum_val += v;
  vector<ll> dp(sum_val + 1, INF); // dp[i] the minimum weight at value i
  dp[0] = 0;
  for (int i = 0; i < n; i++) {
    for (int value_already = sum_val - value[i]; value_already >= 0; value_already--){
      dp[value_already + value[i]] = min(dp[value_already + value[i]], dp[value_already] + weight[i]);
    }
  }
  ll ans = 0;
  for (ll i = 0; i <= sum_val; i++) {
    if (dp[i] <= W) {
      ans = max(ans, i);
    }
  }
  cout << ans << '\n';
  return 0;
}


Measured memory_bytes: 3980
using System;
using System.Linq;
using System.Collections.Generic;

namespace AtCoder.Beginner068
{
    public class ABC068B_BreakNumber
    {
        public static void Main(string[] args)
        {

            int n = int.Parse(Console.ReadLine());

            int ans = 1;

            while(ans * 2 <= n)
            {
                ans *= 2;
            }

            Console.WriteLine(ans);

        }
    }
}

Measured memory_bytes: 11092
#include<stdio.h>
int main (){

int x,y,d,r;
scanf("%d %d\n",&x,&y);

if(x<y){
 r=x;
 x=y;
 y=r;
}

 d=x%y;
 while(d!=0){
  x=y;
  y=d;
  d=x%y;
}
printf("%d\n",y);
}
 

Measured memory_bytes: 1820
#include <bits/stdc++.h>
#define base 1000000007LL
#define ll long long
#define X first
#define Y second
#define ld double
#define pb push_back
#define EPS 1e-9
#define all(a) a.begin(),a.end()
#define sz(a) int((a).size())
#define ms(s, n) memset(s, n, sizeof(s))
#define FOR(i,a,b) for (int i = (a); i <= (b); i++)
#define FORE(i,a,b) for (int i = (a); i >= (b); i--)
#define FORALL(it, a) for (__typeof((a).begin()) it = (a).begin(); it != (a).end(); it++)
using namespace std;
typedef pair<int, int> II;
typedef pair<II, int> III;

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(NULL);
    //freopen("inp.txt", "r", stdin);
    //freopen("out.txt", "w", stdout);
    int n, k;
    cin >> n >> k;
    if (n % k) cout << 1;
    else cout << 0;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
typedef pair<ll, P> P3;
typedef pair<P ,P> PP;
const ll MOD = ll(1e9)+7;
const int IINF = INT_MAX;
const ll LLINF = LLONG_MAX;
const int MAX_N = int(1e5 + 5);
const double EPS = 1e-6;
const int di[] = {0, 1, 0, -1}, dj[] = {1, 0, -1, 0};
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define SORT(v) sort((v).begin(), (v).end())
#define SORTR(v) sort((v).rbegin(), (v).rend())
#define ALL(v) (v).begin(), (v).end()

template <typename Monoid>
struct SegmentTree{
private:
    int N;
    vector<Monoid> node;
    using F = function<Monoid(Monoid, Monoid)>;
    F f;
    Monoid e;

public:
    SegmentTree(){}
    SegmentTree(F f, Monoid e):f(f), e(e){}
    void init(int sz){
        N = 1;
        while(N < sz) N <<= 1;
        node.assign(2*N-1,e);
    }
    void build(vector<Monoid>& v){
        int sz = int(v.size());
        init(sz);
        for(int i=N-1; i<(N<<1); i++){
            node[i] = v[i];
        }
        for(int i=N-2; i>=0; i--){
            node[i] = f(node[i*2+1], node[i*2+2]);
        }
    }
    void add_val(int k, Monoid x){
        k += N-1;
        node[k] += x;
        while(k > 0){
            k = (k-1)/2;
            node[k] = f(node[2*k+1], node[2*k+2]);
        }
    }
    // [a,b)
    Monoid query(int a, int b){return query(a, b, 0, 0, N);}
    Monoid query(int a, int b, int k, int l, int r){
        if(b <= l || r <= a) return e;
        if(a <= l && r <= b) return node[k];
        Monoid vl, vr;
        vl = query(a, b, 2*k+1, l, (l+r)/2);
        vr = query(a, b, 2*k+2, (l+r)/2, r);
        return f(vl, vr);
    }
};



int main() {
    auto f = [=](ll a, ll b){return a + b;};
    SegmentTree<ll> seg(f,0LL);

    int n, q;
    cin >> n >> q;
    seg.init(n);
    for(int i=0; i<q; i++){
        int c, x, y;
        cin >> c >> x >> y;
        if(c){
            cout << seg.query(x-1, y) << endl;
        }
        else{
            seg.add_val(x-1, y);
        }
    }
    return 0;
}



Measured memory_bytes: 4872
import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main {
    static BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

    public static void main(String[] args) throws Exception {
        int[] arr = inputval();
        int N, A, B;
        N = arr[0];
        A = arr[1];
        B = arr[2];
        int m,n;
        int sum_digits;
        int sum = 0;
        for (int i = 1; i <= N; i++) {
            m = i;
            n = i;
            sum_digits = 0;
            while (n > 0) {
                sum_digits += n % 10;
                n /= 10;
            }
            if (A <= sum_digits && sum_digits <=B){
                sum += m;
            }
        }
        System.out.println(sum);
    }


    static int[] inputval() throws Exception {
        String[] strarray = br.readLine().trim().split(" ");
        int[] intarray = new int[strarray.length];
        for (int i = 0; i < intarray.length; i++) {
            intarray[i] = Integer.parseInt(strarray[i]);
        }
        return intarray;
    }

    static void array_sout(int[][] array) {
        for (int i = 0; i < array.length; i++) {
            for (int j = 0; j < array[0].length; j++) {
                System.out.print(array[i][j] + " ");
            }
            System.out.println();
        }
    }

    static void array_sout(int[] array) {
        for (int i = 0; i < array.length; i++) {
            System.out.print(array[i] + " ");
        }
        System.out.println();
    }
}

Measured memory_bytes: 21204
#include <bits/stdc++.h>
#define chmin(a, b) ((a)=min((a), (b)))
#define chmax(a, b) ((a)=max((a), (b)))
#define fs first
#define sc second
#define eb emplace_back
using namespace std;

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

const ll MOD=1e9+7;
const ll INF=1e18;
const double pi=acos(-1);
const double eps=1e-10;

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

int main(){
    while(1){
        int n; cin>>n;
        if(n==0) return 0;

        vector<int> tanku={5, 7, 5, 7, 7};
        vector<string> w(n);
        for(int i=0; i<n; i++) cin>>w[i];

        for(int i=0; i<n; i++){
            int cnt=0, sum=0;
            for(int j=i; j<n; j++){
                sum+=w[j].size();
                if(sum==tanku[cnt]){
                    sum=0;
                    cnt++;

                    if(cnt==5){
                        cout << i+1 << endl;
                        goto END;
                    }
                }
            }
        }

        END:;
    }
}


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

#define rep(i, N) for (int i = 0; i < N; i++)
#define pb push_back
typedef long long ll;
typedef pair<int, int> i_i;

bool check(ll N, ll a, ll b, ll c) {
	if (1<=a && a<=3500); else return false;
	if (1<=b && b<=3500); else return false;
	if (1<=c && c<=3500); else return false;
	ll x = a * b * c * 4;
	ll y = a * b + b * c + c * a;
	if (x % y) return false;
	return x / y == N;
}

int main() {
	ll N; cin >> N;
	double x = 4.0 / N;
	for (ll a = 1; a <= 3500; a++)
		for (ll b = 1; b <= 3500; b++) {
			double y = x - 1.0 / a - 1.0 / b;
			ll c = 1 / y;
			c--;
			if (check(N, a, b, c)) {
				cout << a << ' ' << b << ' ' << c << ' ' << endl;
				return 0;
			}
			c++;
			if (check(N, a, b, c)) {
				cout << a << ' ' << b << ' ' << c << ' ' << endl;
				return 0;
			}
			c++;
			if (check(N, a, b, c)) {
				cout << a << ' ' << b << ' ' << c << ' ' << endl;
				return 0;
			}
		}
}


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

int main(int argc, char *argv[])
{
    int n, w, h, x, y, s, t, num, max;
    while (cin >> n, n) {
        cin >> w >> h;
        bool psm[w + 1][h + 1];
        for (int i = 0; i <= w; ++i)
            for (int j = 0; j <= h; ++j)
                psm[i][j] = false;
        for (int i = 0; i < n; ++i) {
            cin >> x >> y;
            psm[x][y] = true;
        }
        cin >> s >> t;
        max = 0;
        for (int i = 1; i <= w - s + 1; ++i) {
            for (int j = 1; j <= h - t + 1; ++j) {
                num = 0;
                for (int x = 0; x < s; ++x) {
                    for (int y = 0; y < t; ++y) {
                        if (psm[i + x][j + y])
                            num++;
                    }
                }
                max = (max < num) ? num : max;
            }
        }
        cout << max << endl;
    }
    return 0;
}

Measured memory_bytes: 1168
# util functions

# debug
$debugFlag = ( ARGV[0] != nil )
p "==== DEBUG MODE ====" if $debugFlag

def pd(str)
  p str if $debugFlag
end

def printd(str)
  print str if $debugFlag
end

# input
inputs = []
lc = 0
while l = $stdin.gets do
  if true
    inputs << l.chomp.split(" ").map(&:to_s)
  else
    inputs << l.chomp.split(" ").map(&:to_i)
  end
  lc += 1
end

# input check
if $debugFlag
  p "--- INPUT (begin) ---"
  inputs.each do |l_i|
    p l_i
  end
  p "--- INPUT (end) ---"
  print "\n"
end

str = inputs[1][0]

# body
if $debugFlag
end

ans = 0;
(str.length-1).times do |i|
  arr0 = str[0..i].split("").uniq
  arr1 = str[i+1..-1].split("").uniq

  tmp = 0
  arr0.each do |a_i|
    tmp += 1 if arr1.include?(a_i)
  end

  ans = tmp if tmp > ans
end

puts ans


Measured memory_bytes: 1788
#include<iostream>
#include<vector>
#include<algorithm>
#include<set>
#include<map>
#include<string.h>
#include<queue>
#include<math.h>
#include<set>
#include<unordered_set>
#include<limits.h>
using namespace std;

typedef unsigned long long ll;
int n,s;
map<pair<int,int>,int >ma;//sum,number, count
void dfs(int cur,int used,ll status){
    if(cur>10000)return;
    if(used>10){
        return;
    }
    ma[make_pair(cur, used)]++;
    used++;
    for(int j=0;j<=9;j++){
        if(((status>>j)&1ll)==0ll)
            dfs(cur+used*j,used,(status|(1ll<<j)));
    }
}
int main(){
    dfs(0,0,0);
    while(cin>>n>>s){
        int ans=0;
        ans=ma[make_pair(s, n)];
        cout<<ans<<endl;
    }
    return 0;
}

Measured memory_bytes: 3136
import java.util.*;

public class Main {
	
	public static void main(String[] args)  {
		Scanner scan = new Scanner(System.in);
		long n=Long.parseLong(scan.next());
		
		long ans=1000000000000L;
		for (long i=1;i*i<=n;++i) {
			if (n%i!=0)continue;			
			ans=Math.min(ans, i+n/i-2);			
		}
		
		System.out.print(ans);
		
		
}		
}
//end

Measured memory_bytes: 23764
import sys
input = sys.stdin.readline

def m(l):
    l.sort()
    n = len(l)
    
    if n%2==0:
        return (l[n//2-1]+l[n//2])/2
    else:
        return l[n//2]

N = int(input())
A, B = [], []

for _ in range(N):
    Ai, Bi = map(int, input().split())
    A.append(Ai)
    B.append(Bi)
    
l, h = m(A), m(B)

if N%2==0:
    print(int((h-l)*2+1))
else:
    print(h-l+1)

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

int main(){

    int n;
    cin >> n;
    if(n==22) cout << " Christmas Eve Eve Eve " << endl;
    else if(n==23) cout << " Christmas Eve Eve " << endl;
    else if(n==24) cout << " Christmas Eve " << endl;
    else cout << " Christmas " << endl;
    
return 0;
}


Measured memory_bytes: 256
//↓template↓

#include "bits/stdc++.h"
using namespace std;
#define Would
#define you
#define all(n)  n.begin(),n.end()
const long long INF = 1e18;
const long long MOD = 1e9 + 7;
const double pi = acos(-1);
const int SIZE = 1 << 17;
int dx[] = { 1,0,-1,0 }, dy[] = { 0,1,0,-1 }, alp[30];
long long fac[200005], finv[200005], inv[200005];
vector<long long>dij;
struct edge { long long to, cost; };
vector<vector<edge> >G;

long long mod_pow(long long a, long long b) {
	long long res = 1;
	while (b) {
		if (b & 1) { res = res * a%MOD; }
		a = a * a%MOD;
		b >>= 1;
	}
	return res;
}

void addedge(int from, int to, int cost) {
	G[from].push_back({ to,cost });
	G[to].push_back({ from,cost });
}

//↑template↑

int n, k[105], al, bo;
int main() {
	cin >> n;
	for (int i = 0; i < n; ++i) {
		cin >> k[i];
	}
	sort(k, k + n);
	reverse(k, k + n);
	for (int i = 0; i < n; ++i) {
		if (i % 2 == 0) { al += k[i]; }
		else { bo += k[i]; }
	}

	cout << al - bo << endl;
}

Measured memory_bytes: 256
////////////////////////// Author
////////////////////////// Nasim Hossain Rabbi
////////////////////////// JU-CSE28
////////////////////////// CF - imnasim3.1415
////////////////////////// UVA - imnasim3.1415
////////////////////////// Mail - imnasim3.1415@gmail.com
#include<bits/stdc++.h>
using namespace std;
#define sz size()
#define mk make_pair
#define clr clear()
#define B begin()
#define E end()
#define EM empty()
#define mem(a,b) memset(a,b,sizeof(a))
#define rep(i,n) for(i=0;i<n;i++)
#define Rep(i,n) for(i=1;i<=n;i++)
#define all(cont) cont.begin(),cont.end()
#define pb push_back
string en="\n";
string t="hello";
#define sqr(a) ((a) * (a))
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL);cout.tie(NULL)
#define pi 3.1415926535897932384626433832795
#define vi vector<int>
#define vl vector<long long>
#define vs vector<string>
#define vp(vi,x) cin>>x; vi.pb(x);
#define LB(a,x) (lower_bound(aov(a),x)-a.begin())
#define UB(a,x) (upper_bound(aov(a),x)-a.begin())
typedef long long LL;
typedef unsigned long long ULL;
bool isVowel(char ch){ ch=toupper(ch); if(ch=='A'||ch=='U'||ch=='I'||ch=='O'||ch=='E') return true; return false;}
int toInt(string s){int sm;stringstream ss(s);ss>>sm;return sm;}
template<typename T>inline T gcd(T a,T b){if(a<0)return gcd(-a,b);if(b<0)return gcd(a,-b);return (b==0)?a:gcd(b,a%b);}
template<typename T>inline T lcm(T a,T b) {if(a<0)return lcm(-a,b);if(b<0)return lcm(a,-b);return a*(b/gcd(a,b));}
int main()
{
//    fast;
    LL i,j,k,n,m,l,s=0,x,y,tc=1,c=0;
    map<string,int> mp;
    string a; cin>>n;
        rep(i,n)
        {
            cin>>a;
            mp[a]++;
        }
        cin>>m;
        rep(i,m)
        {
            cin>> a;
            mp[a]--;
        }
        map<string,int> :: iterator it=mp.B;
        s=0;
        for(it=mp.B;it!=mp.E;it++)
        {
            if(it -> second >s)
            {
                s=it->second;
            }
        }
        cout<<s<<en;

}



Measured memory_bytes: 256
x0, y0, x1, y1 = map(int, input().split())
res = 'U' * (y1 - y0) + 'R' * (x1 - x0) + 'D' * (y1 - y0) + 'L' * (
    x1 - x0) + 'L' + 'U' * (y1 - y0 + 1) + 'R' * (
        x1 - x0 + 1) + 'D' + 'R' + 'D' * (y1 - y0 + 1) + 'L' * (x1 - x0 +
                                                                1) + 'U'
print(res)

Measured memory_bytes: 3064
# coding: utf-8
# Your code here!


from scipy.misc import comb
mod = 10**9 + 7

n,k = map(int,input().split())

for i in range(1,k+1):
    a = int(comb(k-1, i-1, exact=True)) % mod
    b = int(comb(n-k+1, i, exact=True)) % mod 
    print(a*b%mod)

Measured memory_bytes: 15360
n=int(input())
i=1
total=0
while i <=n:
    if i%15==0:
        #print("FB")
        total+=0
    elif i%5==0:
        #print("B")
        total+=0
    elif i%3==0:
        #print("F")
        total+=0
    else:
        #print(i)
        total+=i
    i+=1
print(total)

Measured memory_bytes: 9176
#include <stdio.h>
#include <stdlib.h>
#define NIL NULL
struct node{
  struct node *right;
  struct node *left;
  struct node *parent;
  int key;
};
typedef struct node * Node;
Node root;

void insert(int);
void inorder(Node);
void preorder(Node);
Node  find(Node,int);
Node treeSuccessor(Node);
Node treeMinimum(Node);
void delite(Node );

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);
}
Node find(Node u,int k){
  while(u!=NIL && k!=u->key){
    if(k<u->key)
      u=u->left;
    else
      u=u->right;
  }
  return u;
}
void delite(Node t){
  Node y;
  Node x;
  if(t->left==NIL||t->right==NIL)
    y=t;
  else
    y=treeSuccessor(x);
  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!=t){
    t->key=y->key;
  }
  free(y);
}
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;
}
Node treeMinimum(Node x){
  while(x->left!=NIL){
    x=x->left;
  }
  return x;
}
    
int main(){
  int n, i, a;
  char com[20];
  Node u;
  scanf("%d", &n);

  for ( i = 0; i < n; i++ ){
    scanf("%s", com);
    if ( com[0] == 'i' ){
      scanf("%d", &a);
      insert(a);
    } else if ( com[0] == 'p' ){
      inorder(root);
      printf("\n");
      preorder(root);
      printf("\n");
    }
    else if ( com[0] == 'f' ){
      scanf("%d", &a);
      u=find(root,a);
      if(u!=NIL)printf("yes\n");
      else printf("no\n");
    }
    else if(com[0] == 'd'){
      scanf("%d",&a);
      delite(find(root,a));
  }
  }
  return 0;
}


Measured memory_bytes: 25292
# coding: utf-8
import sys
import numpy as np

sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

H, W = lr()
S = np.array(['#' * (W+2)] + ['#' + sr() + '#' for _ in range(H)] + ['#' * (W+2)])
S = np.array([[x == '.' for x in row] for row in S])
S = S.astype(np.int16)
left = S.copy(); right = S.copy(); up = S.copy(); down = S.copy()
for i in range(1, W+1):
    left[:, i] += left[:, i-1]
    left[:, i] *= S[:, i]
for i in range(W, 0, -1):
    right[:, i] += right[:, i+1]
    right[:, i] *= S[:, i]
for i in range(1, H+1):
    up[i, :] += up[i-1, :]
    up[i, :] *= S[i, :]
for i in range(H, 0, -1):
    down[i, :] += down[i+1, :]
    down[i, :] *= S[i, :]

answer = (left + right + up + down - 3).max()
print(answer)


Measured memory_bytes: 71528
#include <iostream>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <iomanip>
#include <functional>
using namespace std;
#define int long long
#define All(v) (v).begin(),(v).end()
int dy[4] = {-1,0,1,0};
int dx[4] = {0,1,0,-1};
int Dy[8] = {-1,-1,0,1,1,1,0,-1};
int Dx[8] = {0,1,1,1,0,-1,-1,-1};
const int mod = 1000000007;
const int inf = mod*mod;
const int d5 = 100100;
signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int a,b;
    cin >> a >> b;
    cout << max(a - 2 * b, 0LL) << endl;
}

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

using namespace std;


int main(){
  int a,b;
  cin>>a>>b;
  int i = 1, j = 2;
  
  while(j<=999){
    if(i*(i+1)/2 - a == j*(j+1)/2 - b){
    	cout<<i*(i+1)/2 - a<<"\n";
      	return 0;
    }
    i++, j++;
  }
  
  return 0;
}

Measured memory_bytes: 256
/*
    Author: Alam Khan
    AUST CSE 40th Batch

*/

#include<bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/detail/standard_policies.hpp>
using namespace __gnu_pbds;

typedef long long ll;
typedef tree<ll,null_type,less_equal<ll>,rb_tree_tag,tree_order_statistics_node_update>ordered_set;
#define pb     push_back
#define inf     2e18
#define low     -2e18
#define PI        acos(-1.0)
#define endl  "\n"
#define FAST  ios_base::sync_with_stdio(false);cin.tie(NULL);
#define fr freopen("input.txt","r",stdin)
#define fw freopen("output.txt","w",stdout)
const int sz = 1e5+9;

int main()
{
    ll i,n,t,k,j,x=0,y=0,m;
    ll a[1009];
    cin>>n;
    for(i=0;i<n;i++)
    {
        cin>>a[i];
    }
    for(i=0;i<n;i++)
    {
        for(j=i+1;j<n;j++)
        {
            for(k=j+1;k<n;k++)
            {
                if(a[i]+a[j]>a[k] && a[i]+a[k]>a[j] && a[j]+a[k]>a[i] && a[i]!=a[j] && a[i]!=a[k] && a[j]!=a[k])
                {
                    x++;
                    //cout<<i+1<<" "<<j+1<<" "<<k+1<<endl;
                }
            }
        }
    }
    cout<<x<<endl;
    return 0;
}



Measured memory_bytes: 3636
#define _USE_MATH_DEFINES // M_PI
#include<cmath>
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define REP(i,m,n) for(int i=(int)(m);i<(int)(n);++i)
#define rep(i,n) REP(i,0,n)
#define rREP(i,a,n) for(int (i)=(n)-1; (i)>=(a);--(i))
#define all(x) (x).begin(),(x).end()
#define out(y,x,h,w) (y)<0||(x)<0||(y)>=(h)||(x)>=(w)
constexpr int INF = 2147483647;
constexpr ll mod = 1000000007;

template<class T>inline bool chmin(T& a, T b) {
	if (a > b) {
		a = b;
		return true;
	}
	return false;
}
template<class T>inline bool chmax(T& a, T b) {
	if (a < b) {
		a = b;
		return true;
	}
	return false;
}
inline void init() {
	cin.tie(nullptr); cout.tie(nullptr);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(15);
}


int main() {
	init();

	string s;cin >> s;
	char a = 'a';
	rep(i, 26) {
		bool is = false;
		rep(j, s.size()) {
			if (a == s[j])is = true;
		}
		if (!is) {
			cout << a << "\n";
			return 0;
		}
		++a;
	}
	cout << "None" << "\n";

	return 0;
}


Measured memory_bytes: 512
import java.util.ArrayDeque;
import java.util.Deque;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		int n = scanner.nextInt();
		while (n-- > 0) {
			char[] ch = scanner.next().toCharArray();
			Deque<Character> deque = new ArrayDeque<Character>();
			deque.push(ch[0]);
			for (int i = 3; i < ch.length; i += 3) {
				if (!deque.contains(ch[i])) {
					if (ch[i - 1] == '>') {
						deque.offer(ch[i]);
					} else {
						deque.push(ch[i]);
					}
				}
			}
			for (Character c : deque) {
				System.out.print(c);
			}
			System.out.println();
		}
	}
}

Measured memory_bytes: 21152
import Control.Applicative ((<$>), (<*>))
import Control.Monad
import Data.List

main :: IO ()
main = do
  solve <$> replicateM 28 (getl toInt) >>= mapM_ print

solve :: [Int] -> [Int]
solve xs = sort $ [1..30] \\ xs

toInt :: String -> Int
toInt = read

getl :: (String -> a) -> IO a
getl f = f <$> getLine

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

using namespace std;

int64_t egcd(int64_t a, int64_t b)
{
  if(a < b) return egcd(b, a);
  int64_t r;
  while ((r=a%b)) {
    a = b;
    b = r;
  }
  return b;
}

int main()
{
  int64_t a, b;
  cin >> a >> b;
  int64_t fegcd = egcd(a, b);

  vector<int64_t> cdiv;
  vector<int64_t> cdiv2;
  for(int64_t i = 1;
      i*i <= fegcd;
      ++i)
    {
      if(fegcd % i == 0)
        {
          cdiv.push_back(i);
          cdiv2.push_back(fegcd/i);
        }
    }
  for(int64_t i = cdiv2.size() - 1;
      i != -1;
      --i)
    {
      cdiv.push_back(cdiv2[i]);
    }

  int64_t ans  = 0;
  vector<bool> ansv(cdiv.size(), true);

  for(int64_t i = 1;
      i < cdiv.size();
      ++i)
    {
      if(ansv[i])
        {
          for(int64_t j = i + 1;
              j < cdiv.size();
              ++j)
            {
              if(ansv[j])
                {
                  int64_t tegcd = egcd(cdiv[i], cdiv[j]);
                  if(tegcd != 1)
                    {
                      ansv[j] = false;
                    }
                }
            }
        }
    }

  int64_t len = ansv.size();

  if(a == 1 || b == 1)
    {
      --len;
    }
  for(int64_t i = 0;
      i < len;
      ++i)
    {
      if(ansv[i])
        {
          ++ans;
        }
    }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
#define inf 1000000000
#define INF 1000000000000000
#define ll long long
#define ull unsigned long long
#define M (int)(1e9+7)
#define P pair<int,int>
#define PLL pair<ll,ll>
#define FOR(i,m,n) for(int i=(int)m;i<(int)n;i++)
#define RFOR(i,m,n) for(int i=(int)m;i>=(int)n;i--)
#define rep(i,n) FOR(i,0,n)
#define rrep(i,n) RFOR(i,n,0)
#define all(a) a.begin(),a.end()
#define IN(a,n) rep(i,n){ cin>>a[i]; }
const int vx[4] = {0,1,0,-1};
const int vy[4] = {1,0,-1,0};
#define PI 3.14159265
#define F first
#define S second
#define PB push_back
#define EB emplace_back
#define int ll
void init(){
  cin.tie(0);
  ios::sync_with_stdio(false);
}




ll power(ll x,ll k){
  ll ret=1;
  while(k>0){
    if(k&1) (ret*=x) %= M;
    (x*=x) %= M;
    k >>= 1;
  }
  return ret;
}


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

  int ans=1;
  FOR(i,2,n){
    int k=i;
    int j=2;
    while(k<=n){
      k=power(i,j);
      //cout<<k<<endl;
      if(k>n) break;
      ans=max(ans,k);
      j++;
    }
  }
  cout<<ans<<endl;
}


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

int main() {
    vector<int> A(5);
    for (int i=0; i<5; i++) cin >> A.at(i);
    int k;
    cin >> k;
    bool can = true;
    for(int i=4; i>=1; i--) {
        for(int j=i-1; j>=0; j--) {
            int dist = A.at(i) - A.at(j);
            if (dist > k) {
                can = false;
                break;
            }
        }
        if (!can) break;
    }

    if (can) cout << "Yay!" << endl;
    else cout << ":(" << endl;
    return 0;
}


Measured memory_bytes: 256
#include <map>
#include <cstdio>
#include <algorithm>

using namespace std;

namespace io
{
	const int SIZE = (1 << 21) + 1;
	char ibuf[SIZE], *iS, *iT, obuf[SIZE], *oS = obuf, *oT = oS + SIZE - 1, c, qu[55]; int f, qr;
	#define gc() (iS == iT ? (iT = (iS = ibuf) + fread (ibuf, 1, SIZE, stdin), (iS == iT ? EOF : *iS ++)) : *iS ++)
	inline void flush (){fwrite (obuf, 1, oS - obuf, stdout);oS = obuf;}
	inline void putc (char x){*oS ++ = x;if (oS == oT) flush ();}
	template <class I>
	inline void gi (I &x) {for (f = 1, c = gc(); c < '0' || c > '9'; c = gc()) if (c == '-') f = -1;
		for (x = 0; c <= '9' && c >= '0'; c = gc()) x = x * 10 + (c & 15); x *= f;}
	template <class I>
	inline void print (I x){
		if (!x) putc ('0'); if (x < 0) putc ('-'), x = -x;while(x) qu[++ qr] = x % 10 + '0',  x /= 10;while (qr) putc (qu[qr--]);}
	struct Flusher_ {~Flusher_(){flush();}}io_flusher_;
}
using io::gi;
using io::putc;
using io::print;

const int Max_N(500050);
typedef long long int LL;
const LL MOD(1000000000LL + 7LL);

struct person
{
	int x, v, L, R;
};
int N, PreMax[Max_N], SufMin[Max_N];
person V[Max_N];
map<int, int> seg[Max_N]; 

inline bool comp_x(const person &a, const person &b)
{
	return a.x < b.x;
}

inline bool comp_v(const person &a, const person &b)
{
	return a.v < b.v;
}

void init()
{
	gi(N);
	for (int i = 1;i <= N;++i)
		gi(V[i].x), gi(V[i].v);
	sort(V + 1, V + 1 + N, comp_x);
}

void prepare()
{
	PreMax[1] = V[1].v;
	for (int i = 2;i <= N;++i)
		PreMax[i] = max(PreMax[i - 1], V[i].v);
	SufMin[N] = V[N].v;
	for (int i = N - 1;i >= 1;--i)
		SufMin[i] = min(SufMin[i + 1], V[i].v);
	for (int i = 1;i <= N;++i)
		V[i].L = SufMin[i], V[i].R = PreMax[i];
	sort(V + 1, V + 1 + N, comp_v);
	for (int i = 1, l, r, mid;i <= N;++i)
	{
		l = 1, r = i;
		while (l < r)
		{
			mid = l + ((r - l) >> 1);
			if (V[mid].v >= V[i].L)
				r = mid;
			else
				l = mid + 1;
		}
		V[i].L = l;
		l = i, r = N + 1;
		while (l < r)
		{
			mid = l + ((r - l) >> 1);
			if (V[mid].v <= V[i].R)
				l = mid + 1;
			else
				r = mid;
		}
		V[i].R = l - 1;
		++seg[V[i].R][V[i].R - V[i].L];
	}
}

LL power[Max_N], F[Max_N], BIT[Max_N];

inline int lowbit(const int &x)
{
	return x & -x;
}

void insert(int i, const LL &v)
{
	while (i)
		(BIT[i] += v) %= MOD, i -= lowbit(i);
}

LL query(int i)
{
	LL Ret(0LL);
	if (i == 0)
		++Ret, ++i;
	while (i <= N)
		(Ret += BIT[i]) %= MOD, i += lowbit(i);
	return Ret;
}

void dp()
{
	power[0] = 1LL;
	for (int i = 1;i <= N;++i)
		power[i] = (power[i - 1] << 1LL) % MOD;
	F[0] = 1LL;
	for (int i = 1;i <= N;++i)
	{
		if (seg[i].size())
		{
			int temp(0);
			for (map<int, int>::const_iterator j = seg[i].begin();j != seg[i].end();++j)
			{
				F[i] += power[temp] * ((power[j -> second] - 1LL + MOD) % MOD) % MOD * query(i - j -> first - 1) % MOD;
				F[i] %= MOD;
				temp += j -> second;
			}
		}
		else
			F[i] = 0LL;
		insert(i, F[i]);
	}
	print(F[N]);
}

int main()
{
	init();
	prepare();
	dp();
	return 0;
}

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

#define ld long double
#define ll long long
#define ALL(a)  (a).begin(),(a).end()
#define spa << " " <<
#define MP make_pair
ll MOD = 1e9+7;
//ll MOD = 998244353;
ll INF = 1e18;
void chmin(ll &a, ll b) { if (a > b) a = b; }
void chmax(ll &a, ll b) { if (a < b) a = b; }
void ans1(bool x){
  if(x) cout<<"Yes"<<endl;else cout<<"No"<<endl;}
void ans2(bool x){
  if(x) cout<<"YES"<<endl;else cout<<"NO"<<endl;}
void ans3(bool x){
  if(x) cout<<"Yay!"<<endl;else cout<<":("<<endl;}
void ans(bool x, ll y, ll z){
  if(x) cout<<y<<endl;else cout<<z<<endl;}   


int main(){
  ll i,j;
  //ll n; cin>>n;
  //ll a,b,c,d,e,f; cin>>a>>b;
  //ll a,b,c,d,e,f; cin>>a>>b>>c;
  //ll a,b,c,d,e,f; cin>>a>>b>>c>>d;
  string s,t; cin >> s >> t;
  ll result = 0;
  ll buf = 0;
  ll buf2 = 0;
  ll buf3 = 0;
  bool judge = true;
  sort(ALL(s));
  sort(ALL(t));
  reverse(ALL(t));
  ans1(s<t);

  /*
  vector<ll> a(n);
  for(i=0;i<n;i++){
    cin>>a[i];
  }
  for(i=0;i<n;i++){

  }
  */

  return 0;
}

Measured memory_bytes: 768
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
// Welcome to my source code!

int main() {
    ll l, r;
    cin >> l >> r;
    if (r - l >= 2019) {
        cout << 0 << endl;
        return 0;
    }
    ll ans = 3000;
    for (ll i = l; i <= r - 1; i++) {
        for (ll j = i + 1; j <= r; j++) {
            ans = min(ans, (i * j) % 2019);
        }
    }
    cout << ans << endl;
}

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

int main(void) {
  std::string s;
  std::cin >> s;
  int count = 0;
  int max = 0;
  for (auto &c : s) {
    if (c == 'A' || c == 'C' || c == 'G' || c == 'T') {
      count++;
    } else {
      if (count > max) {
        max = count;
      }
      count = 0;
    }
  }
  if (count > max) {
    max = count;
  }
  std::cout << max << std::endl;
  return 0;
}

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

int main(){

    int N,X;
    cin >> N >> X;
    int m[N],total = 0,totalcost = 0;
    for(int i=0;i<N;i++){
        cin >> m[i];
        total += 1;
        totalcost += m[i];
    }

    int cnt = 3;

    X = X-totalcost;
    sort(m,m+N);
    total += X/m[0];

    cout << total << endl;


    return 0;
}

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

int main(){
  string s,t;
  int i=0;

  cin >> s >> t;

  string str;

  for(int i=0;i < s.size();++i){
    str = s.substr(s.size()-i,i);
    str += s.substr(0,s.size()-i);
    if(str == t)
      {
	cout << "Yes" << endl;
	return 0;
      }
  }
  cout << "No" << endl;
  return 0;
}   

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long int
#define ull unsigned ll
#define jmp cout<<"\n"
#define vl vector<ull>
#define vi vector<int>
#define vvl vector<vl>
#define pb push_back
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define printv(v) for(auto x:v) cout<<x<<" "; jmp;
#define endll "\n"
#define SORT(v) sort(v.begin(),v.end())
#define REV(x)  reverse(x.begin(),x.end())
#define UNI(a) a.erase( unique( a.begin(), a.end() ), a.end() )
#define all(a) a.begin(), a.end()
#define si(x) x.size()
#define ff first
#define ss second
#define iin insert
using namespace std;

ll dp[3005][3005];
ll maxAmount(ll l, ll r, ll a[])

{
	if (l > r)
		return 0;
	if (l == r)
		return a[l];
	if (dp[l][r] != -1)
		return dp[l][r];
	else
		return dp[l][r] = max((a[l] - maxAmount(l + 1, r, a)), (a[r] - maxAmount(l, r - 1, a)));
}
void solve()
{

	ll n, k;
	cin >> n ;
	ll a[n];
	for (ull i = 0; i < n; i++) cin >> a[i];
	memset(dp, -1, sizeof(dp));
	// for (ll i = n - 1; i >= 0; i--)
	// {
	// 	for (ll j = i; j < n; j++)
	// 	{
	// 		if (i == j)
	// 			dp[i][j] = a[i];
	// 		else
	// 			dp[i][j] = max((a[i] - dp[i + 1][j]), ( a[j] - dp[i][j - 1]));
	// 	}
	// }

	cout << maxAmount(0, n - 1, a) << endll;
}
signed main()
{

	fast;
	solve();
	return 0;
}


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

int main(void){
    int n, k;
    cin >> n >> k;
    
    int input;
    int sum = 0;
    int i;
    for(i = 1; i <= n; i++){
        cin >> input;
        sum += min(input, k - input) * 2;
    }
    
    cout << sum << endl;
    
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
#include <cstring>

using namespace std;

struct edge { int to, cap, rev; };
#define MAX_V	(202)
#define INF		(1000000000)

vector<edge> G[MAX_V];
int level[MAX_V];
int iter[MAX_V];

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

void bfs(int s) {
	memset(level, -1, sizeof(level));
	queue<int> que;
	level[s] = 0;
	que.push(s);
	while (!que.empty()) {
		int v = que.front();
		que.pop();
		for (int i = 0; i < G[v].size(); i++) {
			edge& e = G[v][i];
			if (e.cap > 0 && level[e.to] < 0) {
				level[e.to] = level[v] + 1;
				que.push(e.to);
			}
		}
	}
}

int dfs(int v, int t, int f) {
	if (v == t) return f;
	for (int& i = iter[v]; i < G[v].size(); i++) {
		edge& e = G[v][i];
		if (e.cap > 0 && level[v] < level[e.to]) {
			int d = dfs(e.to, t, min(f, e.cap));
			if (d > 0) {
				e.cap -= d;
				G[e.to][e.rev].cap += d;
				return d;
			}
		}
	}
	return 0;
}

int max_flow(int s, int t) {
	int flow = 0;
	while (true) {
		bfs(s);
		if (level[t] < 0) return flow;
		memset(iter, 0, sizeof(iter));
		int f;
		while ((f = dfs(s, t, INF)) > 0) {
			flow += f;
		}
	}
}

bool is_prime(int n) {
	if (1 == n) return false;
	for (int i = 2; i * i <= n; i++)if (0 == n % i) return false;
	return true;
}

int main()
{
	int N;
	cin >> N;
	vector<int> x(N);
	for (int i = 0; i < N; i++) {
		cin >> x[i];
	}
	vector<int> p;
	for (int i = 0; i < N; i++) {
		p.push_back(x[i]);
		for (; i < N - 1 && x[i] + 1 == x[i + 1]; i++);/* 連続スキップ */
		p.push_back(x[i] + 1);
	}
	int s = MAX_V - 2;
	int t = s + 1;
	int num = p.size();
	int evenNum = 0;
	for (int i = 0; i < num; i++) {
		if (0 == (p[i] % 2)) {
			add_edge(s, i, 1);
			evenNum++;
			for (int j = 0; j < num; j++) {
				int dst = abs(p[i] - p[j]);
				if (dst > 2 && is_prime(dst)) add_edge(i, j, 1);
			}
		} else {
			add_edge(i, t, 1);
		}
	}
	int f = max_flow(s, t);
	int ans = f;
	ans += ((evenNum - f)/2 + (num - evenNum - f)/2)*2 ;
	ans += ((evenNum - f) % 2) * 3;
	cout << ans << endl;
}



Measured memory_bytes: 384
a,b,c,d,e,f=map(int,input().split())
able_water=[]
for na in range(1+f//(a*100)):
  for nb in range(1+(f-na*a*100)//(b*100)):
    water=na*a*100+nb*b*100
    if water and water<=f:
      able_water.append(water)
able_water.sort()
import bisect
from fractions import Fraction
ans=[0,0,0]
max_s=(f*e+100-1)//100
for nd in range(1+max_s//d):
  for nc in range(1+(max_s-nd*d)//c):
    sugger=nc*c+nd*d
    min_water=(sugger*100+e-1)//e
    if min_water+sugger>f:continue
    idx=bisect.bisect_left(able_water,min_water)
    if idx <len(able_water) and able_water[idx]+sugger<=f:
      if ans[0]<=Fraction(sugger,(able_water[idx]+sugger)):
        ans=[Fraction(sugger,(able_water[idx]+sugger)),able_water[idx]+sugger,sugger]
print(ans[1],ans[2])

Measured memory_bytes: 5332
import math
from statistics import mean
ans = []
while True:
	n = int(input())
	if n == 0:
		break
	s = list(map(int,input().split()))
	ss = []
	for i in s:
		ss.append(i**2)
	sd = math.sqrt(mean(ss)-mean(s)**2)
	ans.append(sd)
for k in ans:
	print(k)


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

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	long long a, b;
	cin >> a >> b;

	if (a == 0 || b == 0 || a*b < 0) {
		cout << "Zero" << endl;
		return 0;
	}

	if (a > 0 || (-1 * a + b) % 2 == 1) {
		cout << "Positive" << endl;
	} else {
		cout << "Negative" << endl;
	}
	return 0;
}

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

int main()
{
    int a[3];
    cin>>a[0]>>a[1]>>a[2];
    swap(a[0],a[1]);
    swap(a[0],a[2]);
    cout<<a[0]<<" "<<a[1]<<" "<<a[2];
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
using namespace std;
int main()
{
  string c;
  cin >> c;
  if((c == "a") || (c == "i") || (c == "e") || (c == "u") || (c == "o"))
    cout << "vowel";
  else cout << "consonant";
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
	int n;
  cin>>n;
  vector<int >nos(n,0);
  for(int i=0;i<n;i++)cin>>nos[i];
  int pos=1;
  for(int i=n-2;i>=0;i--){
  	if(nos[i]<=nos[i+1])continue;
    if(nos[i]-1<=nos[i+1]){nos[i]-=1;continue;}
    pos=0;break;
  }
  if(pos==1)cout<<"Yes";
  else cout<<"No";
}

Measured memory_bytes: 3760
#include <bits/stdc++.h>
using namespace std;
#define rep(i, a) for(int i=0; i<(a); i++)
typedef long long ll;
template<typename T>
struct edge {
  int src, to;
  T cost;
  edge(int to, T cost) : src(-1), to(to), cost(cost) {}
  edge(int src, int to, T cost) : src(src), to(to), cost(cost) {}
  edge &operator=(const int &x) {
    to = x;
    return *this;
  }
  operator int() const { return to; }
};
template<typename T>
using Edges = vector<edge<T>>;
template<typename T>
using WeightedGraph = vector<Edges<T>>;
using UnWeightedGraph = vector<vector<int>>;
template<typename T>
using Matrix = vector<vector<T>>;

/////////////////////////////////////////////////////////////////////
const ll inf = 1LL<<60;

ll d;
vector<ll> c(26);
vector<vector<ll>> s(365, vector<ll>(26));
vector<ll> t(365);

vector<ll> calc() {
  vector<ll> nsc(26);
  vector<ll> score(d);
  vector<ll> last(26, -1);
  rep(i, d) {
    last[t[i]] = i;
    rep(j, 26) {
      if (t[i] == j) nsc[j] += s[i][j];
      else nsc[j] -= c[j]*(i-last[j]);
    }
    ll sum = 0;
    rep(j, 26) sum += nsc[j];
    score[i] = sum;
  }
  return score;
}

int main()
{
  srand((unsigned)time(NULL));

  cin>>d;
  rep(i, 26) cin>>c[i];
  rep(i, d) rep(j, 26) cin>>s[i][j];

  rep(i, d) {
    ll tmp = 0;
    ll ma = -inf;
    rep(j, 26) {
      if (s[i][j] > ma) {
        ma = s[i][j];
        tmp = j;
      } else if (s[i][j] == ma) {
        if (c[j] < c[tmp]) {
          tmp = j;
        }
      }
    }
    t[i] = tmp;
  }
  vector<ll> fsc = calc();

  {
    vector<ll> last(26, -1);
    vector<ll> nsc(26);
    rep(i, d) {
      ll idx = 0;
      ll sum = 0;
      rep(j, 26) {
        nsc[j] -= c[j]*(i-last[j]);
        sum += nsc[j];
      }
      rep(j, 26) {
        ll aa = sum + c[j]*(i-last[j]) + s[i][j];
        ll bb = sum + c[idx]*(i-last[idx]) + s[i][idx];
        if (aa > bb && aa >= fsc[i]) {
          idx = j;
        }
      }
      nsc[idx] += c[idx]*(i-last[idx]) + s[i][idx];
      last[idx] = i;
      t[i] = idx;
    }
  }
  vector<ll> ssc = calc();

  vector<vector<bool>> flg(365, vector<bool>(26, false));
  int ti = clock();
  while (clock() - ti < 195 * CLOCKS_PER_SEC / 100) {
    ll nd = rand() % d;
    ll nx = rand() % 26;
    if (flg[nd][nx]) continue;
    flg[nd][nx] = true;
    ll px = t[nd];
    t[nd] = nx;
    vector<ll> tsc = calc();
    if (ssc[d-1] < tsc[d-1]) {
      ssc = tsc;
    } else {
      t[nd] = px;
    }
  }

  rep(i, d) cout << t[i]+1 << endl;

  return 0;
}


Measured memory_bytes: 3780
#include<stdio.h>

int main()
{
    int a,b,c;
    scanf("%d %d %d", &a, &b, &c);
    if(a+b+c==17){
      if(a==5||b==5||c==5){
        if(a==7||b==7||c==7)
          printf("YES\n");
      }
    }
    else printf("NO\n");

    return 0;
}


Measured memory_bytes: 128
#include <iostream>
#include <vector>
#include <map>
#include <unordered_map>
#include <queue>
#include <set>
#include <algorithm>
#include <string>
#include <math.h>
#include <limits.h>
#include <stack>
#include <complex>
#include <stdlib.h>
#include <stdio.h>
#include <functional>
#include <cfloat>
#include <math.h>


#define fs first
#define sc second

using namespace std;

typedef long long ll;
typedef pair<int, int> P;
typedef pair<P, int> P2;

ll res[1010][1010];
P dir[4] = {P(1, 0), P(0, 1), P(-1, 0), P(0, -1)};
queue<P2> q;
int h, w;

bool ok(P x, P d){
    if(x.fs + d.fs < h && x.fs + d.fs >= 0 && x.sc + d.sc < w && x.sc + d.sc >= 0){
        return true;
    }
    else{
        return false;
    }
}

void solve(){
    while(!q.empty()){
        P2 x = q.front(); q.pop();
        P pos = x.fs;
        for(auto d: dir){
            P next = P(pos.fs + d.fs, pos.sc + d.sc);
            if(ok(pos, d) && res[next.fs][next.sc] == -1){
                res[next.fs][next.sc] = x.sc;
                q.push(P2(next, x.sc+1));
            }
        }
    }
}



int main(){
    cin >> h >> w;
    for(int i = 0; i < 1010; i++){
        for(int j = 0; j < 1010; j++){
            res[i][j] = -1;
        }
    }
    for(int i = 0; i < h; i++){
        for(int j = 0; j < w; j++){
            char c;
            cin >> c;
            if(c == '#'){
                res[i][j] = 0;
                q.push(P2(P(i, j), 1));
            }
        }
    }
    solve();

    ll ret = 0;
    for(int i = 0; i < h; i++){
        for(int j = 0; j < w; j++){
            ret = max(ret, res[i][j]);
        }
    }

    cout << ret << endl;

    return 0;
}


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

int main(){
	string dp[70][70];
	string max,ans;
	char c[70][70];
	int w,h,i,j;
	while(cin>>w>>h &&(w|h)){
		ans="";
		for(i=0;i<h;i++){
			for(j=0;j<w;j++)cin>>c[i][j];
		}
		for(i=0;i<h;i++){
			for(j=0;j<w;j++)dp[i][j].clear();
		}
		for(i=0;i<h;i++){
			for(j=0;j<w;j++){
				if(c[i][j]<'0'||'9'<c[i][j])continue;
				max = "";
				if(0<i)max = dp[i-1][j];
				if(0<j && (max.length()<dp[i][j-1].length()
					|| max.length()==dp[i][j-1].length() && max<dp[i][j-1]) )
					max= dp[i][j-1];
				if(max=="" &&  c[i][j]=='0')continue;
				dp[i][j] = max+c[i][j];
				if(ans.length() < dp[i][j].length()
					|| ans.length() == dp[i][j].length() && ans<dp[i][j]){
					ans=dp[i][j];
				}
			}
		}
		cout<<ans<<endl;
	}
}

Measured memory_bytes: 1044
from collections import defaultdict, deque

N = int(input())
dic = defaultdict(list)
color = [-1]*N

for _ in range(N-1):
    u, v, w = map(int, input().split())
    w %= 2
    dic[u].append([u, v, w])
    dic[v].append([v, u, w])

queue = deque()
color[0]=0
for i in dic[1]:
    queue.append(i)

while queue:
    u, v, w =map(int, queue.popleft())
    if (color[u-1]+w)%2==0:
        color[v-1]=0
    else:
        color[v-1]=1
    for i in dic[v]:
        if color[i[1]-1]==-1:
            queue.append(i)
print(*color)
        
    

Measured memory_bytes: 118536
from collections import Counter,defaultdict,deque
import sys,heapq,bisect,math,itertools,string,queue
sys.setrecursionlimit(10**8)
mod = 10**9+7
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))
def inpl_str(): return list(sys.stdin.readline().split())
def inpln(n): return list(int(sys.stdin.readline()) for i in range(n))

n = inp()
a = inpl()
if n%2:
    for i in range(n)[::-2]:
        print(a[i],end=' ')
    for i in range(1,n)[::2]:
        print(a[i],end=' ')
    print()
else:
    for i in range(n)[::-2]:
        print(a[i],end=' ')
    for i in range(n)[::2]:
        print(a[i],end=' ')
    print()
    

Measured memory_bytes: 87424
#include<cstdio>
using namespace std;
int main()
{
	int cnt,i,j,n,x,m[1000],min;
	scanf("%d %d",&n,&x);
	for(i=0;i<n;i++){
		scanf("%d",&m[i]);
		x-=m[i];
	}
	cnt=n;
	min=100000;
	for(i=0;i<n;i++){
		if(min>m[i]){
			min=m[i];
		}
	}
	while(1){
		if(x>=min){
			x-=min;
			cnt++;
		}
		else{
			break;
		}
	}
	printf("%d\n",cnt);
	return 0;
}


Measured memory_bytes: 128