akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
typedef vector<long long> vi;
typedef vector<vi> vvi;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef vector<string> vs;
typedef long long int ll;
typedef unsigned long long int ull;
typedef pair<int, int> pii;

inline bool valid(int x, int n) {
    return 0 <= x && x < n;
}

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

template <typename T>
inline T pop(queue<T>& q) {
    T front = q.front();
    q.pop();
    return front;
}

template <typename T>
inline T gcd(T a, T b) {
    for (; b; a %= b, swap(a, b));
    return a; 
}

template <typename T>
tuple<T, T, T> xgcd(T a, T b) {
    if (b == 0) return {1, 0, a};
    T x, y, g;
    tie(x, y, g) = xgcd(b, a%b);
    return {y, x-(a/b)*y, g};
}

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

    string s; cin >> s;
    deque<char> S(s.begin(), s.end());
    bool rev = false;

    int Q; cin >> Q;
    while (Q--) {
        int T; cin >> T;
        if (T == 1) rev = !rev;
        else {
            int F; cin >> F;
            char C; cin >> C;

            if (!rev) {
                if (F == 1) S.push_front(C);
                else S.push_back(C);
            }
            else {
                if (F == 1) S.push_back(C);
                else S.push_front(C);
            }
        }
    }

    string rst(S.begin(), S.end());
    if (rev) reverse(rst.begin(), rst.end());
    cout << rst;
}

Measured memory_bytes: 1232
n=int(input())
l=list(map(int,input().split()))
# print(l)
lst=[]
cnt=0
for i in range(n-2):
    for j in range(i+1,n-1):
        for k in range(j+1,n):
            # lst.append((l[i],l[j],l[k]))
            ln=max ( (l[i] , l[j] , l[k]) )
            if l[i]!=l[j] and l[i]!=l[k] and l[j]!=l[k] and ln<(l[i]+l[j]+l[k]-ln):
                cnt+=1
                # print(i+1,j+1,k+1)
print(cnt)

Measured memory_bytes: 9204
#include <iostream>
#include <limits.h>
#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <list>
#include <map>
#include <numeric>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <queue>
#include <unordered_map>
#include <unordered_set>
#include <cassert>

#define REP(i,n) for(int i=0;i<n;i++)
#define all(x) (x).begin(),(x).end()
#define mp make_pair
#define eb emplace_back

typedef long long ll;
using namespace std;

ll ans = 0;
multiset<int> sr;//right
multiset<int,greater<int>> sl;//left

void add(int a,int b){
    ans += b;
    if(sr.empty()){
        sr.insert(a);
        sl.insert(a);
        return;
    }
    int r = *sr.begin();
    int l = *sl.begin();
    if(r < a){
        ans += a - r;
        sl.insert(r);
        sr.erase(sr.begin());
        sr.insert(a);
        sr.insert(a);
    }
    else if(a < l){
        ans += l - a;
        sr.insert(l);
        sl.erase(sl.begin());
        sl.insert(a);
        sl.insert(a);
    }
    else{
        sr.insert(a);
        sl.insert(a);
    }
}
void answer(){
   cout << *sl.begin() << " " << ans << '\n';
}
int main(void){
    //cin.tie(0);
    //ios::sync_with_stdio(false);
    int query;cin >> query;
    REP(_,query){
        int q;cin >> q;
        if(q == 1){
           int a,b;cin >> a >> b;
           add(a,b);
        }else{
            answer();
        }
    }
    return 0;
}


Measured memory_bytes: 18944
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner cin = new Scanner(System.in);
		while(true){
			int N=cin.nextInt();
			if(N==0){
				break;
			}
			while(N--!=0){
				Qua[] a = new Qua[4];
				Qua[] b = new Qua[4];
				for(int i = 0;i<4;i++){
					int c = cin.nextInt();
					a[i]=new Qua(c,i);
				}
				for(int i = 0;i<4;i++){
					int c = cin.nextInt();
					b[i]=new Qua(c,i);
				}
				Qua[] c = new Qua[16];
				int cnt=0;
				for(int i = 0;i<4;i++){
					for(int j = 0;j<4;j++){
						c[cnt++]=a[i].mult(b[j]);
					}
				}
				for(int i = 0;i<4;i++){
					int ans=0;
					for(int j = 0;j<16;j++){
						if(i==c[j].type){
							ans+=c[j].num;
						}
					}
					if(i==0){
						System.out.print(ans);
					}
					else{
						System.out.print(" "+ans);
					}

				}
				System.out.println();
			}
		}
	}

}
class Qua{
	int num;
	int type;
	Qua(int a,int b){
		num=a;type=b;
	}
	public String toString(){
		return ""+num+" " +type;
	}
	Qua mult(Qua q){
		Qua res=new Qua(this.num,this.type);
		res.num=res.num*q.num;
		if(res.type==0&&q.type==0){
			return res;
		}
		if(res.type==q.type){
			res.type=0;
			res.num*=-1;
			return res;
		}
		if(res.type==0){
			res.type=q.type;
			return res;
		}
		if(q.type==0){
			return res;
		}
		if(res.type==1){
			if(q.type==2){
				res.type=3;
			}
			else if(q.type==3){
				res.type=2;
				res.num*=-1;
			}
			return res;
		}
		if(res.type==2){
			if(q.type==1){
				res.type=3;
				res.num*=-1;
			}
			else if(q.type==3){
				res.type=1;
			}
			return res;
		}
		if(res.type==3){
			if(q.type==1){
				res.type=2;
			}
			else if(q.type==2){
				res.type=1;
				res.num*=-1;
			}
			return res;
		}
		return res;
	}
}

Measured memory_bytes: 12000
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
ll modinv(ll a, ll m) {
	assert(m > 0);
	if (m == 1) return 0;
	a %= m;
	if (a < 0) a += m;
	assert(a != 0);
	if (a == 1) return 1;
	return m - modinv(m, a) * m / a;
}

template <int MOD_> struct modnum {
private:
	int v;
public:
	static const int MOD = MOD_;

	modnum() : v(0) {}
	modnum(ll v_) : v(int(v_ % MOD)) { if (v < 0) v += MOD; }
	explicit operator int () const { return v; }
	friend bool operator == (const modnum& a, const modnum& b) { return a.v == b.v; }
	friend bool operator != (const modnum& a, const modnum& b) { return a.v != b.v; }

	modnum operator ~ () const {
		modnum res;
		res.v = modinv(v, MOD);
		return res;
	}

	modnum& operator += (const modnum& o) {
		v += o.v;
		if (v >= MOD) v -= MOD;
		return *this;
	}
	modnum& operator -= (const modnum& o) {
		v -= o.v;
		if (v < 0) v += MOD;
		return *this;
	}
	modnum& operator *= (const modnum& o) {
		v = int(ll(v) * ll(o.v) % MOD);
		return *this;
	}
	modnum& operator /= (const modnum& o) {
		return *this *= (~o);
	}

	friend modnum operator + (const modnum& a, const modnum& b) { return modnum(a) += b; }
	friend modnum operator - (const modnum& a, const modnum& b) { return modnum(a) -= b; }
	friend modnum operator * (const modnum& a, const modnum& b) { return modnum(a) *= b; }
	friend modnum operator / (const modnum& a, const modnum& b) { return modnum(a) /= b; }
};

