akhauriyash/Code-Regression huggingface dataset:
/**
 *    author:  otera    
**/
#include<iostream>
#include<string> 
#include<cstdio>
#include<cstring>
#include<vector>
#include<cmath>
#include<algorithm> 
#include<functional>
#include<iomanip>
#include<queue>
#include<deque>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
#include<cassert>
using namespace std;

#define int long long
typedef long long ll;
typedef unsigned long long ul;
typedef unsigned int ui;
typedef long double ld;
const int inf=1e9+7;
const ll INF=1LL<<60 ;
const ll mod=1e9+7 ;
#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 complex<ld> Point;
const ld eps = 1e-8;
const ld pi = acos(-1.0);
typedef pair<int, int> P;
typedef pair<ld, ld> LDP;
typedef pair<ll, ll> LP;
#define fr first
#define sc second
#define all(c) c.begin(),c.end()
#define pb push_back
#define debug(x)  cerr << #x << " = " << (x) << endl;
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; }

void solve() {
	ll x, y; cin >> x >> y;
    if(abs(x - y) == 0 || abs(x - y) == 1) {
		cout << "Brown" << endl;
	} else {
		cout << "Alice" << endl;
	}
}

signed main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	//cout << fixed << setprecision(10);
	//int t; cin >> t; rep(i, t)solve();
	solve();
    return 0;
}

Measured memory_bytes: 3640
#include <iostream>
#include <iomanip>
#include <utility>
#include <cmath>
#include <random>
#include <vector>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <string>
#include <algorithm>
using namespace std;

#define rep(i,n) for(int i = 0; i<n; ++i)
#define REP(i,n) for(int i = 1; i<=n; ++i)
#define all(x) begin(x),end(x)
typedef long long ll;
typedef pair<int,int> ip;
typedef pair<ll,ll> lp;
const int inf = 1001001000;
const ll INF = 1LL<<60;
const int MOD = (int)1e9 + 7;

int main(){
	int N;
	cin>>N;
	map<ll,ll> A;
	A[0LL] = 1LL;
	rep(i,N){
		ll a;
		cin>>a;
		A[a]++;
	}
	auto itr = --A.end();
	ll x = INF;
	for(; itr!=A.begin(); --itr){
		ll len = itr->first;
		ll cnt = itr->second;
		//cout<<len<<' '<<cnt<<endl;
		if(x == INF && cnt>=4LL){
			cout<<len*len<<endl;
			return 0;
		}
		if(cnt>=2LL){
			if(x == INF)x = len;
			else {
				cout<<len*x<<endl;
				return 0;
			}
		}
	}
	cout<<0<<endl;
	return 0;
}

Measured memory_bytes: 6528
import java.io.PrintWriter

fun next() = readLine()!!
fun nextInt() = next().toInt()
fun nextLong() = next().toLong()
fun nextDouble() = next().toDouble()
fun nextList() = next().split(" ")
fun nextIntList() = nextList().map(String::toInt)
fun nextLongList() = nextList().map(String::toLong)
fun nextDoubleList() = nextList().map(String::toDouble)

val pw = PrintWriter(System.out)
fun print(s: Any = "") = pw.print(s)
fun println(s: Any = "") = pw.println(s)

fun <T> Iterable<T>.join(separator: CharSequence = ", ", prefix: CharSequence = "", postfix: CharSequence = "") = joinToString(separator, prefix, postfix)
fun <T> Array<T>.join(separator: CharSequence = ", ", prefix: CharSequence = "", postfix: CharSequence = "") = joinToString(separator, prefix, postfix)

fun main(args: Array<String>) {
    main()
    pw.flush()
}

fun main() {
    val (A, B, C) = nextIntList()
    println(A * B / 2)
}

Measured memory_bytes: 36332
#include<iostream>
#include<vector>
#include<algorithm>

using ull = unsigned long long;

int main() {
	ull n;
	std::cin >> n;

	ull A[10001]{};

	for (ull i{}; i < n; ++i) {
		ull t;
		std::cin >> t;
		++A[t];
	}
	/*
	for (int i{}; i < n; i++) {
		std::cout << A[i] << " ";
	}*/
	auto count{0};
	for (ull i{}; i < 10001; ++i) {
		for (ull j{}; j < A[i]; ++j) {
			
			std::cout << i << (count<n-1?" ":"\n");
			count++;
		}
	}

	return 0;
}



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

using namespace std;
using ll = long long;

int main(){
    int n;
    cin>>n;
    map<string,int> mp;
    for (int i = 0; i < n; ++i) {
        string s;
        cin >> s;
        ++mp[s];
    }
    int cnt=-1;
    for(auto i:mp){
        if(cnt<i.second){
            cnt=i.second;
        }
    }
    for(auto i:mp){
        if(cnt==i.second){
            cout<<i.first<<endl;
        }
    }
    return 0;
}

Measured memory_bytes: 25216
import sys
from math import log2, floor

n, k, *A = map(int, sys.stdin.read().split())

def main():
    if k == 0:
        return sum(A)

    bits = [0] * 40
    for a in A:
        for i in range(40):
            bits[i] += a >> i & 1

    bl = [bits[i] < n / 2 for i in range(40)]

    k_bit = [k >> i & 1 for i in range(40)]
    i = floor(log2(k))
    while True:
        tmp_x = 2 ** i - 1
        x_bit = [tmp_x >> j & 1 for j in range(40)]
        res1 = 0
        res2 = 0
        for j in range(i+1):
            if k_bit[j] & bl[j]:
                res1 += 2 ** j * (n - bits[j])
            else:
                res1 += 2 ** j * bits[j]
            
            if x_bit[j] & bl[j]:
                res2 += 2 ** j * (n - bits[j])
            else:
                res2 += 2 ** j * bits[j]
            
        if res2 > res1:
            for j in range(i):
                k_bit[j] |= 1
            k_bit[i] = 0
            break

        for j in range(i-1, -1, -1):
            if k_bit[j] == 1:
                i = j
                break
        else:
            break

    res = 0
    for i in range(40):
        if bl[i] & k_bit[i]:
            res += 2 ** i * (n - bits[i])
        else:
            res += 2 ** i * bits[i]
    
    return res

if __name__ == '__main__':
    ans = main()
    print(ans)

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