template <typename T> T pow(T a, long long b) {
	assert(b >= 0);
	T r = 1; while (b) { if (b & 1) r *= a; b >>= 1; a *= a; } return r;
}

using num = modnum<int(1e9)+7>;

int main(){
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	ll h, w;
	cin >> h >> w;
	ll t;
	cin >> t;
	ll mult = 1;
	mult *= __gcd(t, h);
	mult *= __gcd(t, w);
	h /= __gcd(t, h);
	w /= __gcd(t, w);
	num v = 0;
	v += pow(num(2), w);
	v += pow(num(2), h);
	v += pow(num(2), __gcd(h, w));
	v -= 3;
	v = pow(v, mult);
	cout << (int)v << '\n';
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int n, m;
int main() {
    cin >> n >> m;
    if (n % 2 == 0) {
        for (int i = 0; i < n / 2 + 1; i++) { if (i)cout << ' '; cout << "0"; }
        for (int i = 0; i < n / 2 - 1; i++)cout << ' ' << m;
    }
    else {
        for (int i = 0; i < n / 2 + 1; i++) { if (i)cout << ' '; cout << "0"; }
        for (int i = 0; i < n / 2; i++)cout << ' ' << m;
    }
    cout << endl;
    return 0;
}

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

using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;

template <typename T>
struct segment_tree{
    const T INF = numeric_limits<T>::max();
    int num_of_leafs;
    vector<T> tree;
    int P2(int t){
        int s = 1;
        while(t > s) s <<= 1;
        return s;
    }
    segment_tree(vector<T> &v) : num_of_leafs(P2(v.size())), tree(num_of_leafs*2-1, INF){        
        for(int i=0;i<v.size();i++) tree[i + num_of_leafs - 1] = v[i];
        update_all();
    }
    void update_all(){ //複数変更をまとめて反映させたい場合に使う
        for(int p=num_of_leafs-2;p>=0;p--) tree[p] = min(tree[p*2+1], tree[p*2+2]);
    }
    void update(int i, T x) {
        i += num_of_leafs - 1;
        tree[i] = x;
        while(i > 0){
            i = (i-1)/2;
            tree[i] = min(tree[i*2+1], tree[i*2+2]);
        }
    }
    T query(int a, int b){return query_sub(a, b, 0, 0, num_of_leafs);}
    T query_sub(int a, int b, int k, int l, int r) {
        if (r <= a || b <= l) {
            return INF;
        } else if (a <= l && r <= b) {
            return tree[k];
        } else {
            T vl = query_sub(a, b, k*2+1, l, (l+r)/2);
            T vr = query_sub(a, b, k*2+2, (l+r)/2, r);
            return min(vl, vr);
        }
    }
};

ll N;
vector<P> v;

int main(){
    cin >> N;
    for(int i=0;i<N;i++){
        ll a,b;
        cin >> a >> b;
        v.push_back({a-b,a+b});
    }
    sort(v.begin(),v.end());
    vector<ll> w;
    for(auto &e : v){
        w.push_back(e.second);
    }
    segment_tree<ll> st(w);
    ll ans = 0;
    ll x = -1e18;
    while(true){
        ll idx = lower_bound(v.begin(),v.end(),make_pair(x,(ll)-1e18)) - v.begin();
        if(idx >= N) break;
        ans++;
        x = st.query(idx,N);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 8676
#include <iostream>

using std::cin;
using std::cout;
using std::endl;

#define ForIndex(N) for (size_t index = 0; index < (N); index++)

// ポインタの参照渡し
// -> 呼び出し元のポインタアドレスを書き換える
template<typename T>
void input1DArray(T*& outArray, size_t size)
{
    outArray = new T[size];

    for (size_t index = 0; index < size; index++)
    {
        cin >> outArray[index];
    }
}

template<typename T>
void delete1DArray(T*& array)
{
    delete [] array;
}

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

    char* s;
    input1DArray(s, N);

    bool isFourType = false;
    ForIndex(N)
    {
        if (s[index] == 'Y') isFourType = true;
    }

    cout << ((isFourType) ? "Four" : "Three") << endl;

    delete1DArray(s);
    return 0;
}


Measured memory_bytes: 256
import sys

sys.setrecursionlimit(10 ** 6)
int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep="\n")
def IS(): return sys.stdin.readline()[:-1]
def II(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def LI(): return list(map(int, sys.stdin.readline().split()))
def LI1(): return list(map(int1, sys.stdin.readline().split()))
def LII(rows_number): return [II() for _ in range(rows_number)]
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def LLI1(rows_number): return [LI1() for _ in range(rows_number)]

def main():
	N = II()
	L = LI();L.sort();
	#a<=b<=c

	def BS(a,c,i,j):
		s,t = i,j
		while s+1 < t:
			mid = (s+t)//2
			if (a+L[mid]>c):
				t = mid
			else:
				s = mid
		return j-t


	ans = 0

	for i in range(N-1):
		for j in range(i+2,N):
			a = L[i]
			c = L[j]
			ans += BS(a,c,i,j)

	print(ans)

main()

Measured memory_bytes: 42972
//* AuThOr GaRyMr *//
#include<bits/stdc++.h>
#define rb(a,b,c) for(int a=b;a<=c;++a)
#define rl(a,b,c) for(int a=b;a>=c;--a)
#define niv vector<int>
#define LL long long
#define IT iterator
#define PB push_back
#define II(a,b) make_pair(a,b)
#define FIR first
#define SEC second
#define FREO freopen("check.out","w",stdout)
#define rep(a,b) for(int a=0;a<b;++a)
#define KEEP while(1)
#define SRAND mt19937 rng(chrono::steady_clock::now().time_since_epoch().count())
#define random(a) rng()%a
#define ALL(a) a.begin(),a.end()
#define ff fflush(stdout)
using namespace std;
const int INF=0x3f3f3f3f;
typedef pair<int,int> mp;
typedef pair<mp,mp> superpair;
vector<int> each[200+10];
int res=-1;int n;
void bfs(int x){
	int v[201]={0};
	v[x]=1;
	queue<int> q;
	q.push(x);
	while(!q.empty()){
		int now=q.front();
		q.pop();
		for(auto it:each[now]){
			if(!v[it]){
				q.push(it);
				v[it]=v[now]+1;
			}
			else{
				if(v[it]!=v[now]+1&&v[it]!=v[now]-1) return ;
			}
		}
	}
	rb(i,1,n){
		res=max(res,v[i]);	
	}
}
int main(){
	
	cin>>n;
	rb(i,1,n){
		rb(j,1,n){
			char c;
			cin>>c;
			if(c=='1') each[i].PB(j);
		}
	} 
	rb(root,1,n){
		bfs(root);
	}
	cout<<res<<endl;
	return 0;
}


Measured memory_bytes: 512
x,n=map(int, input().split())
P=list(map(int, input().split()))

ans = 200
abs_ans = 200
for i in range(102):
    if i in P:
        continue
    if abs(x-i) < abs_ans:
        ans = i
        abs_ans = abs(x-i)
print(ans)

Measured memory_bytes: 9120
"use strict";
const Main = (input) =>{
   let xs = input.trim().split(' ');
   let ans = parseInt(xs[0].charCodeAt());
   if(ans>=65&&ans<=90){
     console.log('A');
   }else{
     console.log('a');
   }

}
Main(require('fs').readFileSync('/dev/stdin','utf8'));

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

int main() {
  int A,B;
  cin >> A>>B;
  int X,Y;
  X=A+B;
  if (X%2==0) {
    Y=X/2;
    cout << Y << '\n';
  }else{
    cout << "IMPOSSIBLE" << '\n';
  }
}

Measured memory_bytes: 256
import java.util.Scanner;
public class Main {
	public static void main(String[] args) throws java.io.IOException {
		Scanner scan = new Scanner(System.in);
		int t[] = new int[4];
		int m[] = new int[4];
		for(int i = 0; i<4 ; i++){
			t[i] = scan.nextInt();
			m[i] = scan.nextInt();
		}
		for(int i = 0; i<4 ; i++){
			if(t[i] == 1){
				System.out.println(6000*m[i]);
			}else if(t[i] == 2){
				System.out.println(4000*m[i]);
			}else if(t[i] == 3){
				System.out.println(3000*m[i]);
			}else{
				System.out.println(2000*m[i]);
			}
		}
	}
}

Measured memory_bytes: 17328
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,n) for(ll i=0;i<(n);i++)
#define rrep(i,n) for(ll i = 1; i <= (n); ++i)
#define drep(i,n) for(ll i = (n)-1; i >= 0; --i)
#define all(v) v.begin(),v.end()
#define len(x) (ll)(x).length()
#define maxs(x,y) x = max(x,y)
#define mins(x,y) x = min(x,y)
#define pb push_back
#define sz(x) (ll)(x).size()
#define v(T) vector<T>
#define vv(T) vector<vector<T>>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
ll gcd(ll a,ll b){if(a%b==0){return b;}else{return(gcd(b,a%b));}}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}
const int INF=1e9;
const ll MX = 1e18;
const ll MOD=INF+7;
const int di[] = {-1,0,1,0};
const int dj[] = {0,-1,0,1};
const double PI=acos(-1);
#define dame { puts("-1"); return 0;}
#define yn {puts("Yes");}else{puts("No");}
#define YN {puts("YES");}else{puts("NO");}
const ll MAX = 1000001;
long long fac[MAX], finv[MAX], inv[MAX];
void COMinit() {fac[0] = fac[1] = 1;finv[0] = finv[1] = 1;inv[1] = 1;for (ll i = 2; i < MAX; i++){fac[i] = fac[i - 1] * i % MOD;inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;finv[i] = finv[i - 1] * inv[i] % MOD;}}
long long COM(ll n, ll k){if (n < k) return 0;if (n < 0 || k < 0) return 0;return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;}

int powex(int n,int i){
  int cnt=n;
  for(int j=0;j<i-1;j++){
    n*=cnt;
  }
  return n;
}

int main() {
  int n;
  cin>>n;
  vi dp(n+1);
  rrep(i,n){
    dp[i]=dp[i-1]+1;
    for(int j=1;i>=powex(6,j);j++){
      mins(dp[i],dp[i-powex(6,j)]+1);
    }
    for(int j=1;i>=powex(9,j);j++){
      mins(dp[i],dp[i-powex(9,j)]+1);
    }
  }
  cout<<dp[n]<<endl;
}    


Measured memory_bytes: 3704
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <numeric>
#include <functional>
#include <cmath>
#include <queue>
#include <stack>
#include <bitset>
#include <map>
#include <string>
#include <utility>

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

using namespace std;

int inputValue(){
	int a;
	cin >> a;
	return a;
}

void inputArray(int *p,int a){
	rep(i,a){
		cin >> p[i];
	}
}

void inputVector(vector<int> *p,int a){
	rep(i,a){
		int input;
		cin >> input;
		p -> push_back(input);
	}
}

template <typename T>
void output(T a,int precision){
	if(precision > 0){
		cout << setprecision(precision) << a << "\n";
	}else{
		cout << a << "\n";
	}
}

int main(){
	//source
	int a[5];
	int b[5];
	int c[5];
	int sum=0;
	rep(i,5){
		cin>>a[i];
		if(a[i]%10==0){
			b[i]=(a[i]/10)*10;
		}else{
			b[i]=(a[i]/10)*10+10;
		}
		sum+=b[i];
	}
	rep(i,5){
		c[i]=sum-b[i]+a[i];
	}
	int ans=pow(10,9);
	rep(i,5){
		ans=min(ans,c[i]);
	}
	cout << ans << endl;
	return 0;
}


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

int main(){
	int a,b,c;
	cin >> a >>  b >> c ;
	if (a==c){
		cout << b;
	}
	if (b==c){
		cout << a;
	}
	if (a==b){
		cout << c;
	}
}

Measured memory_bytes: 256
/* AtCoder Beginner Contest abc128
 * Problem D
 * Au: SJoshua
 */
#include <cstdio>
#include <vector>
#include <string>
#include <algorithm>
#include <iostream>
#include <climits>
#include <queue>
#include <functional>

using namespace std;

int f[101][101][101];