int main(){
  int n;
  cin >> n;
  int sum = 0;
  vector<int> s(n);
  for (int i = 0; i < n; i++) {
    cin >> s.at(i);
    sum += s.at(i);
  }
  sort(s.begin(), s.end());
  if (sum % 10 != 0) {
    cout << sum << endl;
    return 0;
  }
  for (int i = 0; i < n; i++) {
    if ((sum - s.at(i)) % 10 == 0) {
      continue;
    } else {
      cout << sum - s.at(i) << endl;
      return 0;
    }
  }
  cout << 0 << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define int long long
#define N 200005

using namespace std;
typedef long long ll;

template <class T> inline void read(T &x) {
	char ch; bool flag = false;
	while (!isdigit(ch = getchar())) flag |= ch == '-';
	for (x = ch ^ 48; isdigit(ch = getchar()); x = x * 10 + (ch ^ 48));
	if (flag) x = -x;
}

inline int input() {
	int x; char ch; bool flag = false;
	while (!isdigit(ch = getchar())) flag |= ch == '-';
	for (x = ch ^ 48; isdigit(ch = getchar()); x = x * 10 + (ch ^ 48));
	return flag ? -x : x;
}

const int mod = 1e9 + 7;
inline int add(int x, int y) { x += y; return x >= mod ? x - mod : x; }
inline void inc(int &x, int y) { x += y; x -= x >= mod ? mod : 0; }

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

template <class T> void chkmax(T &x, T y) { x = x > y ? x : y; }
template <class T> void chkmin(T &x, T y) { x = x < y ? x : y; }
template <class T> T gcd(T x, T y) { return !y ? x : gcd(x % y, y); }

struct node{int x, opt, id;} c[N];
bool cmp(node g, node h){return g.x < h.x;}
int n, a[N], b[N], ans, cnt, d[N], w[3], t;

signed main() {
	ios::sync_with_stdio(false);
	cin >> n;
	for(int i = 1; i <= n; i++){
		cin >> a[i] >> b[i];
		c[++cnt].x = a[i], c[cnt].id = i, c[cnt].opt = 0;
		c[++cnt].x = b[i], c[cnt].id = i, c[cnt].opt = 1;
	}
	sort(c + 1, c + cnt + 1, cmp);
	for(int i = 1; i <= n; i++){
		d[c[i].id]++; ans += c[i].x;
		w[c[i].opt]++; if(d[c[i].id] == 2) t = 1;
	}
	if(t == 1 || w[1] == 0 || w[0] == 0){
		cout << ans << endl; return 0;
	}
	ll Ans = LLONG_MAX;
	for(int i = 1; i <= n; i++){
		if(c[n].id != i) Ans = min(Ans, ans + max(a[i], b[i]) - c[n].x);
		else Ans = min(Ans, ans + max(a[i], b[i]) - c[n - 1].x);
	}
	cout << Ans << endl;
	return 0;
}


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

sys.setrecursionlimit(10000)

H, W, N = (int(i) for i in input().split())
if N == 0:
    reslis = [0] * 10
    reslis[0] = (H-2)*(W-2) - sum(reslis)
else:
    L = []
    for k in range(N):
        a, b = (int(i) for i in input().split())
        for i in range(3):
            for j in range(3):
                if 1 <= a - 2 + i <= H - 2 and 1 <= b - 2 + j <= W - 2:
                    L.append((a-2 + i, b-2 + j))
    L.sort()
    temp = None
    cc = 1
    reslis = [0] * 10
    for se in L:
        if temp == se:
            cc += 1
        else:
            if temp == None:
                pass
            else:
                reslis[cc] += 1
                cc = 1
            temp = se
    reslis[cc] += 1

    reslis[0] = (H-2)*(W-2) - sum(reslis)

for i in reslis:
    print(i)

Measured memory_bytes: 128032
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <cmath>
#include <math.h>
#include <vector>
#include <algorithm>
#include <stack>
#include <set>
#include <ctime>
#include <queue>
#include <deque>
#include <unordered_map>
#include <map>
#include <random>
#include <cstdio>
#include <string>
#include <cctype>
#define int long long
#define pb push_back
#define eb emplace_back
#define rs resize
#define ld long double
#define vi vector<int>
#define vpii vector<pair<int, int>>
#define ull unsigned long long 

using namespace std;

const int SZ = (int)1e6 + 228;

void solve() {
    int n, k;
    cin >> n >> k;
    vi a(n);
    for (int i = 0; i < n; i++) {
        cin >> a[i];
    }
    int ans = 0;
    sort(a.begin(), a.end());
    for (int i = 0; i < k; i++) {
        ans += a[i];
    }
    cout << ans;
}

signed main() {
    //freopen("olympiad.in", "r", stdin);
    //freopen("olympiad.out", "w", stdout);
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cout << fixed;
    cout.precision(30);
    int t = 1;
    //cin >> t;
    while (t--)
        solve();
    //   system("pause");
}

Measured memory_bytes: 3192
// 
#include <algorithm>
#include <bitset>
#include <cmath>
#include <functional>
#include <iomanip>
#include <ios>
#include <iostream>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
using ll = long long;
using P = pair<int,int>;

int calc_tax(int val, float rate) {
    int tax = (float)val * rate;
    return tax;
}

int main() {
    double A, B;
    cin >> A >> B;
    
    int i;
    rep(i, 1000) {
        if ((calc_tax(i+1, 0.08) == A) && (calc_tax(i+1, 0.1) == B)) {
            cout << i + 1 << endl;
            return 0;
        }
    }

    cout << -1 << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int n;
typedef long long ll;
const int maxn = 2e5+5;
ll a[maxn],b[maxn];
int get_num(){
	int num = 0;
	char c;
	bool flag = false;
	while((c = getchar()) == ' ' || c == '\r' || c == '\n');
	if(c == '-')
		flag = true;
	else num = c - '0';
	while(isdigit(c = getchar()))
		num = (num<<3) + (num<<1) + c - '0';
	return (flag ? -1 : 1) * num;
}
ll ret = 0;
ll mxa,mna,mxb,mnb;
ll dmx,dmi;
ll id[maxn];
bool cmp(int x,int y){
	return a[x] < a[y];
}
int main(){
	n = get_num();
	mna = mnb = 1e9;
	for(int i = 1;i <= n;++i){
		id[i] = i;
		a[i] = get_num();
		b[i] = get_num();
		if(a[i] > b[i])swap(a[i],b[i]);
		mxa = max(mxa,a[i]);
		mna = min(mna,a[i]);
		mxb = max(mxb,b[i]);
		mnb = min(mnb,b[i]);
	}
	ret = (mxb - mnb) * (mxa - mna);
	dmx = 0;
	dmi = 1e9;
	sort(id+1,id+n+1,cmp);
	for(int i = 1;i <= n;++i){
		dmx = max(dmx,b[id[i]]);
		dmi = min(dmi,b[id[i]]);
		ret = min(ret,(ll)(max(dmx,a[id[n]])-min(dmi,a[id[i+1]])) * (mxb - mna));
	}
	cout << ret << endl;
	return 0;
}

Measured memory_bytes: 4992
#include<stdio.h>
#include<string.h>
#include<algorithm>
using namespace std;
int a[4][4];
int main()
{
    int n,x1,x2,x3,y1,y2,y3,i,j,k,flag;
    for(i=1;i<=3;i++)
    for(j=1;j<=3;j++)
    scanf("%d",&a[i][j]);
    for(x1=0;x1<=100;x1++)
    for(x2=0;x2<=100;x2++)
    for(x3=0;x3<=100;x3++)
    {
        flag=1;
        y1=a[1][1]-x1;
        y2=a[2][1]-x2;
        y3=a[3][1]-x3;
        if(y1!=y2||y1!=y3||y2!=y3)
            flag=0;
        y1=a[1][2]-x1;
        y2=a[2][2]-x2;
        y3=a[3][2]-x3;
        if(y1!=y2||y1!=y3||y2!=y3)
            flag=0;
        y1=a[1][3]-x1;
        y2=a[2][3]-x2;
        y3=a[3][3]-x3;
        if(y1!=y2||y1!=y3||y2!=y3)
            flag=0;
        if(flag==1)
        {
            printf("Yes\n");
            return 0;
        }
    }
    printf("No\n");
    return 0;
}


Measured memory_bytes: 128
#include<iostream>

using namespace std;

int main(void)
{
	int a,b;
	while(cin>>a>>b)
	{
		int c=a+b;
		int ans=1;
		while(1){
			c=c/10;
			if(c==0){break;}
			else{
				ans++;
			}
		}
		cout<<ans<<endl;
	}
}

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


int main(){
	    int K, X; cin >> K >> X;
        if(500 * K >= X) cout << "Yes" << endl;
        else cout << "No" << endl;
}


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

count,ans = 0,0
for i in range(1,N+1):
    if i%2 == 1:
        for j in range(1,i+1):
            if i%j==0:
                count += 1

    if count == 8:
        ans += 1
    count = 0

print(ans)

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

int main()
{
    string s, t;
    cin >> s >> t;
    if (s[0] == t[2] && s[1] == t[1] && s[2] == t[0])
    {
        cout << "YES" << endl;
    }
    else
    {
        cout << "NO" << endl;
    }
}

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

int main() {
  int sx, sy, tx, ty;
  cin >> sx >> sy >> tx >> ty;
  for (int i = 0; i < (tx - sx); i++) cout << 'R';
  for (int i = 0; i < (ty - sy); i++) cout << 'U';
  for (int i = 0; i < (tx - sx); i++) cout << 'L';
  for (int i = 0; i < (ty - sy) + 1; i++) cout << 'D';
  for (int i = 0; i < (tx - sx) + 1; i++) cout << 'R';
  for (int i = 0; i < (ty - sy) + 1; i++) cout << 'U';
  cout << "LU";
  for (int i = 0; i < (tx - sx) + 1; i++) cout << 'L';
  for (int i = 0; i < (ty - sy) + 1; i++) cout << 'D';
  cout << 'R' << endl;
}

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

int main() {
  int N;
  cin>>N;
  vector<int>B(N-1);
  rep(i,N-1) cin>>B[i];
  int C=B[0];
  rep(i,N-2) C+=min(B[i],B[i+1]);
  cout<<C+B[N-2]<<endl;

  
}

  
  

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define MEM 100001
#define sanic ios_base::sync_with_stdio(0)
using namespace std;
typedef long long ll;
const ll INF = 1e9+9;
ll l;
string s;
int main() {
    cin >> s;
    l = s.size();
    ll st=0;
    while(st<=l/2){
        if(s[st]!=s[l-st-1]){
            cout << "No";
            return 0;
        }
        st++;
    }
    st=0;
    ll pe=(l-1)/2;
    while(st<=pe/2){
        if(s[st]!=s[pe-st-1]){
            cout << "No";
            return 0;
        }
        st++;
    }
    st=(l+3)/2;
    while(st<=l/2+pe/2){
        if(s[st]!=s[l-st-1]){
            cout << "No";
            return 0;
        }
        st++;
    }
    cout << "Yes";
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <cmath>
#include <string>
#include <sstream>
using namespace std;
vector<string> arr;

void dec(int index,int residue,string s)
{
  if(index==0)
  {
    if (residue<10)
    {
      arr.push_back(s+(char)(residue-0+'0'));
    }
    return;
  }
  int alpha=pow(2,index);

    int n=residue/alpha;

      for(int i=0;i<=9&i<=n;i++)
      {
        char f=(char)(i-0+'0');
        dec(index-1,residue-alpha*i,s+f);
      }


}
int main()
{
	// your code goes here
  int n;
  cin>>n;
  cout<<180*(n-2)<<endl;
  /*int t;
  cin>>t;
  while(t--)
  {
    int n;
    cin>>n;
    int z;
    stringstream geek(arr[n-1]);
    geek>>z;
    cout<<z<<endl;
  }

  /*for(int o=0;o<arr.size();o++)
  {
    stringstream geek(arr[o]);
    int xyz;
    geek>>xyz;
    cout<<xyz<<endl;
  }*/
  

	return 0;
}


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

int main(){
	int h, w;
	for(;;){
		cin >> h >> w;
		if(h == 0) return 0;
		for(int i = 0; i < h; i++){
			string line(w, '#');
			cout << line << endl;
		}
		cout << endl;
	}
}

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

int main(int argc, char const *argv[])
{
	int n;
	cin>>n;
	int x[n],y[n];
	for (int i = 0; i < n; ++i)
	{
		cin>>x[i]>>y[i];
	}
	map<pair<int,int>,int> mp;
	int ans=0;
	for (int i = 0; i < n; ++i)
	{
		for (int j = 0; j < n; ++j)
		{
			if (i==j)
			{
				continue;
			}
			++mp[make_pair(x[i]-x[j],y[i]-y[j])];
			ans=max(ans,mp[make_pair(x[i]-x[j],y[i]-y[j])]);
		}
	}
	cout<<n-ans<<endl;
	return 0;
}


Measured memory_bytes: 384
//#pragma GCC optimize ("-O3","unroll-loops")
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<math.h>
#include<iomanip>
#include<set>
#include<numeric>
#include<cstring>
#include<cstdio>
#include<functional>
#include<bitset>
#include<limits.h>
#include<cassert>
#include<iterator>
#include<complex>
#include<stack>
#include<unordered_map>
#include<unordered_set>
#include<time.h>
#include<random>

using namespace std;

#define REP(i, n) for(int i = 0;i < n;++i)
#define REPR(i, n) for(int i = n-1;i >= 0;--i)
#define FOR(i, m, n) for(int i = m;i < n;++i)
#define FORR(i, m, n) for(int i = m-1;i >= n;--i)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define REVERSE(v,n) reverse(v,v+n);
#define VREVERSE(v) reverse(v.begin(), v.end())
#define ll long long
#define pb(a) push_back
#define print(x) cout<<(x)<<endl
#define pe(x) cout<<(x)<<" "
#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define lb(v,n) lower_bound(v.begin(), v.end(), n)
#define ub(v,n) upper_bound(v.begin(), v.end(), n)
//#define int long long
#define all(x) (x).begin(), (x).end()
#define print_space(v) REP(i,v.size())cout << v[i] << ((i == v.size() - 1) ? "\n" : " ")

template<typename T1, typename T2> inline void chmin(T1 & a, T2 b) { if (a > b) a = b; }
template<typename T1, typename T2> inline void chmax(T1& a, T2 b) { if (a < b) a = b; }
//typedef pair<int, int>P;
const int MOD = 1e9 + 7; const int MAX = 200020;
const double pi = acos(-1); const double EPS = 1e-12;
const ll INF = 1e16;


double X[10], Y[10];

double dist(double x1, double y1, double x2, double y2) {
	return sqrt((x1 - x2)*(x1 - x2) + (y1 - y2)*(y1 - y2));
}
void solve() {
	int N; cin >> N;
	REP(i, N)cin >> X[i] >> Y[i];
	int perm[10];
	REP(i, N)perm[i] = i;
	double ans = 0;
	do {
		REP(i, N - 1) {
			ans += dist(X[perm[i]], Y[perm[i]], X[perm[i+1]], Y[perm[i + 1]]);
		}
	} while (next_permutation(perm, perm + N));;
	int fac = 1;
	FOR(i, 1, N + 1)fac *= i;
	ans /= (double)fac;
	cout << setprecision(20) << ans << endl;
}

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

	solve();

}



Measured memory_bytes: 256
// -----------------------------------
// Author     : MatsuTaku
// Affiliation: Tokushima University
// Country    : Japan
// Date       : 04/08/2020
// -----------------------------------

#include <bits/stdc++.h>

using namespace std;
using ll = long long;

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

  int n,k; cin>>n>>k;
  ll ans=0;
  if (k == 0)
    ans = (ll)n*n;
  else {
    for (ll b = k+1; b <= n; b++) {
      ans += (b-k)*(n/b);
      if (n%b>=k)
        ans += n%b-k+1;
    }
  }
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
import sys
H, W, N = map(int, input().split())
Sr, Sc = map(int, input().split())
S = input()
T = input()

True_arr = [0, 0, 0, 0]

LRUD_S = {"L":0, "R":1, "U":2, "D":3}
LRUD_T = {"R":0, "L":1, "D":2, "U":3}

for i in range(N):
    if True_arr[LRUD_T[T[-i-1]]] > 0:
        True_arr[LRUD_T[T[-i-1]]] -= 1
    
    True_arr[LRUD_S[S[-i-1]]] += 1
    if True_arr[0] == W or True_arr[1] == W or True_arr[2] == H or True_arr[3] == H:
        break

if Sr > True_arr[2] and Sr <= H - True_arr[3] and Sc > True_arr[0] and Sc <= W - True_arr[1]:
    print("YES")
else:
    print("NO")

Measured memory_bytes: 3784
//↓template↓

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

ll mod_pow(ll a, ll b) {
	ll res = 1, mul = a;
	for (int i = 0; i < 31; ++i) {
		if (b >> i & 1) {
			res *= mul;
			res %= MOD;
		}
		mul = (mul * mul) % MOD;
	}
	return res;
}

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

template<typename T>
vector<T> make_v(size_t a) { return vector<T>(a); }

template<typename T, typename... Ts>
auto make_v(size_t a, Ts... ts) {
	return vector<decltype(make_v<T>(ts...))>(a, make_v<T>(ts...));
}

template<typename T, typename V>
typename enable_if<is_class<T>::value == 0>::type
fill_v(T & t, const V & v) { t = v; }

template<typename T, typename V>
typename enable_if<is_class<T>::value != 0>::type
fill_v(T & t, const V & v) {
	for (auto& e : t) fill_v(e, v);
}

template<typename T>
void outp(vector<T>v) {
	for (int i = 0; i < v.size(); ++i) {
		cout << v[i];
		if (i != v.size() - 1) { cout << " "; }
	}
}

double add(double a, double b) {
	if (abs(a + b) < EPS * (abs(a) + abs(b))) { return 0; }
	return a + b;
}


//↑template↑

int main() {
	int n;
	cin >> n;
	set<ll>s;
	for (int i = 0; i < n; ++i) {
		int a, b;
		cin >> a >> b;
		if (a == 0) {
			s.insert(b);
			cout << s.size() << endl;
		}
		else {
			cout << s.count(b) << endl;
		}
	}
}


Measured memory_bytes: 12436
from collections import deque

N = int(input())

G = [set() for i in range(N)]
for _ in range(N-1):
    a, b, c = map(int, input().split())
    G[a-1].add((b, c))
    G[b-1].add((a, c))

Q, K = map(int, input().split())

visited = [False] * N
visited[K-1] = True

distance = [-1]*N

que = deque([(K, 0)])
while que:
    cur, d = que.popleft()
    distance[cur-1] = d

    for nx, nd in G[cur-1]:
        if visited[nx-1] is False:
            visited[nx-1] = True
            que.append((nx, d+nd))

for i in range(Q):
    x, y = map(int, input().split())
    print(distance[x-1]+distance[y-1])


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

#define fi first
#define se second
#define show(x) cerr << #x << "=" << "\n"
typedef long long ll;
typedef unsigned long long ull;

using namespace std;
const ll llinf = LLONG_MAX;
const ull ullinf = ULLONG_MAX;

int n, k;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.precision(10);
  cout << fixed;
#ifdef LOCAL_DEFINE
  FILE *stream1;
  //FILE *stream2;
  stream1 = freopen("in.txt", "r", stdin);
  //stream2 = freopen("out.txt", "w", stdout);
  if (stream1 == NULL) return 0;
  //if (stream2 == NULL) return 0;
#endif
  cin >> n >> k;
  vector<int> v;
  int cont = 0;
  for (int i = 0; i < n; i++) {
    int a; cin >> a;
    if (a == 1) {
      v.push_back(cont);
      cont = 0;
    } else {
      cont++;
    }
  }
  v.push_back(cont);
  int ans = v[0] / (k - 1) + (v[0] % (k - 1) != 0) + v[1] / (k - 1) + (v[1] % (k - 1) != 0);
  //cout << ans << endl;
  cout << (n - 1) / (k - 1) + ((n - 1) % (k - 1) != 0) << endl;
#ifdef LOCAL_DEFINE
  cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << "s.\n";
  fclose(stream1);
  //fclose(stream2);
#endif
  return 0;
}


Measured memory_bytes: 256
n, x = map(int, input().split(" "))
a = list(map(int, input().split(" ")))

def main():
	capacity = sum(a)
	if x > capacity:
		print(n - 1)
		return
	elif x == capacity:
		print(n)
		return
	else:
		b = sorted(a)
		ans = 0
		y = x
		for i in range(0, n):
			y -= b[i]
			if y < 0:
				break
			ans += 1
		print(ans)
		return

main()

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

int main(){
  int n;
  long int S = 0;
  bool flag = false;;
  cin >> n;

  for(int i = 0; i < n; i++){
    char c;
    int x;
    cin >> c >> x;
    if(c == '(') S += x;
    else S -= x;
    if (S < 0){
      flag = true;
    }
  }
  
  if(S == 0 && !flag) cout << "YES" << endl;
  else cout << "NO" << endl;
  return 0;
}


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

const char NL = '\n';
const int MOD = 1e9 + 7;

// A - Frog 1
// https://atcoder.jp/contests/dp/tasks/dp_a

void solve()
{
    int n; cin >> n;
    vector<int> v;
    for (int i = 0; i < n; ++i) {
        int h; cin >> h;
        v.push_back(h);
    }
    vector<int> dp(n, 0);
    dp[1] = abs(v[1] - v[0]);
    for (int i = 2; i < n; ++i) {
        dp[i] = min(dp[i - 1] + abs(v[i] - v[i - 1]), dp[i - 2] + abs(v[i] - v[i - 2]));
    }
    cout << dp[n - 1] << NL;
}

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    solve();
    return 0;
}