int main(void) {
	int n, k;
	cin >> n >> k;
	vector <int> v(n + 1);
	for (int i = 1; i <= n; i++) {
		cin >> v[i];
	}
	int ans = 0;
	int op = min(n, k);
	priority_queue <int, vector<int>, greater<int>> pq;
	int cnt = 0;
	for (int i = 0; i <= op; i++) {
		if (i) {
			pq.push(v[i]);
			cnt += v[i];
		}
		for (int j = 0; i + j <= op; j++) {
			priority_queue <int, vector<int>, greater<int>> tmp = pq;
			int c2 = cnt;
			for (int x = n; x > n - j; x--) {
				tmp.push(v[x]);
				c2 += v[x];
			}
			int allow = k - i - j;
			while (!tmp.empty() && allow--) {
				if (tmp.top() < 0) {
					c2 -= tmp.top();
					tmp.pop();
				} else {
					break;
				}
			}
			ans = max(ans, c2);
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
import sys
sys.setrecursionlimit(10**6)

MOD = 10**9+7


def main(input, print):
    s = int(input())
    dp = [0]*(s+1)
    dp[0] = 1
    for i in range(1, s+1):
        for j in range(i-3+1):
            dp[i] += dp[j]
            dp[i] %= MOD
    print(dp[s])


if __name__ == '__main__':
    main(sys.stdin.readline, print)


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

const int Maxb = 31;

int n;
map <int, int> M;
int res;

int main()
{
    scanf("%d", &n);
    for (int i = 0; i < n; i++) {
        int a; scanf("%d", &a);
        M[a]++;
    }
    for (int i = Maxb - 1; i >= 0; i--)
        for (map <int, int>::iterator it = M.begin(); it != M.end() && 2 * it->first <= (1 << i); it++) {
            if (it->second == 0) continue;
            int nd = (1 << i) - it->first;
            if (nd == it->first) {
                int tk = it->second / 2;
                it->second -= 2 * tk;
                res += tk;
            } else {
                map <int, int>::iterator it2 = M.find(nd);
                if (it2 != M.end()) {
                    int tk = min(it->second, it2->second);
                    it->second -= tk; it2->second -= tk;
                    res += tk;
                }
            }
        }
    printf("%d\n", res);
    return 0;
}


Measured memory_bytes: 9600
#include <ctime>
#include <string>
#include <iostream>
using namespace std;
int N, K, card[500][500];
int main() {
	srand((unsigned)time(NULL));
	scanf("%d%d", &N, &K);
	for (int i = 0; i < K; i++) {
		for (int j = 0; j < N / 2; j++) {
			scanf("%d", &card[i][j]);
		}
	}
	while (true) {
		string s;
		for (int i = 0; i < N; i++) {
			s += rand() % 2 + 48;
		}
		bool flag = true;
		for (int i = 0; i < K; i++) {
			int c = 0;
			for (int j = 0; j < N / 2; j++) {
				if (s[card[i][j] - 1] == '1') c++;
			}
			if (c < N / 8 || 3 * N / 8 < c) { flag = false; break; }
		}
		if (flag) { printf("%s\n", s.c_str()); break; }
	}
	return 0;
}

Measured memory_bytes: 4204
import java.util.*;

public class Main{
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    int[] dp = new int[N+1];
    int[] list = {1, 6, 9, 36, 81, 216, 729, 1296, 6561, 7776, 46656, 59049};
    int len = list.length;
    for(int i = 0; i<N+1; i++){
      if(i == 0) dp[i] = 0;
      else dp[i] = 1000007;
    }
    for(int i=0; i<N+1; i++){
      for(int j=0; j<len; j++){
        if(i+list[j]<N+1) dp[i+list[j]] = Math.min(dp[i]+1, dp[i+list[j]]);
      }
    }
    System.out.println(dp[N]);
  }
}

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

int main() {
	int n, u, v, l;
	cin >> n;
	int A[n + 1][n + 1];
	for (int i = 1; i <= n; i++) {
		for (int j = 1; j <= n; j++) {
			A[i][j] = 0;
		}
	}

	for (int i = 1; i <= n; i++) {
		cin >> u >> l;
		for (int j = 0; j < l; j++) {
			cin >> v;
			A[u][v] = 1;
		}
	}

	for (int i = 1; i <= n; i++) {
		for (int j = 1; j <= n; j++) {
			if (j != 1) cout << ' ';
			cout << A[i][j];
		}
		cout << endl;
	}

	return 0;
}

Measured memory_bytes: 1200
import java.util.Arrays;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner scan = new Scanner(System.in);

		String s = scan.next();
		String t = scan.next();
		String sDash = "";
		String tDash = "";

		char[] sChar = s.toCharArray();
		Arrays.sort(sChar);
		char[] tChar = t.toCharArray();
		Arrays.sort(tChar);

		s = new String(sChar);
		t = new String(tChar);

		StringBuffer sb = new StringBuffer(t);
		t = sb.reverse().toString();

		boolean flag = true;
		for (int i = 0; i < Math.min(s.length(), t.length()); i++) {
			if (s.charAt(i) != t.charAt(i)) flag = false;
			if (s.charAt(i) < t.charAt(i)) {
				System.out.println("Yes");
				System.exit(0);
			}
		}

		if (flag && s.length() < t.length()) System.out.println("Yes");
		else System.out.println("No");
 	}
}

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

int main()
{
  int n,ans,mn;
  ans=1;
  cin>>n;
  vector<int> a(n);
  for(int i=0;i<n;i++)
  {
    cin>>a.at(i);
  }
  mn=a.at(0);
  for(int i=1;i<n;i++)
  {
    if(mn>a.at(i))
      ans++;
    mn=min(mn,a.at(i));
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 4048
n,k=map(int,input().split())
s=list(input())
cnt=0
ans=0
j=0
for i in range(n):
    if s[i]=="0":
        if i==0 or s[i-1]=="1":
            cnt+=1
    if cnt>k:
        while s[j]=="1":
            j+=1
        while s[j]=="0":
            j+=1
        cnt-=1
    ans=max(ans,i-j+1)

print(ans)

Measured memory_bytes: 49776
#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
#include<tuple>
using namespace std;
typedef long long ll;
typedef unsigned int ui;
const ll mod = 1000000007;
const ll INF = (ll)1000000007 * 1000000007;
typedef pair<int, int> P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define Per(i,sta,n) for(int i=n-1;i>=sta;i--)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef long double ld;
const ld eps = 1e-8;
const ld pi = acos(-1.0);
typedef pair<ll, ll> LP;
int dx[4]={1,-1,0,0};
int dy[4]={0,0,1,-1};

int n;
ll a[100];
map<ll,ll> dp[85];

void solve(){
    cin >> n;
    rep(i,n){
        cin >> a[i];
    }
    dp[0][0]=1000;
    rep(i,n){
        for(auto p:dp[i]){
            dp[i+1][0]=max(dp[i+1][0],p.second+a[i]*p.first);
            dp[i+1][p.first]=max(dp[i+1][p.first],p.second);
            dp[i+1][p.first+p.second/a[i]]=max(dp[i+1][p.first+p.second/a[i]],p.second%a[i]);
        }
    }
    cout << dp[n][0] << endl;
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(50);
    solve();
}

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

//from https://misora192.hatenablog.com/entry/2019/01/09/074031
int n,m;
const int max_n=1e5+10;
vector<int> g[max_n];
bool used[max_n];
vector<int> v;

void dfs(int u) {
    if (used[u]) return;
    used[u]=true;
    for (int i: g[u]) dfs(i);
    v.push_back(u);
}

void tsort() {
    for (int i=0;i<n;i++) dfs(i);
    reverse(v.begin(), v.end());
}

int main(){
    int mod=1000000007;
    scanf("%d %d",&n,&m);
    for (int i=0;i<m;i++) {
        int x,y;
        scanf("%d %d",&x,&y);
        x--;
        y--;
        g[x].push_back(y);
    }
    tsort();
    reverse(v.begin(), v.end());
    vector<int> dp(n,0);
    int ans=0;
    for (int i: v) {
        for (int u: g[i]) {
            dp[i]=max(dp[i],dp[u]+1);
        }
        ans=max(ans,dp[i]);
    }
    printf("%d\n",ans);
    return 0;
}

Measured memory_bytes: 8824
import sys
from pprint import pprint

N, K = map(int, sys.stdin.readline().strip().split())
ans = 0
for i in range(K, N + 2):
    sum_min = i * (i - 1) // 2
    sum_max = i * N - i * (i - 1) // 2
    ans += sum_max - sum_min + 1
    # print(ans)
    ans %= 10**9 + 7

print(ans)

Measured memory_bytes: 68680
#include <bits/stdc++.h>
using namespace std;
 
int main(void){
    int n;
    cin>>n;
    int kouho=n/1.08;
    if ((int)(kouho*1.08)==n) cout<<kouho<<endl;
    else if ((int)((kouho+1)*1.08)==n) cout<<kouho+1<<endl;
    else cout<<":("<<endl;
}

Measured memory_bytes: 256
#!/usr/bin/env python
N, M = map(int, input().split())
X = []
for m in range(M):
    p, y = map(int, input().split())
    X.append([m, p, y])

X_sort = sorted(X, key=lambda x:(x[1], x[2]))

c = 1
X_sort[0].append(str(X_sort[0][1]).zfill(6) + str(1).zfill(6))
for i,x in enumerate(X_sort[1:]):
    if x[1] == X_sort[i][1]:
        c += 1
        x.append(str(x[1]).zfill(6) + str(c).zfill(6))
    else:
        x.append(str(x[1]).zfill(6) + str(1).zfill(6))
        c = 1

Y = sorted(X_sort, key=lambda x:x[0])
for y in Y:
    print(y[3])

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

#define all(v) (v).begin(), (v).end()
#define sortv(v) sort(all(v))
#define uniqv(v) (v).erase(unique(all(v)), (v).end())
#define pb push_back
#define FI first
#define SE second
#define lb lower_bound
#define ub upper_bound
#define mp make_pair
#define test 1
#define TEST if(test)

using namespace std;

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

const int MOD = 1000000007; // 998244353
const int INF = 2e9;
const ll INFLL = 1e18;
const int MAX_N = 1;

int N;

int main(){
	cin>>N;
	cout<<N*N*N;
	return 0;
}


Measured memory_bytes: 256
//#define TIMER_
#include <bits/stdc++.h>
using namespace std;
#define rep(i,r) for(int i = 0; i < (r); i++)
#define pb push_back
#define ALL(a) a.begin(), a.end()
#define fastio ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)
using ll = long long;
using ull = unsigned long long;

int main() {
  fastio;
  int N; cin >> N;
  unordered_map<ll, ll> mp;
  ll res = 0;
  for (int i = 1; i <= N; i++) {
    ll h;
    cin >> h;
    res += mp[i - h];
    mp[h + i]++;
  }
  cout << res << endl;
  
  
  #ifdef TIMER_
    cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
  #endif
}


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

using namespace std;

#define sz(v)           ((int)((v).size()))
#define clr(v, d)       memset(v, d, sizeof(v))
#define rep(i, v)       for(int i=0; i<sz(v); ++i)
#define lp(i, n)        for(int i=0; i<(int)(n); ++i)
#define lpi(i, j, n)    for(int i=(j); i<(int)(n); ++i)
#define lpd(i, j, n)    for(int i=(j); i>=(int)(n); --i)
#define INF             1000000000

typedef long long ll;
typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef vector<int> vi;

const int N = 1e5+5;

void init()
{
	std::ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
}

double arr[10][2];
double dis[10][10];
void saveDist(int idx1, int idx2){
	dis[idx1][idx2] = dis[idx2][idx1] = sqrt((arr[idx1][1] - arr[idx2][1]) * (arr[idx1][1] - arr[idx2][1]) + (arr[idx1][0] - arr[idx2][0]) * (arr[idx1][0] - arr[idx2][0]));
}
int main()
{
	init();
	int n;
	cin >> n;
	lp(i, n){
		cin >> arr[i][0] >> arr[i][1];
		lp(j, i){
			saveDist(j, i);
		}
	}
	double res = 0;
	lp(i, n){
		lp(j, n){
			res += dis[i][j];
		}
	}
	cout << setprecision(9) << res/(n);
	return 0;
}


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

int n, m, a, b, ans;
int mem[64][64], use[64][64];

int bfs(int pos, int vis[8]){
    int c = 0;
    for(int i = 0; i < n; i++){
        if(vis[i] == 1) ++c;
    }
    if(c == n){
        ++ans;
        return 0;
    }
    for(int i = 1; i < n; i++){
        if(mem[pos][i] == 1 && vis[i] != 1){
            vis[i] = 1;
            bfs(i, vis);
            vis[i] = 0;
        }
    }
}

int main(){
    cin  >> n >> m;
    for(int i = 0; i < m; i++){
        cin >> a >> b;
        mem[a-1][b-1] = mem[b-1][a-1] = 1;
    }
    int visited[8] = {};
    visited[0] = 1;
    bfs(0,visited);
    
    cout << ans << endl;
}

Measured memory_bytes: 256
import java.util.Scanner;
public class Main {
  int count = 1;
  public static void main(String[] args) {
    new Main().run();
  }
  public void run() {
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    int K = sc.nextInt();
    for(int i = 0; i < N; i++){
      if(count < K) {
        count *= 2;
      }else {
        count += K;
      }
    }
    System.out.println(count);
    sc.close();
  }
}


Measured memory_bytes: 21972
#include <stdio.h>

#include <math.h>

  /* 配列の要素を交換する */
void Swap(long int x[ ], long int i, long int j)
{
    int temp;

    temp = x[i];
    x[i] = x[j];
    x[j] = temp;
}


void QSort(long int x[ ], long int left, long int right)
{
    long int i, j;
    long int pivot;

    i = left;                      /* ソートする配列の一番小さい要素の添字 */
    j = right;                     /* ソートする配列の一番大きい要素の添字 */

    pivot = x[(left + right) / 2]; /* 基準値を配列の中央付近にとる */

    while (1) {                    /* 無限ループ */

        while (x[i] < pivot)       /* pivot より大きい値が */
            i++;                   /* 出るまで i を増加させる */

        while (pivot < x[j])       /* pivot より小さい値が */
            j--;                   /*  出るまで j を減少させる */
        if (i >= j)                /* i >= j なら */
            break;                 /* 無限ループから抜ける */

        Swap(x, i, j);             /* x[i] と x[j]を交換 */
        i++;                       /* 次のデータ */
        j--;
    }

    if (left < i - 1)              /* 基準値の左に 2 以上要素があれば */
        QSort(x, left, i - 1);     /* 左の配列を Q ソートする */
    if (j + 1 <  right)            /* 基準値の右に 2 以上要素があれば */
        QSort(x, j + 1, right);    /* 右の配列を Q ソートする */
}


int main(void)
{
  long int n, m, i, j;
  long long int ans = 0;
  long int x[100002];
  long int a[100002];
  
  scanf("%ld %ld", &n, &m);
  
  for (i = 0; i < m; i++){
    scanf("%ld", &x[i]);
  }
  QSort(x, 0, m-1);
  
  for (i = 0; i < (m-1); i++){
    a[i] = abs(x[i] -x[i+1]);
    ans += abs(x[i] -x[i+1]);
  }
  QSort(a, 0, m-2);
  
  j = m -2;
  for (i = 0; i < (n - 1); i++){
    ans -= a[j];
    j--;
  }
  
  if (n >= m){
    printf("0");
  } else {
    printf("%lld", ans);
  }
  
  return 0;
}

Measured memory_bytes: 1664
/*
Author : N_o_o_B
Created : April 22 2020 21:34:41 
*/
#include <bits/stdc++.h>
using namespace std;
/*
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
*/
#define TRACE
#ifdef TRACE
#define trace(...) { cerr<<"[ "; __trace__(#__VA_ARGS__, __VA_ARGS__);}
#undef endl
template <typename Arg1,typename Arg2>
ostream& operator << (ostream& out, const pair<Arg1,Arg2> &x) {
    return out<<"("<<x.first<<","<<x.second<<")";
}
 
template <typename Arg1>
ostream& operator << (ostream& out, const vector<Arg1> &a) {
    out<<"[";for(const auto &x:a)out<<x<<",";return out<<"]";
}
 
template <typename Arg1>
ostream& operator << (ostream& out, const set<Arg1> &a) {
    out<<"[";for(const auto &x:a)out<<x<<",";return out<<"]";
}
 
template <typename Arg1,typename Arg2>
ostream& operator << (ostream& out, const map<Arg1,Arg2> &a) {
    out<<"[";for(const auto &x:a)out<<x<<",";return out<<"]";
}
 
template <typename Arg1>
void __trace__(const string name, Arg1&& arg1){
    cerr << name << " : " << arg1 << " ] " << endl;
}
 
template <typename Arg1, typename... Args>
void __trace__(const string names, Arg1&& arg1, Args&&... args){
    const string name = names.substr(0,names.find(','));
    cerr<<name<<" : "<<arg1<<" | ";
    __trace__(names.substr(1+(int)name.size()), args...);
}
#else
    #define trace(args...)
#endif
 
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<pair<int,int>> vii;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<pair<ll,ll>> vll;
typedef vector<vl> vvl;
//typedef tree<pii, null_type, less<pii>, rb_tree_tag, tree_order_statistics_node_update> oset;
#define fori(i,n) for(int i=0;i<n;i++)
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define repd(i,a,b) for(int i=a;i>=b;i--)
#define ford(i,n)  for(int i=n-1;i>=0;i--)
#define trav(x,a) for(auto& x:a)
#define all(x) x.begin(),x.end()
#define pb push_back
#define endl '\n'
#define sz(a) (int)a.size()
#define fi first
#define se second
clock_t time_p=clock();
void time_taken()
{
    time_p=clock()-time_p;
    cerr<<"Time Taken : "<<(float)(time_p)/CLOCKS_PER_SEC<<"\n";
}
//const ll mod=998244353;
const ll mod=1e9+7;
const ll INF=1e18;

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);cout.tie(NULL);
    cout.precision(12);cout << fixed;

    int a,b;
    cin >>a  >> b;
    string s;
    cin >> s;
    bool ok =1;
    fori(i,sz(s)){
        ok &= ((i==a and s[i]=='-') or (i!=a and s[i]>='0' and s[i]<='9'));
    }   

    cout << (ok ? "Yes":"No") << endl;

    time_taken();
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
int main()
{
	ios_base :: sync_with_stdio(0);
	cin.tie(0);
	int n, d, x;
	cin >> n ;
	cin >> d >> x;
	/*vector<int> a;
	int i, count = x;
	for(i=0; i<n; i++){
		int p;
		cin>>p;
		a.push_back(p);
	}*/
	int i, p, count = x;
	for(i=0; i<n; i++){
		cin >> p;
		count++;
		for(int j=1; ; j++){
			if((j*p)+1<=d) count++;
			else break;
		}
	}
	cout << count << endl;
	return 0;
}


Measured memory_bytes: 3612
#include<iostream>
#include<string>
#include<math.h>
#include<algorithm>
#define rep(i,n)for(int i=0;i<n;i++)
using namespace std;

int main(){
	int a;
	cin >> a;
	if (a == 1){
		cout << "Hello World" << endl;
	}
	else if (a == 2){
		int a, b;
		cin >> a >> b;
		cout << a + b << endl;
	}
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define int long long
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define F first
#define S second

using namespace std;
typedef pair<int,int> P;
typedef vector<int> ivec;

const int MOD=1000000007;
int INF=100100100100100;

vector<pair<char,int>> RL_S(string s){
  vector<pair<char,int>> res;
  int n=s.length();
  char ima;int cnt=0;
  rep(i,n){
    if(cnt==0){
      ima=s[i];
      cnt++;
    }
    else if(s[i]==ima)cnt++;
    else{
      res.pb(make_pair(ima,cnt));
      ima=s[i];
      cnt=1;
    }
  }
  res.pb(make_pair(ima,cnt));
  return res;
}

ivec res;
signed main(){
  int n,k;cin>>n>>k;
  string s;cin>>s;
  vector<pair<char,int>> po=RL_S(s);
  if(po[0].F=='0')res.pb((int)0);
  for(auto p:po)res.pb(p.S);
  if((*po.rbegin()).F=='0')res.pb(0);
  
  int len=res.size();
  if(k>=len/2){
    cout<<n<<endl;
    return 0;
  }
  
  int sum=0;
  int ans=0;
  rep(i,2*k+1)sum+=res[i];
  ans=sum;
  for(int i=2;i+2*k<len;i+=2){
    sum+=(res[i+2*k]+res[i+2*k-1]-res[i-1]-res[i-2]);
    ans=max(ans,sum);
  }
  cout<<ans<<endl;
  return 0;
}


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

int w, h;
int s[32][32];
int cost[4];

// dir
// 0 : right
// 1 : up
// 2 : left
// 3 : down
const int dr[4] = {0, -1, 0, 1};
const int dc[4] = {1, 0, -1, 0};
const int dd[4] = {0, 3, 2, 1};

typedef std::pair<int, int> Pii;

class Node {
public:
  Node() {}
  Node(int r_, int c_, int dir_) : r(r_), c(c_), dir(dir_) {}
  int r, c, dir;
};

class Data {
public:
  Data() {}
  Data(Node s_, Node t_, int cost_) : s(s_), t(t_), cost(cost_) {}
  Node s, t;
  int cost;
};

inline bool operator < (const Data& a, const Data& b) {
  return a.cost > b.cost;
}

int dist[32][32][8];
int dijkstra() {
  std::priority_queue<Data> q;
  int r = 0;
  int c = 0;
  int dir = 0;
  dist[r][c][dir] = 0;
  for(int k = 0; k < 4; ++k) {
    int nd = (dir + dd[k]) % 4;
    int nr = r + dr[nd];
    int nc = c + dc[nd];
    if( not ( 0 <= nr and nr < h and 0 <= nc and nc < w ) ) continue;
    q.push(Data(Node(r, c, dir), Node(nr, nc, nd), dist[r][c][dir] + (k == s[r][c] ? 0 : cost[k])));
  }
  while( not q.empty() ) {
    Data t = q.top(); q.pop();
    int r = t.t.r, c = t.t.c, dir = t.t.dir;
    if( dist[r][c][dir] <= t.cost ) continue;
    dist[r][c][dir] = t.cost;
    if( r == h - 1 and c == w - 1 ) continue;
    for(int k = 0; k < 4; ++k) {
      int nd = (dir + dd[k]) % 4;
      int nr = r + dr[nd];
      int nc = c + dc[nd];
      if( not ( 0 <= nr and nr < h and 0 <= nc and nc < w ) ) continue;
      q.push(Data(Node(r, c, dir), Node(nr, nc, nd), dist[r][c][dir] + (k == s[r][c] ? 0 : cost[k])));
    }
  }
  int res = (1 << 30);
  for(int i = 0; i < 4; ++i) {
    res = std::min(res, dist[h-1][w-1][i]);
  }
  return res;
}

void Init() {
  for(int i = 0; i < 32; ++i) {
    for(int j = 0; j < 32; ++j) {
      for(int k = 0; k < 4; ++k) {
        dist[i][j][k] = (1 << 29);
      }
    }
  }
}

int main() {
  for(;;) {
    Init();
    scanf("%d %d", &w, &h);
    if( w == 0 and h == 0 ) break;
    for(int i = 0; i < h; ++i) {
      for(int j = 0; j < w; ++j) {
        scanf("%d", &s[i][j]);
      }
    }
    for(int i = 0; i < 4; ++i) {
      scanf("%d", &cost[i]);
    }
    int res = dijkstra();
    printf("%d\n", res);
  }
  
  return 0;
}

Measured memory_bytes: 3400
#include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
#include <cmath>
#include <algorithm>
#include <map>
using namespace std;
map<int,char> e;
void read(int& x){
    x=0;
    int y=1;
    char ch=getchar();
    while (ch<'0'||ch>'9'){
        if (ch=='-') y=-1;
        ch=getchar();
    }
    while (ch>='0'&&ch<='9'){
        x=x*10+ch-'0';
        ch=getchar();
    }
    x=x*y;
}
int main(){
	int x,i,n,now=1,cnt=0;
	read(n);
	for (i=1;i<=n;++i){
		read(x);
		if (x<now){
			printf("No\n");
			continue;
		}
		printf("Yes\n");
		while (e[x]>0&&x>0){
			e[x]=0;
			--cnt;
			--x;
		}
		++cnt;
		e[x]=1;
		while (e[now]>0&&now<=500010){
			++now;
		}
		now=min(now,cnt);
		if (!x) now=1e9;
	}
	return 0;
}

Measured memory_bytes: 14772
#include <algorithm>
#include <cstdlib>
#include <iostream>
#include <memory>
#include <random>
using namespace std;

// Randomized Binary Search Tree
// infix, 0-based

typedef int type;
constexpr int INF = (1 << 29);
constexpr type INIT = INF;

mt19937 engine;
uniform_int_distribution<int> rnd;

// update function
inline type func(type a, type b) {
	return min(a, b);
}

struct RBST {
	type value, res;
	int size;
	RBST *left, *right;

	RBST(int v):value(v), res(v), size(1), left(nullptr), right(nullptr) {}

	void update() {
		size = 1;
		res = value;

		if(left) {
			size += left->size;
			res = func(res, left->res);
		}

		if(right) {
			size += right->size;
			res = func(res, right->res);
		}
	}
};

inline int node_size(const RBST *x) {
	return x ? x->size : 0;
}

RBST *merge(RBST * x, RBST * y) {
	if(!x) return y;
	if(!y) return x;

	if(rnd(engine) % (x->size + y->size) < x->size) {
		x->right = merge(x->right, y);
		x->update();
		return x;
	}
	else {
		y->left = merge(x, y->left);
		y->update();
		return y;
	}
}

typedef pair<RBST *, RBST *> P;

P split(RBST *x, int num) {
	if(!x) return P(nullptr, nullptr);

	const int l_size = node_size(x->left);
	if(l_size < num) {
		const P tmp = split(x->right, num - l_size - 1);
		x->right = tmp.first;
		x->update();
		return P(x, tmp.second);
	}
	else {
		const P tmp = split(x->left, num);
		x->left = tmp.second;
		x->update();
		return P(tmp.first, x);
	}
}

RBST *insert(RBST *x, int pos, type value) {
	RBST *new_node = new RBST(value);
	const P tmp = split(x, pos);
	return merge(merge(tmp.first, new_node), tmp.second);
}

RBST *erase(RBST *x, int pos) {
	P tmp = split(x, pos);
	RBST *left = tmp.first;
	tmp = split(tmp.second, 1);
	delete tmp.first;
	return merge(left, tmp.second);
}

// [l, r)

// x, [0, x-size)
type query(RBST *x, int l, int r) {
	if(!x) return INIT;
	if(r <= 0 || x->size <= l) return INIT;
	if(l <= 0 && x->size <= r) return x->res;

	const int l_size = node_size(x->left);
	const type res = (l <= l_size && l_size < r ? x->value : INIT);
	const type vl = query(x->left, l, r);
	const type vr = query(x->right, l - l_size - 1, r - l_size - 1);
	return func(res, func(vl, vr));
}

enum { SHIFT, QUERY, UPDATE };

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

	RBST *root = nullptr;
	for(int i = 0; i < n; ++i) {
		int a;
		cin >> a;
		root = insert(root, i, a);
	}

	while(q--) {
		int x, y, z;
		cin >> x >> y >> z;
		switch(x) {
		case SHIFT:
		{
			const auto value = query(root, z, z + 1);
			root = erase(root, z);
			root = insert(root, y, value);
			break;
		}
		case QUERY:
		{
			cout << query(root, y, z + 1) << endl;
			break;
		}
		case UPDATE:
		{
			root = erase(root, y);
			root = insert(root, y, z);
			break;
		}
		}
	}

	return EXIT_SUCCESS;
}

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

int main(){
  int A, B, C, D;
  cin >> A >> B >> C >> D;
 
  if(A+B > C+D){
    cout << "Left" ;
  }
  else if(A+B < C+D){
    cout << "Right" ;
  }
  else{
    cout << "Balanced" ;
  }
}

Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>

int main(void)
{
	int		 a,b, c,  num, max, min,  middle, i;
	
	scanf("%d",&num) ;
	
	for(i=0; i<num; i++){
		scanf("%d %d %d",&a, &b, &c);
		if(a > b){
			if(a>c){
				if(a*a == ((b*b) + (c*c))){
					printf("YES\r\n");
				}
				else{
					printf("NO\r\n");			
				}			
			}
			else {
				if(c*c == ((b*b) + (a*a))){
					printf("YES\r\n");
				}
				else{
					printf("NO\r\n");			
				}			
			}
		}
		else{
			if(c>b){
				if(c*c == ((a*a) + (b*b))){
					printf("YES\r\n");
				}
				else{
					printf("NO\r\n");			
				}			
			}
			else{
				if(b*b == ((c*c) + (a*a))){
					printf("YES\r\n");
				}
				else{
					printf("NO\r\n");			
				}			
			}

		}
	}
	return 0;
}

Measured memory_bytes: 580
#n, m, q = map(int, input().split())
#List = list(map(int, input().split()))
#req = [list(map(int, input().split())) for _ in range(q)]
#t = t[:-1]
#print(ans[j], end = "") 改行無しで出力
#[0]*n
n, k = map(int, input().split())
p = list(map(int, input().split()))
sort = sorted(p)
ans = 0

for i in range(k):
    ans = ans + sort[i]

print(ans)


Measured memory_bytes: 9176
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=(a);i<=(b);i++)
#define per(i,a,b) for(int i=(a);i>=(b);i--)
#define ms(s,x) memset(s,x,sizeof(s))
#define pb push_back
#define pf push_front
#define mp make_pair
#define inf 0x3f3f3f3f
typedef long long ll;
using namespace std;