Measured memory_bytes: 4196
#include<bits/stdc++.h>
#define ll          long long
#define pb          push_back
#define INF         9223372036854775807
#define    endl        '\n'
#define pii         pair<ll int,ll int>
#define vi          vector<ll int>
#define all(a)      (a).begin(),(a).end()
#define F           first
#define S           second
#define sz(x)       (ll int)x.size()
#define hell        1000000007
#define rep(i,a,b)    for(ll int i=a;i<b;i++)
#define lbnd        lower_bound
#define ubnd        upper_bound
#define bs          binary_search
#define mp          make_pair
#define lower(u)    transform(u.begin(), u.end(), u.begin(), ::tolower);//convert string u to lowercase;
#define upper(u)    transform(u.begin(), u.end(), u.begin(), ::toupper);
using namespace std;

#define N  100005

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int TESTS=1;
//    cin>>TESTS;
    while(TESTS--)
    {
        char c;
        cin>>c;
        char d=c+1;
        cout<<d<<endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <cstdio>
#include <functional>
#include <iostream>
#include <cfloat>
#include <climits>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <time.h>
#include <complex>
#include <vector>
#include <limits>
#include <iomanip>
#include <cassert>
// #include <atcoder/fenwicktree>

using namespace std;
// using namespace atcoder;

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

#define debug(x) cout << #x << " = " << (x) << endl;
#define rep(i, n) for(int i = 0;i < n;i++)
#define repr(i, n) for(int i = n-1;i >= 0;i--)
#define pb push_back
#define mp make_pair
#define F first
#define S second

const long double pi = 3.141592653589793;
const int mod = 1e9 + 7;

int main() {

 // freopen("input.in","r",stdin);
 // freopen("output.out","w",stdout);

 ios_base::sync_with_stdio(false);
 cin.tie(nullptr);
 ll a, b, c, n;
 cin>>n;
 a = b = c = 1;
 rep(i, n) {
   a*=10;
   b*=9;
   c*=8;
   a %= mod;
   b %= mod;
   c %= mod;
 }
 cout << (a+c+mod-2*b%mod)%mod << endl;


 return 0;
}


Measured memory_bytes: 3596
import java.util.Scanner;

public class Main {

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

		int w = scan.nextInt();
		int a = scan.nextInt();
		int b = scan.nextInt();

		if(a+w < b){
			System.out.println(b-(a+w));
		}else if(a > b+w){
			System.out.println(a-(b+w));
		}else{
			System.out.println("0");
		}

	}

}

Measured memory_bytes: 21844
N = gets.to_i
a = gets.split.map(&:to_i)
all = a.reduce(:+)
a_odd = 0
a[0...-1].each_with_index do |v, i|
  next if i % 2 == 1
  a_odd += v
end
last_v = all - a_odd * 2
first_v = (a[-1]*2 - last_v)
ans = []
ans << first_v
a.each do |v|
  ans << v * 2 - ans[-1]
end
puts ans[0...-1]

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

int main(){
  long long int m=1000000007,ans=0;
  int x,y,a,b;
  cin >> x >> y;
  if((x+y)%3==0){ 
    a=(2*y-x)/3;
    b=(2*x-y)/3;
    if(a>=0&&b>=0){
      long long int p=1,q=1;
      for(int i=a+b;i>a;i--){
        p*=i;
        p%=m;
        q*=(i-a);
        q%=m;
      }
      for(int i=0;i<m;i++){
        if(i*q%m==p){
          ans=i;
          break;
        }
      }
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
#define rep(i,a,b) for(ll i=ll(a);i<ll(b);i++)
#define irep(i,a,b) for(ll i=ll(a);i>=ll(b);i--)
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
#define pb push_back
#define mp make_pair
#define F .first
#define S .second 
#define pll pair<ll,ll>
using ll=long long;
using ld=long double;
const ll INF = 1LL<<60;
const ll mod=1e9+7;
using namespace std;
ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
ll a[1100000];
int main(){
    ll n;
    cin>>n;
    ll sum=0,ans=0;
    rep(i,0,n){cin>>a[i];sum+=a[i];}
sum%=mod;
    rep(i,0,n){
        sum-=a[i];
        if(sum<0)sum+=mod;
        ll pos=(sum*a[i])%mod;
        ans=(ans+pos)%mod;
    }
    cout<<(ans%mod);
}




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

int main() {
  int N;
  int counter = 0;
  int temp = 0;
  
  cin >> N;
  vector<int> mochi(N);
  for(int i=0; i<N; i++){
    cin >> mochi.at(i);
  }
  
  sort(mochi.begin(), mochi.end());
  for(int i=0; i<N; i++){
    if(mochi.at(i) != temp){
      counter++;
    }
    temp = mochi.at(i);
  }
  
  cout << counter << endl;

}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <set>
#include <queue>
#include <stack>
#define ll long long
#define rep(i,n) for(int i=0;i<(n);i++)
using namespace std;
const int MOD = 1000000007;
int gcd(int a,int b){
    while(b!=0){
        a %= b;
        if(a==0) return b;
        b %= a;
    }
    return a;
}
int main(){
    int n,x;
    cin >> n >> x;
    int t[n],y[n];
    rep(i,n){
        cin >> t[i];
        y[i]=abs(t[i]-x);
    }
    int ans = y[0];
    rep(i,n){
        ans=gcd(ans,y[i]);
    }
    cout << ans << endl;
    
}



Measured memory_bytes: 1024
use std::str::FromStr;

fn main() {
    let stdin = std::io::stdin();
    let mut buf = String::new();
    stdin.read_line(&mut buf).ok();
    let mut it = buf.split_whitespace().map(|n| usize::from_str(n).unwrap());
    let (a, b) = (it.next().unwrap(), it.next().unwrap());
    if (a+b) % 2 == 0 {
        println!("{}\n", (a+b) / 2);
    }
    else {
        println!("IMPOSSIBLE\n");
    }
}

Measured memory_bytes: 4352
#include <iostream>
#include <iomanip>
#include<vector>
#include <algorithm>
#include <queue>
#include<string>
#include <map>
#include <cmath>
#include <deque>
#include <list>
#include <stack>
#include <queue>
#include <utility>
#include <set>
#include <bitset>
typedef long long ll;
typedef long double ld;

#define REP(i,s,n)for(ll i=s;i<(n);++i)
#define rep(i,n) REP(i,0,n)
using namespace std;

ll counter(ll x) {
	if (x == 0)return 0;
	return counter(x >> 1) + (x & 1);
}

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

	for (ll i = 0; i < (1 << N); ++i) {
		if (counter(i) == K) {
			vector<ll>C;
			for (int j = 0; j < N; ++j) {
				if ((i&(1 << j))) {
					C.push_back(A[j]);
				}
			}
			cout << i << ":";
			for (int j = 0; j < C.size(); ++j) {
				cout << " " << C[j];
			}
			cout << endl;
		}
	}
	return 0;
}


Measured memory_bytes: 3168
H, W = [int(a) for a in input().split()]
S = [None] * H
for i in range(H):
    S[i] = input()

L = [[0 for _ in range(W)] for _ in range(H)]
R = [[0 for _ in range(W)] for _ in range(H)]
U = [[0 for _ in range(W)] for _ in range(H)]
D = [[0 for _ in range(W)] for _ in range(H)]

ans = 0

# L, R, Uを求める
for i in range(H):
    for j in range(W):

        if S[i][j] == '#':
            pass  # L, R, Uは0で初期化されている
        else:
            # Uを求める
            if i == 0:  U[i][j] = 1
            else:       U[i][j] = U[i - 1][j] + 1

            # Lを求める
            if j == 0:  L[i][j] = 1
            else:       L[i][j] = L[i][j - 1] + 1

        # Rを求める
        if S[i][W - 1 - j] == '#':
            pass
        elif j == 0:
            R[i][W - 1 - j] = 1
        else:
            R[i][W - 1 - j] = R[i][W - j] + 1

# Dを求める
for i in range(H - 1, -1, -1):
    for j in range(W):
        if S[i][j] == '#':  pass
        elif i == H - 1:    D[i][j] = 1
        else:               D[i][j] = D[i + 1][j] + 1
        ans = max(ans, L[i][j] + R[i][j] + U[i][j] + D[i][j] - 3)

print(ans)

Measured memory_bytes: 185476
#include<stdio.h>
main(){
  int kazu[100][100];
  int i,j,k;
  int n;
  int count;
  while(1){
    scanf("%d",&n);
    if(n==0) break;
    for(i=0;i<n;i++){
      for(j=0;j<n;j++){
	scanf("%d",&kazu[i][j]);
      }
    }
    for(i=0;i<n;i++){
      count=0;
      for(j=0;j<n;j++){
	count+=kazu[i][j];
      }
      kazu[i][n]=count;
    }
    for(i=0;i<n;i++){
      count=0;
      for(j=0;j<n;j++){
	count+=kazu[j][i];
      }
      kazu[n][i]=count;
    }
    count=0;
    for(i=0;i<n;i++){
      count+=kazu[n][i];
    }
    kazu[n][n]=count;
    for(i=0;i<n+1;i++){
      for(j=0;j<n+1;j++){
	printf("%5d",kazu[i][j]);
      }
      printf("\n");
    }
  }
  return 0;
}

Measured memory_bytes: 628
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class Main {
    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        StringBuilder sb = new StringBuilder();
        // code goes here
        int[] arr = nextIntArray(br, 3);
        int d = arr[0];
        int t = arr[1];
        int s = arr[2];
        if((d*1.0/s) > t){
            sb.append("No\n");
        }else{
            sb.append("Yes\n");
        }
        System.out.print(sb.toString());
    }

    private static int nextInt(BufferedReader br) throws IOException{
        return Integer.parseInt(br.readLine());
    }

    private static int[] nextIntArray(BufferedReader br, int n) throws IOException{
        StringTokenizer st = new StringTokenizer(br.readLine());
        int[] arr = new int[n];
        for(int i = 0; i < n; i++){
            arr[i] = Integer.parseInt(st.nextToken());
        }
        return arr;
    }

    static class Pair<A, B>{
        A first;
        B second;
        public Pair(A first, B second){
            this.first = first;
            this.second = second;
        }
    }
}


Measured memory_bytes: 32556
#include <bits/stdc++.h>
#define REP(i,n) for(LL i=0;i<(LL)(n);i++)
#define ALL(x) (x).begin(),(x).end()
#define LL long long
#define pii pair<LL,LL>
#define pll pair<LL,LL>

using namespace std;

int main(){

    LL N,D;cin>>N>>D;
    LL d[N];
    REP(i,N)cin>>d[i];
    LL pos[N+1];
    pos[0]=D;
    REP(i,N)pos[i+1]=min(pos[i], abs(pos[i]-d[i]));
    LL grandy[N+1];
    grandy[N]=0;
    REP(i,N)grandy[N-1-i]=(2*grandy[N-i]+1 >= d[N-1-i] ? grandy[N-i]+d[N-1-i]:grandy[N-i]);

    LL Q;cin>>Q;
    while(Q--){
        LL q;cin>>q;
        cout<<(pos[q-1]<=grandy[q] ? "NO":"YES")<<endl;
    }


    return 0;
}

Measured memory_bytes: 13696
#line 1 "agc043_a.cpp"
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define ALL(v) (v).begin(), (v).end()
#define coutd(n) cout << fixed << setprecision(n)
#define ll long long int
#define vl vector<ll>
#define vi vector<int>
const int INF = 2147483647;
const ll MOD = 1000000007;

using namespace std;

int main() {
  int h, w;
  cin >> h >> w;
  string grid[h];
  REP(i, h) { cin >> grid[i]; }

  vector<vi> dp(h, vi(w, 500));
  if (grid[h - 1][w - 1] == '#')
    dp[h - 1][w - 1] = 1;
  else
    dp[h - 1][w - 1] = 0;

  for (int i = h - 1; i >= 0; i--) {
    for (int j = w - 1; j >= 0; j--) {
      if (j + 1 <= w - 1) {
        if (grid[i][j] == '#' && grid[i][j + 1] == '.') {
          dp[i][j] = dp[i][j + 1] + 1;
        } else {
          dp[i][j] = dp[i][j + 1];
        }
      }
      if (i + 1 <= h - 1) {
        if (grid[i][j] == '#' && grid[i + 1][j] == '.') {
          dp[i][j] = min(dp[i][j], dp[i + 1][j] + 1);
        } else {
          dp[i][j] = min(dp[i][j], dp[i + 1][j]);
        }
      }
    }
  }

  cout << dp[0][0] << endl;
}


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

int main(){
  string s;
  cin>>s;
  int i,n=s.size();
  for(int bit=0;bit<(1<<n-1);bit++){
    string t;
    for(i=0;i<n;i++){
      t+=s[i];
      if(i==n-1){
        break;
      }
      if(bit&1<<i){
        t+='-';
      }else{
        t+='+';
      }
    }
    int sum=0,k=t.size();
    sum+=(t[0]-'0');
    for(i=2;i<k;i+=2){
      if(t[i-1]=='+'){
        sum+=(t[i]-'0');
      }else{
        sum-=(t[i]-'0');
      }
    }
    if(sum==7){
      cout<<t<<"=7"<<endl;
      return 0;
    }
  }
}

Measured memory_bytes: 256
//#pragma GCC optimize ("O3")
//#pragma GCC target ("avx2")
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define Would
#define you
#define please

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

	string S;
	cin >> S;

	if (S == "ABC") co("ARC");
	else co("ABC");


	Would you please return 0;
}