const double PI = acos(-1.0);
const double eps = 1e-8;
const int MAXN = 1e5+5;
const ll MOD = 1e9+7;

int main()
{
    int n, q, t, ans = 0;
    int num[10005];
    cin >> n;
    rep(i, 1, n)
        cin >> num[i];
    cin >> q;
    while (q--)
    {
        cin >> t;
        rep(i, 1, n)
        {
            if (num[i] == t)
            {
                ans++;
                break;
            }
        }
    }
    printf("%d\n", ans);

    return 0;
}



Measured memory_bytes: 3220
s = gets.chomp.split("").map(&:to_i)
count = []
s.each_with_index do |v,i|
	if i !=0
		if v == s[i-1]
        	count.push(1)
        else
        	count.push(0)
		end
	end
end
if count.count(1) != 0
	puts "Bad"
else
	puts "Good"
end

Measured memory_bytes: 1788
#include <bits/stdc++.h>
#include <iostream>
#include <ctime>
using namespace std;
#define _LL long long
#define rep(i, n) for (_LL i = 0; i < (_LL)(n); i++)
#define vecrep(itr, v) for (auto itr = (v).begin(); itr != (v).end(); itr++)

int main()
{
    string s; cin >> s;
    int l = s.length();
    int total = 0;
    rep(i, l)
    {
        total += s[i] - '0';
    }
    if( total % 9 == 0 )
    {
        cout << "Yes";
    }
    else
    {
        cout << "No";
    }
    return 0;    
}