Measured memory_bytes: 3636
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <queue>
#include <map>
#include <utility>
#include <functional>

using namespace std;

#define LEN 1000000

char str[LEN];
int cnt[LEN];

int main() {
	char ch;
	int s = -1, ans = 0;

	while (cin >> ch) {
		if (str[s] != ch) {
			s++;
		}
		str[s] = ch;
		cnt[s]++;
	}

	for (int i = 0; i + 2 <= s; ++i) {
		if (str[i] == 'J' && str[i + 1] == 'O' && str[i + 2] == 'I') {
			if (cnt[i + 1] <= cnt[i] && cnt[i + 1] <= cnt[i + 2]) {
				ans = max(ans, cnt[i + 1]);
			}
		}
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 7964
#include<stdio.h>
#define MAX 10000
#define NIL -1

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

struct Node T[MAX];
int n;

void preParse(u);
void inParse(u);
void postParse(u);



int main(){
  
  int i;
  int v, l;
  int r;
  int root;

  
  scanf("%d", &n);

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

    T[i].p = NIL;

  }

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

    
    scanf("%d %d %d", &v, &l, &r);

    T[v].l = l;
    T[v].r = r;

    if ( l != NIL ) {
      T[l].p = v;
    }
    if ( r != NIL ) {
      T[r].p = v;
    }

    
  }

  for ( i = 0; i < n; i++ ){
    if ( T[i].p == NIL ) {
      root = i;
    }
  }

  printf("Preorder\n");
  preParse(root);
  printf("\n");
  
  printf("Inorder\n");
  inParse(root);
  printf("\n");
  
  printf("Postorder\n");
  postParse(root);
  printf("\n");

  return 0;
  
}

void preParse(int u){
  
  if ( u == NIL ) return;

  printf(" %d", u);
  preParse(T[u].l);
  preParse(T[u].r);

}
void inParse(int u){

  if ( u == NIL ) return;

  inParse(T[u].l);
  printf(" %d", u);
  inParse(T[u].r);

}
void postParse(int u){

  if ( u == NIL ) return;

  postParse(T[u].l);
  postParse(T[u].r);
  printf(" %d", u);

}

Measured memory_bytes: 620
// clang-format off
#include <bits/stdc++.h>
#define int long long
#define main signed main()
// #define main int main()
#define loop(i, a, n) for (int i = (a); i < (n); i++)
#define rep(i, n) loop(i, 0, n)
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define prec(n) fixed << setprecision(n)
#define stlice(from, to) substr(from, (to) - (from) + 1)
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
using namespace std;
using pii = pair<int, int>;
using vi = vector<int>;
using vd = vector<double>;
using vc = vector<char>;
using vb = vector<bool>;
using vs = vector<string>;
using vpii = vector<pii>;
using vvi = vector<vi>;
using vvb = vector<vb>;
using vvpii = vector<vpii>;
template<typename A> using fn = function<A>;
constexpr int INF = sizeof(int) == sizeof(long long) ? 1000000000000000000LL : 1000000000;
constexpr int MOD = 1000000007;
constexpr double PI = acos(-1);
template<typename A, typename B> bool cmin(A &a, const B &b) { return a > b ? (a = b, true) : false; }
template<typename A, typename B> bool cmax(A &a, const B &b) { return a < b ? (a = b, true) : false; }
constexpr bool odd(const int &n) { return n & 1; }
constexpr bool even(const int &n) { return !odd(n); }
void solve();
main { solve(); return 0; }
// clang-format on