Measured memory_bytes: 3748
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;

public class Main {
    int n, k;
    String s;
    private static Scanner sc;
    public static void main(String[] args) {
        Main instance = new Main();
        sc = instance.new Scanner();
        instance.solve();
    }

    private void solve() {
        try {
            n = sc.nextInt();
            k = sc.nextInt();
            s = sc.next();
            List<Integer> index = new ArrayList<>();
            char current = '0';
            for (int i = 0; i < n; i++) {
                if (i == 0) {
                    index.add(i);
                    current = s.charAt(i);
                } else if (current != s.charAt(i)) {
                    index.add(i);
                    current = current == '0' ? '1' : '0';
                }
            }

            int lim = index.size();
            for (int i = 0; i < 3 * k; i++) {
                index.add(n);
            }

            int max = 0;

            for (int i = 0; i < lim; i++) {
                int tmpmax;
                if (s.charAt(index.get(i)) == '0') {
                    tmpmax = index.get(i + 2*k) - index.get(i);
                } else {
                    tmpmax = index.get(i + 2*k + 1) - index.get(i);
                }
                if (max < tmpmax) {
                    max = tmpmax;
                }
            }

            System.out.println(max);

        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    private class Scanner {
        String[] s;
        int i;
        BufferedReader br;
        String regex = " ";

        public Scanner() {
            s = new String[0];
            i = 0;
            br = new BufferedReader(new InputStreamReader(System.in));
        }

        @Override
        protected void finalize() throws Throwable {
            try {
                super.finalize();
            } finally {
                destruction();
            }
        }

        private void destruction() throws IOException {
            if (br != null) br.close();
        }

        public String next() throws IOException {
            if (i < s.length) return s[i++];
            String st = br.readLine();
            while (st == "") st = br.readLine();
            s = st.split(regex, 0);
            i = 0;
            return s[i++];
        }

        public int nextInt() throws NumberFormatException, IOException {
            return Integer.parseInt(next());
        }

        public Long nextLong() throws NumberFormatException, IOException {
            return Long.parseLong(next());
        }

        public Double nextDouble() throws NumberFormatException, IOException {
            return Double.parseDouble(next());
        }
    }
}

Measured memory_bytes: 31828
#include <bits/stdc++.h>
#define maxn 1000005
#define endl '\n'

using namespace std;

typedef long long ll;
typedef double db;
typedef pair <int,int> par;
typedef pair <par,int> tri;
const db eps = 1e-9;
const db pi = acos(-1);
const int inf = 1<<30;

int n, k, a[maxn], rmq[maxn][22];

int query ( int a, int b ) {
	int e = 31 - __builtin_clz ( b-a+1 );
	return min ( rmq[a][e], rmq[b-(1<<e)+1][e] );
}

int main() {
    //~ #ifdef acm
        //~ freopen ("a.in", "r", stdin );
        //~ freopen ("slingshot.out", "w", stdout );
    //~ #endif // acm
	//~ ios_base::sync_with_stdio (0);
	//~ cin.tie(0);
	
	cin >> n >> k;
	for ( int i = 1; i <= n; i ++ ) {
		cin >> a[i];
		rmq[i][0] = a[i];
	}

	for ( int j = 1; (1<<j) <= n; j ++ )
		for ( int i = 1; i+(1<<j)-1 <= n; i ++ )
			rmq[i][j] = min ( rmq[i][j-1], rmq[i+(1<<(j-1))][j-1] );
	for ( int i = 1; i+k-1 <= n; i ++ ) 
		cout << query ( i, i+k-1 ) << " \n"[i+k-1==n];

	return 0;
}




Measured memory_bytes: 92980
#include<iostream>
#include<string>
#include<vector>
#include<cmath>
#include<algorithm>
#include<set>
#include<stdio.h>
#include<ctype.h>
using namespace std;
int main()
{
	long long int a, b;
	cin >> a >> b;
	long long int aa = a;
	long long int bb = b;
	for(;;)
	{
		if (a < b)
		{
			a += aa;
		}
		else if(a>b)
		{
			b += bb;
		}
		else
		{
			break;
		}
		
	}
	cout << a << endl;
}


Measured memory_bytes: 256