template<typename T>
struct Monoid {
  T id;
  fn<T(T, T)> op;
  Monoid(T e, fn<T(T, T)> f)
    : id(e), op(f) {
  }
};

template<typename T>
class SegT {
private:
  vector<T> data;
  Monoid<T> monoid;
  int size = 1;

public:
  SegT(const int &n, const Monoid<T> &m = Monoid<T>(INF, [](int a, int b) { return min(a, b); }))
    : monoid(m) {
    while (size < n) size *= 2;
    data = vector<T>(2 * size, monoid.id);
  }

  void update(int i, const T &x) {
    i += size;
    data[i]                = x;
    while (i /= 2) data[i] = monoid.op(data[i * 2], data[i * 2 + 1]);
  }

  T fold(const int &a, const int &b, const int &k = 1, const int &l = 0, int r = -1) {
    if (r == -1) r = size;
    if (r <= a || b <= l) return monoid.id;
    if (a <= l && r <= b) return data[k];
    return monoid.op(fold(a, b, k * 2, l, (l + r) / 2),
                     fold(a, b, k * 2 + 1, (l + r) / 2, r));
  }

  const T &operator[](const int &i) const {
    return data[i + size];
  }
};

void solve() {
  int n, q;
  cin >> n >> q;
  SegT<int> t(n, Monoid<int>(0, plus<int>()));
  while (q--) {
    int com, x, y;
    cin >> com >> x >> y;
    x--;
    if (com) {
      cout << t.fold(x, y) << endl;
    } else {
      t.update(x, t[x] + y);
    }
  }
}

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

#define for_(i,a,b) for(int i=a;i<b;++i)

struct Edge {
	int v, c, h, r;
	Edge(int v_, int c_, int h_, int r_ = 0) : v(v_), c(c_), h(h_), r(r_) {}
	bool operator > (const Edge& e) const { return c > e.c; }
};

void update(int& a, int b) { a = min(a, b); }

int N, M, H, K, s, t, P, d[1 << 8], pas[1 << 8];
vector< vector< Edge > > edges;

int dp[2][1 << 8], cost[110][25];

int djk(int S) {
	for_(i,0,N) for_(j,0,25) cost[i][j] = 1e9;
	
	priority_queue< Edge, vector< Edge >, greater< Edge > > q;
	q.push(Edge(s, 0, 0));
	cost[s][0] = 0;
	
	while (!q.empty()) {
		Edge e = q.top(); q.pop();
		
		if (cost[e.v][e.h] < e.c) continue;
		
		for_(i,0,(int)edges[e.v].size()) {
			Edge ei = edges[e.v][i];
			int c = (S >> ei.r & 1) ? 0 : ei.c;
			
			if (e.h + ei.h <= H && cost[ei.v][e.h + ei.h] > e.c + c) {
				cost[ei.v][e.h + ei.h] = e.c + c;
				q.push(Edge(ei.v, e.c + c, e.h + ei.h));
			}
		}
	}
	
	int res = 1e9;
	for_(i,0,H+1) update(res, cost[t][i]);
	return res;
}

void solve() {
	for_(S,0,(1<<K)+1) dp[0][S] = 1e9;
	dp[0][0] = 0;
	
	for_(i,0,P) {
		for_(S,0,(1<<K)) dp[1][S] = 1e9;
		
		for_(S,0,(1<<K)) {
			if (dp[0][S] == 1e9) continue;
			update(dp[1][S], dp[0][S]);
			update(dp[1][S | pas[i]], dp[0][S] + d[i]);
		}
		
		swap(dp[0], dp[1]);
	}
	
	int ans = 1e9;
	for_(S,0,(1<<K)) {
		if (dp[0][S] == 1e9) continue;
		update(ans, djk(S) + dp[0][S]);
	}
	
	cout << (ans < 1e9 ? ans : -1) << endl;
}

int main() {
	while (cin >> N >> M >> H >> K, N) {
		edges.assign(N, vector< Edge >());
		
		for_(i,0,M) {
			int a, b, c, h, r;
			scanf("%d %d %d %d %d", &a, &b, &c, &h, &r);
			--a; --b; --r;
			edges[a].push_back(Edge(b, c, h, r));
			edges[b].push_back(Edge(a, c, h, r));
		}
		
		cin >> s >> t >> P;
		--s; --t;
		
		for_(i,0,P) {
			int l; cin >> l >> d[i];
			
			pas[i] = 0;
			for_(j,0,l) {
				int k; cin >> k; --k;
				pas[i] |= 1 << k;
			}
		}
		
		solve();
	}
	
	return 0;
}

Measured memory_bytes: 1400
#include <cstdio>
#include <vector>
#include <utility>
#include <algorithm>

using namespace std;

vector<int> Heap;

void insert(int node)
{
	Heap.push_back(node);
}

void Max_Heapify(int node)
{
	int l = node * 2;
	int r = node * 2 + 1;

	int largest;

	if (l < Heap.size())
	{
		if (Heap[node] < Heap[l])
		{
			largest = l;
		}
		else
		{
			largest = node;
		}
	}
	else
	{
		largest = node;
	}

	if (r < Heap.size())
	{
		if (Heap[largest] < Heap[r])
		{
			largest = r;
		}
	}

	if (largest != node)
	{
		swap(Heap[largest], Heap[node]);

		Max_Heapify(largest);
	}
}

int main()
{
	int N; scanf("%d", &N); Heap.push_back(0);

	int tmp;

	for (int i = 1; i <= N; i++)
	{
		scanf("%d", &tmp);

		insert(tmp);
	}

	for (int i = N / 2; i >= 1; i--)
	{
		Max_Heapify(i);
	}

	for (int i = 1; i <= N; i++)
	{
		printf(" %d", Heap[i]);
	}

	printf("\n");
	
	return 0;
}

Measured memory_bytes: 4424
import collections

def cmb(n, r):
  #MOD = 10**9+7
  if r > n: return 0
  if n - r < r: r = n - r
  if r == 0: return 1
  if r == 1: return n

  numerator = [n - r + k + 1 for k in range(r)]
  denominator = [k + 1 for k in range(r)]

  for p in range(2,r+1):
    pivot = denominator[p - 1]
    if pivot > 1:
      offset = (n - r) % p
      for k in range(p-1,r,p):
        numerator[k - offset] /= pivot
        denominator[k] /= pivot

  result = 1
  for k in range(r):
    if numerator[k] > 1:
      result *= int(numerator[k])
      #result %= MOD

  return result

n = int(input())
a = list(map(int,input().split()))

count = collections.Counter(a)

l1 = [0 for _ in range(n)]
l2 = [0 for _ in range(n)]

for i,v in count.items():
	if v != 1:
		l1[i-1] = cmb(v,2)
		l2[i-1] = cmb(v-1,2)

sum_l1 = sum(l1)

for i in range(n):
	#print(l2[a[i]-1], sum_l1, l1[a[i]-1])
	print(l2[a[i]-1] + sum_l1 - l1[a[i]-1])


Measured memory_bytes: 26780
#include<bits/stdc++.h>
	#define fastio ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	#define endl "\n"
	#define ll long long
	#define fs first
	#define ss second//typedef second ss;
	using namespace std;

	int main(){
		fastio;
		int r,g,b,k;
      cin>>r>>g>>b>>k;
      int count = 0;
      while(r>=g) {count++; g*=2;}
      while(g>=b) {count++; b*=2;}
      if(count <= k){cout<<"Yes"<<endl;}
      else{cout<<"No"<<endl;}
                     
		return 0;
	}


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

int main() {
    string s; cin >> s;
    vector<bool> alpha(26, false);
    for (char c: s) {
        alpha[(int)c-(int)'a'] = true;
    }
    
    if (s=="zyxwvutsrqponmlkjihgfedcba") {
        cout << -1 << endl;
        return 0;
    }

    for (int i=0; i<26; i++) {
        if (!alpha[i]) {
            cout << s << (char)((int)'a'+i) << endl;
            return 0;
        }
    }

    for (int i=s.length()-1; i>=0; i--) {
        for (int l=0; l<26; l++) {
            if (!alpha[l] && (int)(s[i]-'a') < l) {
                for (int k=0; k<i; k++) cout << s[k];
                cout << (char)(l+(int)'a') << endl;
                return 0;
            }
        }
        alpha[s[i]-(int)'a'] = false;
    }
}

Measured memory_bytes: 764
using System;
using System.Numerics;
using System.Linq;
using System.Collections.Generic;
using System.Text;

namespace debug
{
    class main 
    {
        static void Main(string[] args)
        {
            ProgramA a = new ProgramA();
            a.main();
            
        }

    }

    class ProgramA
    {
        public void main()
        {
            //入力
            string s = Console.ReadLine();

            if (s == "Sunny")
                Console.WriteLine("Cloudy");
            else if (s == "Cloudy")
                Console.WriteLine("Rainy");
            else
                Console.WriteLine("Sunny");

        }


    }

    
}


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

int main(){
	ll x;
	cin >> x;
	
	ll money = 100;
	ll year = 0;
	while (money < x) {
		money *= 1.01;
		year++;
      //cout << year << endl;
	}
	cout << year << endl;
}


Measured memory_bytes: 3636