akhauriyash/Code-Regression huggingface dataset:
let K = Int(readLine()!)!
let input = readLine()!.split(separator: " ").map { Int($0)! }
let A = input[0]
let B = input[1]

if A % K == 0 {
    print("OK")
} else {
    print(A / K != B / K ? "OK" : "NG")
}


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

using namespace std;

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

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

  ll x = n / (a + b);
  ll y = n % (a + b ) ;
  
  if(y >= a)
  {
    y = a;
  }
  
  cout << (x * a + y) << endl;
  
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <utility>
#include <algorithm>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <climits>
using namespace std;
typedef vector<int> vec;

#define MIN(a,b) (((a)<(b))?(a):(b))
#define MAX(a,b) (((a)>(b))?(a):(b))
#define N 100020
#define N2 100000020


int a[105];
//int p[N2];
//int q[N2];

int findmax(int t){
    int max=0,ind=-1;
    for (int i=0; i<t; i++) {
        if (a[i]>max ) {
            max=a[i];
            ind=i;
        }
    }
    return ind;
}
int findmaxnotpre(int t,int pre){
    int max=0,ind=-1;
    for (int i=0; i<t; i++) {
        if (a[i]>max && i!=pre) {
            max=a[i];
            ind=i;
        }
    }
    return ind;
}
int solve(){
    
    int k,t,count=0,pre=-1;
    cin>>k>>t;
    for (int i=0; i<t; i++) {
        cin>>a[i];
    }
//    sort(a, a + t);
    int ind=findmax(t);
    a[ind]--;
    pre =ind;
    for (int i=0; i<k-1; i++) {
        int ind=findmaxnotpre(t,pre);
        
        if (ind==-1) {
            count+=a[findmax(t)];
            return count;
        } else{
            a[ind]--;
            pre=ind;
        }
    }
    
    return count;
}
int main(int argc, const char * argv[]) {
    cout<<solve()<<endl;
    
    return 0;
}


















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

using namespace std;

int card[201];

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

    for (int i = 1; i <= 2*n; ++i) card[i] = i;

    for (int i = 0; i < m; ++i) {
        int k; cin >> k;
        int temp[201];
        if (k == 0) {
            int idx = 1;
            for (int j = 1; j <= n; ++j) {
                temp[idx]   = card[j];
                temp[idx+1] = card[n+j];
                idx += 2;
            }
        } else {
            int idx = 1;
            for (int j = 0; j < 2*n-k; ++j) {
                temp[idx++] = card[k+1+j];
            }
            for (int j = 0; j < k; ++j) {
                temp[idx++] = card[j+1];
            }
        }

        for (int j = 1; j <= 2 * n; ++j) {
            card[j] = temp[j];
        }
    }

    for (int i = 1; i <= 2*n; ++i) {
        printf("%d\n", card[i]);
    }

    return 0;
}

Measured memory_bytes: 1144
#include<iostream>
#include<map>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
int w,h,s,sum;
struct P{
	int y,x;
	P(){}
	P(int y,int x):y(y),x(x){}
};
P pmax(P a,P b){
	if(a.y!=b.y){
		if(a.y>b.y)
			return a;
		return b;
	}else{
		if(a.x>b.x)
			return a;
		return b;
	}
}
int u[32][32];
P dp[32][32][32][32];
P ret(P a,P b,int cnt){
	if(dp[a.y][a.x][b.y][b.x].y!=-1)
		return dp[a.y][a.x][b.y][b.x];
	P ans(1,cnt);
	int s1=0,s2=0;
	for(int i=a.y;i<b.y;i++){
		for(int j=a.x;j<=b.x;j++){
			s1+=u[i][j];
		}
		if(sum-s1>s)
			continue;
		if(sum-(cnt-s1)>s)
			break;
		P x=ret(a,P(i,b.x),s1),y=ret(P(i+1,a.x),b,cnt-s1);
		ans=pmax(ans,P(x.y+y.y,min(x.x,y.x)));
	}
	for(int i=a.x;i<b.x;i++){
		for(int j=a.y;j<=b.y;j++){
			s2+=u[j][i];
		}
		if(sum-s2>s)
			continue;
		if(sum-(cnt-s2)>s)
			break;
		P x=ret(a,P(b.y,i),s2),y=ret(P(a.y,i+1),b,cnt-s2);
		ans=pmax(ans,P(x.y+y.y,min(x.x,y.x)));
	}
	return dp[a.y][a.x][b.y][b.x]=ans;
}
int main(){
	while(cin>>h>>w>>s,h||w||s){
		sum=0;
		rep(i,h)rep(j,w)rep(k,h)rep(l,w)
		dp[i][j][k][l]=P(-1,0);
		rep(i,h)rep(j,w){
			cin>>u[i][j];
			sum+=u[i][j];
		}
		P ans=ret(P(0,0),P(h-1,w-1),sum);
		cout<<ans.y<<" "<<s-(sum-ans.x)<<endl;
	}
	return 0;
}

Measured memory_bytes: 9068
#include<stdio.h>
#include<string.h>
#include<ctype.h>

int main(){
  char ch,a;
  scanf("%c",&ch);
  a='\n';
  while(1){
    if(islower(ch)){
      printf("%c",toupper(ch));}
    else if(isupper(ch)){
      printf("%c",tolower(ch));}
    else printf("%c",ch);
    if(a==ch) break;
    scanf("%c",&ch);
    }
  return 0;}

Measured memory_bytes: 524
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <iomanip>
#include <utility>
#include <tuple>
#include <functional>
#include <bitset>
#include <cassert>
#include <complex>
#include <stdio.h>
#include <time.h>
#include <numeric>
#include <random>
#include <unordered_map>
#include <unordered_set>
#define all(a) a.begin(),a.end()
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define pb push_back
#define debug(x) cerr << __LINE__ << ' ' << #x << ':' << x << '\n'
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
using namespace std;
typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<ll, ll> P;
typedef complex<ld> com;
template<class T> using pque = priority_queue<T, vector<T>, greater<T>>;
constexpr int inf = 1000000010;
constexpr ll INF = 1000000000000000010;
constexpr int mod1e9 = 1000000007;
constexpr int mod998 = 998244353;
constexpr ld eps = 1e-12;
constexpr ld pi = 3.141592653589793238;
constexpr ll ten(int n) { return n ? 10 * ten(n - 1) : 1; };
int dx[] = { 1,0,-1,0,1,1,-1,-1 }; int dy[] = { 0,1,0,-1,1,-1,1,-1 };
void fail() { cout << "-1\n"; exit(0); } void no() { cout << "No\n"; exit(0); }
template<class T, class U> inline bool chmax(T &a, const U &b) { if (a < b) { a = b; return true; } return false; }
template<class T, class U> inline bool chmin(T &a, const U &b) { if (a > b) { a = b; return true; } return false; }
template<class T> istream &operator >> (istream &s, vector<T> &v) { for (auto &e : v) s >> e; return s; }
template<class T> ostream &operator << (ostream &s, const vector<T> &v) { for (auto &e : v) s << e << ' '; return s; }

struct fastio {
	fastio() {
		cin.tie(0); cout.tie(0);
		ios::sync_with_stdio(false);
		cout << fixed << setprecision(20);
		cerr << fixed << setprecision(20);
	}
}fastio_;

class unionfind {
	vector<int> par;
	vector<int> sz;
public:
	unionfind(int n) {
		par = vector<int>(n);
		for (int i = 0; i < n; i++) par[i] = i;
		sz = vector<int>(n, 1);
	}
	int find(int x) {
		if (par[x] == x) return x;
		else return par[x] = find(par[x]);
	}
	int size(int x) { return sz[find(x)]; }
	bool same(int x, int y) { return find(x) == find(y); }
	void unite(int x, int y) {
		x = find(x);
		y = find(y);
		if (x == y) return;
		if (sz[x] < sz[y]) {
			par[x] = y;
			sz[y] += sz[x];
		}
		else {
			par[y] = x;
			sz[x] += sz[y];
		}
	}
};

int main() {
	int n;
	cin >> n;
	unionfind uni(n);
	vector<pair<P, int>> p(n);
	rep(i, n) {
		int x, y;
		cin >> x >> y;
		x--; y--;
		p[i].first.first = x;
		p[i].first.second = y;
		p[i].second = i;
	}
	sort(all(p));
	pque<P> que;
	rep(i, n) {
		P mi = { p[i].first.second,i };
		P t = mi;
		while (!que.empty()) {
			if (que.top() > t) break;
			P p = que.top(); que.pop();
			uni.unite(p.second, i);
			chmin(mi, p);
		}
		que.push(mi);
	}
	vector<int> ans(n);
	rep(i, n) ans[p[i].second] = uni.size(i);
	rep(i, n) cout << ans[i] << '\n';
}

Measured memory_bytes: 10568
#include<iostream>
#include<string>
#include<algorithm>
#include<cstdlib>
#include<cmath>
#include<vector>
#include<list>
#include<cstdint>
#include<bits/stdc++.h>
#include<queue>
#include<set>

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define rep_r(i, n) for(int i = n-1; i >= 0; i--)
#define rep1(i, n) for(int i = 1; i <= (int)(n); i++)
#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define all(x) (x).begin(),(x).end()
#define SZ(x) ((ll)(x).size())
#define bit(n) (1LL<<(n))
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );

#define INF bit(60)
#define pb push_back
#define mod 1000000007

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

using namespace std;
using uif=uint_fast64_t;
using ll=long long int;

int qp(int a,ll b){int ans=1;do{if(b&1)ans=1ll*ans*a%mod;a=1ll*a*a%mod;}while(b>>=1);return ans;}
int qp(int a,ll b,int mo){int ans=1;do{if(b&1)ans=1ll*ans*a%mo;a=1ll*a*a%mo;}while(b>>=1);return ans;}

int gcd(int a,int b){return b?gcd(b,a%b):a;}
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};


#define FACSIZE 2002

ll invfac[FACSIZE];
ll fac[FACSIZE];

ll mod_pow(ll ,ll );
ll mod_add(ll ,ll );
ll mod_mul(ll ,ll );
ll mod_div(ll ,ll );
void make_fact(ll );
void make_invfact(ll );



int main(void){

  ll n,d;
  cin>>n>>d;

  if( n%(2*d+1)==0 ){
    cout << n/(2*d+1) << endl;
  }
  else{
    cout << n/(2*d+1)+1 << endl;  
  }
  

  return 0;

}

ll mod_pow(ll x,ll r){
  if(r==0) return 1;
  else if(r==1) return x%mod;
  else if(r%2==0){
    ll t=mod_pow(x,r/2)%mod;
    return t*t %mod;
  } 
  else{
    ll t=mod_pow(x,r/2)%mod;
    ll k= t*t %mod;
    return k*x%mod;
  } 
}
ll mod_add(ll a,ll b){
  return (a+b)%mod;
}

ll mod_mul(ll a,ll b){
  return (a*b)%mod;
}

ll mod_div(ll a,ll b){
  return mod_mul(a,mod_pow(b,mod-2));
}

void make_fact(ll n){
  fac[0]=1;
  rep(i,n){
    fac[i+1]=mod_mul(fac[i],i+1);
  }  
}

void make_invfact(ll n){
  invfac[n]= mod_pow( fac[n] ,mod-2);
  for(int i=n-1;i>=0;i--){
    invfac[i]=mod_mul(invfac[i+1],i+1);
  }

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0; i < n; i++)
#define all(x) (x).begin(), (x).end()
#define INF 1000000007
#define mod 1005
#define ll long long int
const double mx = 2e6 + 5 ;
/*
8
100 120 100 120 100 120 100 120*/
void solve()
{
	ll n;
	cin>>n;
	ll money = 1000;
	ll stocks = 0;
	vector<ll> price(n+1);
	REP(i,n)
		cin>>price[i];
	int day = 0; //0th days
	while(day<n)
	{
//		cout<<day<<"->\n";
		while(day+1<n && price[day]>=price[day+1]) //find the lowest point
			day++;
		if(day!=n-1) // if the lowest point is not the end of the array
		{
			stocks = money/price[day]; //buy the maximum possible stocks
			money-=(stocks*price[day]); // subtract the price of those stocks from the money
		}
		day++;
//		cout<<"buy: "<<stocks<<", money left:"<<money<<"\n";
		while(day<n && price[day]<=price[day+1])
			day++;
//		cout<<day<<"\n";
		money+=(stocks*price[day]);
		stocks=0;
		day++;
//		cout<<day<<"\n";
//		cout<<"sell: "<<stocks<<", money made: "<<money<<"\n";
//		cout<<day<<"<-\n";
	}
	cout<<money<<"\n";
}
int main()
{
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
	int t = 1;
//	cin>>t;
	while(t--)
	{
		solve();
	}
	return 0;
}

Measured memory_bytes: 3656
package main

import "fmt"

func num_div(n int) int {
	if n%2 == 0 {
		return num_div(n/2) + 1
	} else {
		return 0
	}
}

func main() {
	var n int
	fmt.Scan(&n)
	as := make([]int, n)
	for i := range as {
		fmt.Scan(&as[i])
	}

	min := num_div(as[0])
	for _, a := range as {
		if nd := num_div(a); nd < min {
			min = nd
		}
	}
	fmt.Println(min)
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
char a[100010];
int la,i;
int main()
{
    gets(a);
    la=strlen(a);
    for(i=0;i<=la/2;i++)
    {
        int l=i,r=la-i-1;
        if(a[l]=='b' && a[r]=='d' || a[l]=='d' && a[r]=='b' || a[l]=='p' && a[r]=='q' || a[l]=='q' && a[r]=='p');
        else
        {
            printf("No");
            return 0;
        }
    }
    printf("Yes");
    return 0;
}

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

using namespace std;

typedef long long LL;

const int N = 110;
int a[N];

int main() {
    int n, m, sum = 0;
    scanf("%d", &n);
    for (int i = 1; i <= n; i++) scanf("%d", a + i), sum += a[i];
    scanf("%d", &m);
    while (m--) {
        int p, x;
        scanf("%d%d", &p, &x);
        printf("%d\n", sum - a[p] + x);
    }
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define all(vec) vec.begin(),vec.end()
#define mp make_pair
using namespace std;
using ll=long long;
using P=pair<ll,ll>;
const ll INF=1LL<<30;
const ll LINF=1LL<<60;
const double eps=1e-5;
const ll MOD=1000000007LL;
template<typename T>void chmin(T &a,T b){a=min(a,b);};
template<typename T>void chmax(T &a,T b){a=max(a,b);};
int dx[4]={0,1,0,-1};
int dy[4]={1,0,-1,0};
int main(){
    int n;cin>>n;
    vector<int> a(n);
    for(int i=0;i<n;i++)cin>>a[i];
    sort(all(a));
    int sum=0;
    for(int i=0;i<n-1;i++){
        sum+=a[i];
    }
    if(sum>a[n-1]){
        cout<<"Yes"<<endl;
    }else{
        cout<<"No"<<endl;
    }
}


Measured memory_bytes: 256
#include<stdio.h>
#include <algorithm>
#include <string.h>
using namespace std;

int main(){
	int a, b;
	scanf("%d %d", &a, &b);
	if (a <= 5)printf("0");
	else if (a <= 12) printf("%d", b / 2);
	else printf("%d", b);
}

Measured memory_bytes: 1700
#include <iostream>
using namespace std;
int main()
{
    int a, b, c, t;
    cin >> a >> b >>c;
	
	if (a > b){
                t = a;
		a = b;
		b = t;
                t = 0;
	}
	if(b > c){
		t = b;
		b = c;
		c = t;
                t = 0;
	}
	if (a > b){
                t = a;
		a = b;
		b = t;
	}
	
	
	cout << a << " " << b << " " << c << endl;
	return 0;
}

Measured memory_bytes: 1164
#include <cstdio>
using namespace std;

int main()
{
	int a, b;
	bool first = true;

	while (scanf("%d%d", &a, &b), a){
		if (!first){
			printf("\n");
		}

		first = false;

		bool na = true;
		for (int i = a; i <= b; i++){
			if (i % 400 == 0 || (i % 4 == 0 && i % 100 != 0)){
				printf("%d\n", i);
				na = false;
			}
		}

		if (na){
			printf("NA\n");
		}
	}

	return (0);
}

Measured memory_bytes: 1044
#include <bits/stdc++.h>
#define syosu(x) fixed<<setprecision(x)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef pair<double,double> pdd;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<string> vs;
typedef vector<P> vp;
typedef vector<vp> vvp;
typedef vector<pll> vpll;
typedef pair<int,P> pip;
typedef vector<pip> vip;
const int inf=1<<30;
const ll INF=1ll<<60;
const double pi=acos(-1);
const double eps=1e-9;
const ll mod=1e9+7;
const int dx[4]={0,1,0,-1},dy[4]={1,0,-1,0};

ll Pow(ll n,ll p){
	ll r=1;
	for(;p>0;p>>=1){
		if(p&1) r=(r*n)%mod;
		n=(n*n)%mod;
	}
	return r;
}

const int M=110000;
ll F[M];

void Init(){
	F[0]=1;
	for(int i=1;i<M;i++) F[i]=F[i-1]*i%mod;
}

ll Div(ll n,ll m){
	return n*Pow(m,mod-2)%mod;
}

ll nCk(ll n,ll k){
	return Div(F[n],F[n-k]*F[k]%mod);
}

ll n,m;

ll f(ll x){
	ll t=0,M=m;
	while(m%x==0){
		m/=x;
		t++;
	}
	return nCk(n+t-1,t);
}

int main(){
	Init();
	cin>>n>>m;
	ll res=1;
	for(ll i=2;i*i<=m;i++) if(m%i==0){
		(res*=f(i))%=mod;
	}
	if(m>1) (res*=f(m))%=mod;
	cout<<res<<endl;
}

Measured memory_bytes: 1152
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.Scanner;

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

    static class TaskB {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            int n = in.nextInt();
            int[] l = new int[n];

            for (int i = 0; i < n; i++) {
                l[i] = in.nextInt();
            }

            Arrays.sort(l);
            int sum = 0;
            for (int i = 0; i < n - 1; i++) {
                sum += l[i];
            }

            if (l[n - 1] < sum) {
                out.print("Yes");
            } else {
                out.print("No");
            }

        }

    }
}



Measured memory_bytes: 23764
#include <iostream>
#include <string>
#include <vector>
#include <deque>
#include <list>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <array>
#include <queue>
#include <stack>
#include <algorithm>
#include <tuple>
#include <numeric>
#include <type_traits>

int main()
{
	long N;
	std::unordered_map<long, std::unordered_map<long, long> > E; // src -> {dst -> weight}

	std::cin >> N;
	for (int i = 0; i < N-1; ++i) {
		long u, v;
		long w;
		std::cin >> u >> v >> w;
		--u;
		--v;
		E[u][v] = w;
		E[v][u] = w;
	}

	std::vector<long> D;
	std::priority_queue<std::pair<long, long>, std::vector<std::pair<long, long>>, std::greater<std::pair<long, long>>> Q;
	D.resize(N);
	D[0] = 0;
	for (long i = 1; i < N; ++i) {
		D[i] = std::numeric_limits<long>::max();
	}
	Q.push({0, 0});

	while (!Q.empty()) {
		auto wu = Q.top();
		auto u = wu.second;
		Q.pop();
		const auto& edges = E[u];
		for (auto& vw : edges) {
			auto v = vw.first;
			auto w = vw.second;
			long alt = D[u] + w;
			if (D[v] > alt) {
				D[v] = alt;
				Q.push({alt, v});
			}
		}
	}

	for (long i = 0; i < N; ++i) {
		std::cout << (D[i] % 2) << "\n";
	}
}


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

#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,s,n) for(int i=(s);i<=(n);i++)
#define repr(i,n) for(int i=n-1;i>=0;i--)
#define REPR(i,s,n) for(int i=(s);i>=(n);i--)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define Eunique(v) v.erase(unique(all(v)),v.end())
#define Eback(s) s.erase(s.end()-1,s.end())
#define rev(v) reverse(all(v))
#define minvec(v) *min_element(all(v))
#define maxvec(v) *max_element(all(v))
#define pb push_back
#define pf push_front
#define mod 1000000007
#define m_p make_pair
#define DOUBLE fixed << setprecision(15)
#define OK puts("OK")
#define OK1 puts("OK1")
#define OK2 puts("OK2")
#define SIZE(s) (int)s.size()
#define INF ((1LL<<62)-(1LL<<31))
#define zero(x,n) setw(x) << setfill('0') << n

typedef long long ll;

typedef vector<int> vi;
typedef vector<long long> vll;
typedef vector<double> vd;
typedef vector<char> vc;
typedef vector<string> vs;

typedef vector<vi> vvi;
typedef vector<vll> vvll;
typedef pair<ll,ll> pll;
typedef pair<int,int> pii;
typedef vector<pair<int,int>> vpii;
typedef vector<pair<ll,ll>> vpll;

const double pi = acos(-1.0);

template<class A, class B>
ostream& operator<<(ostream& ost, const pair<A, B>&p) {
	ost << "{" << p.first << ", " << p.second << "} ";
	return ost;
}

template<class T>
ostream& operator<<(ostream& ost, const vector<T>&v) {
	ost << "{";
	for (int i = 0; i<(int)v.size(); i++) {
		if (i)ost << " ";
		ost << v[i];
	}
	ost << "} \n";
	return ost;
}

template<class A, class B>
ostream& operator<<(ostream& ost, const map<A, B>&v) {
	ost << "{";
	for (auto p:v) {
		ost << "{" << p.first << ", " << p.second << "} ";
	}
	ost << "} ";
	return ost;
}

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

ll gcd(ll x, ll y) {return __gcd(x,y);}
ll lcm(ll x, ll y) {return x/__gcd(x,y)*y;}

int main()
{
	ll n,m,x,y,ans=0;
	cin >> n;
	vvll a(n,vll(n,-1));
	rep(i,n){
		cin >> m;
		rep(j,m){
			cin >> x >> y;
			a[i][x-1]=y;
		}
	}
	rep(i,1<<n){
        vll v;
		vll tmp(n);
		bool b=true;
        rep(j,n){
            if(i&(1<<j)) tmp[j]=1;
        }
		rep(j,n){
			if(tmp[j]){
				rep(k,n){
					if(a[j][k]==-1) continue;
					if(a[j][k]!=tmp[k]) b=false;
				}
			}
		}
		if(b) chmax(ans,(ll)__builtin_popcount(i));
    }
	cout << ans << endl;
	return 0;
}

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

int main()
{
    char str[1205];
    cin.getline(str,1205);
    int l=strlen(str);
    for(int i=0;i<l;i++)
    {
        if(str[i]>=65 && str[i]<=90)
        {
            str[i]=str[i]+32;
        }
        else if(str[i]>=97 && str[i]<=122)
        {
            str[i]=str[i]-32;
        }
    }
    cout<<str<<endl;


    return 0;
}



Measured memory_bytes: 3096
fun main(args: Array<String>) {
    val MOD = 1000000007L
    val SIZE = 2002
    val c = Array<LongArray>(SIZE+1) { LongArray(SIZE+1) }
    c[0][0] = 1
    for (i in 0 until SIZE) {
        for (j in 0 until SIZE) {
            c[i + 1][j] += c[i][j]
            c[i + 1][j] %= MOD
            c[i + 1][j + 1] += c[i][j]
            c[i + 1][j + 1] %= MOD
        }
    }
    fun comb(n: Int, k: Int): Long = if (n < k) 0 else c[n][k]
    fun f2(n: Int, k: Int): Long = comb(n + k - 1, k - 1)
    fun f(n: Int, k: Int): Long = if (k < 1) 0 else f2(n-k, k)

    val (N, K) = listOfInt()
    for (i in 1..K) {
        val blue = f(K, i)
        val red = f2(N - K - (i - 1), i + 1)
        val ans = blue * red % MOD
        println(ans)
    }
}
fun next() = readLine()!!
fun listOfString() = next().split(" ")
fun listOfInt() = listOfString().map { Integer.parseInt(it) }


Measured memory_bytes: 90724
n,m,k=map(int,input().split())
A=list(map(int,input().split()))
B=list(map(int,input().split()))

asum=[0]
bsum=[0]

for i in range(n):
  asum.append(asum[i]+A[i])
  
for j in range(m):
  bsum.append(bsum[j]+B[j])

ans=0
ko=m
for i in range(n+1):
  if asum[i]>k:
    break
  while asum[i]+bsum[ko]>k:
    ko-=1
  ans=max(ans,i+ko)
  
print(ans)


Measured memory_bytes: 47508
import java.util.*;
import static java.lang.Math.*;
import java.math.BigInteger;

public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		
		// 入力
		int n = sc.nextInt();
		
		// 計算
		long result = 0;
		long a = 2;
		long b = 1;
		for(int i = 1; i < n+1; i++){
		    if(i == 1) result = 1;
		    if(i > 1){
		        result = a + b;
		        a = b;
		        b = result;
		    }
		}
		
		// 出力
		System.out.println(result);
	}
}



Measured memory_bytes: 23892
#include <iostream>
#include "bits/stdc++.h"
using namespace std;
#define print(x) cout<<x<<endl;
#define rep(i,a,b) for(ll i=a;i<b;i++)
#define REP(i,a) for(ll i=0;i<a;i++)
#define jkl ll debug = 0;
#define RREP(i,a) for(ll i=a-1;i>=0;i--)
#define rrep(i,a,b) for(ll i=a-1;i>=b;i--)
#define printall(n,array) {for(ll i=0;i<n;i++){cout<<array[i]<<" ";}cout<<endl;}
#define U() cout<<endl;
#define mp make_pair
typedef long long ll;
typedef pair<ll, ll> Pi;
typedef pair<ll, Pi> V;
typedef vector<ll> VE;
const ll mod = 1e9 + 7; //10^9+7

int main(){
    ll n, m;
    VE x;
    ll X, sum = 0;
    VE diff;
    cin >> n >> m;
    REP(i, m){
        cin >> X;
        x.push_back(X);
    }
    if(n >= m){
        print(0);
        return 0;
    }
    sort(x.begin(), x.end());
    REP(i, x.size()-1){
        ll D = x[i] - x[i+1];
        diff.push_back(abs(D));
        sum += abs(D);
    }
    sort(diff.rbegin(), diff.rend());
    REP(i, n-1){
        sum -= diff[i];
    }
    print(sum);
}



Measured memory_bytes: 2548
#include <bits/stdc++.h>
  using namespace std;
  typedef long long ll;
  const ll P = 1e9 + 7;


  int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int n;
    cin >> n;
    int a[n + 1];
    memset(a, 0, sizeof(a));
    for (int i = 1; i < n; i++) {
      int x;
      cin >> x;
      a[x]++;
    }
    for (int i = 1; i <= n; i++) {
      cout << a[i] << '\n';
    }
    return 0;
  }

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

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

    vector<int> a(n);
    for (auto i = 0; i < n; i++) cin >> a[i];

    cin >> q;
    vector<int> m(q);
    for (auto i = 0; i < q; i++) cin >> m[i];

    map<int, bool> sum;
    for (auto i = 0; i < (1 << n); i++) {
        int tmp = 0;
        for (auto j = 0; j < n; j++) {
            if(i & (1 << j)) tmp += a[j];
        }
        sum[tmp] = true;
    }

    for (auto i = 0; i < q; i++) {
        if(sum.count(m[i])) cout << "yes" << endl;
        else cout << "no" << endl;
    }

    return 0;
}


Measured memory_bytes: 3120
#define _GLIBCXX_DEBUG
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
ll MOD = 1e9 + 7;
int INF = 1 << 30;


int main(void){

    string S; cin>>S;

    if(S=="ABC") cout<<"ARC"<<endl;
    else cout<<"ABC"<<endl;

}


Measured memory_bytes: 3624
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <cmath>

int main()
{
    int a, b, ans = 0;
    std::cin >> a >> b;

    for (int i = 0; i < 2; i++)
    {
        if (a > b)
        {
            ans += a;
            a--;
        }
        else
        {
            ans += b;
            b--;
        }
    }

    std::cout << ans << std::endl;
    return 0;
}

Measured memory_bytes: 384
import sys

S = input()
if len(set(S)) == 1:
    print(0)
    sys.exit()

tmp = ""
for i in range(1, len(S)):
    if S[i - 1] == S[i]:
        continue
    else:
        tmp += S[i - 1]

tmp += S[-1]
# print(tmp)
print(len(tmp) - 1)


Measured memory_bytes: 3316
#include <bits/stdc++.h>
#define REP(i,a,b) for(int i=(a);i<(b);i++)
typedef long long ll;
using namespace std;
const int INF=1e9, MOD=1e9+7;
const int MAX_N=10000;
int a,b,c,d,e,f;

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	
	cin >> a >> b >> c >> d >> e >> f;
	
	bool water[3001]={false};
	bool sugar[3001]={false};
	REP(i,0,31) REP(j,0,31) if(100*a*i+100*b*j<=f) water[100*a*i+100*b*j]=true;
	REP(i,0,3001) REP(j,0,3001) if(c*i+d*j<=f) sugar[c*i+d*j]=true;
	
	int wat=0,sug=0;
	REP(i,1,3001){
		REP(j,0,3001){
			if(water[i] and sugar[j] and i*e>=100*j){
				if(i+j<=f and sug*(i+j)<=j*(wat+sug)){
					wat=i;
					sug=j;
				}
			}
		}
	}
	
	cout << wat+sug << " " << sug << endl;
	return 0;
}


Measured memory_bytes: 256
//g++ -std=c++14 test.cpp -o test.out
#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <cassert>
#include <algorithm>
#include <functional>
#include <iostream>
#include <iomanip>
#include <vector>
#include <queue>
#include <map> 
#include <utility>
using namespace std;

#define ll long long int 
ll gcd(ll a, ll b) { return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) { return a/gcd(a,b)*b;}
 
ll N,M;
ll a[100000];

ll ans = 0;

ll numof2(ll X){//約数の2の個数を返す
	ll ret = 0;
	ll n = X;
	while(1){
		if(n%2==1) return ret;
		n/=2;
		ret+=1;
	}
}
 
void solve(){
	sort(a,a+N);
	//各(a[i]/2)が同じ数2を約数に持っているか調べる
	//持ってなければ条件を満たすXは存在しない
	ll t = numof2(a[0]/2);
	for(int i=1;i<N;i++){
		if(t!=numof2(a[i]/2))return;
	}
	M >>= t;

	ll lcm_ak = a[0]>>(t+1);
	for(int i=1;i<N;i++){
		lcm_ak = lcm(lcm_ak,a[i]>>(t+1));
	}

	//1~Mまでの(奇数×lcm_ak)の数を数える
	//まずM/lcm_akで1~Mのうち、lcm_akを約数に持つ数全部がわかる
	//その中から奇数だけを取り出す
	//注意：lcm_akは奇数なので
	//1~Mのうち、lcm_akを約数に持つ数全部がわかるが、これらの数は小さい順に
	//奇数、偶数、奇数、偶数、....と交互に続く
	ans = (M/lcm_ak+1)/2;
}
 
int main(){
	cin>>N>>M;
	for(int i=0;i<N;i++) cin>>a[i];

	solve();

	cout<<ans;
	return 0;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<ll,ll>;
using vl = vector<ll>;
using Map = map<ll,ll>;
using Tup = tuple<ll,ll,ll>;
using vvl = vector<vector<ll>>;
#define all(v) v.begin(), v.end()
#define prt(v) cout<<(v)<<"\n";
#define fl cout<<flush;
#define fi(v) get<0>(v)
#define se(v) get<1>(v)
#define th(v) get<2>(v)
#define endl "\n"
template <typename T> bool chmax(T &a, const T &b){if (a<b){a=b;return 1;}return 0;}
template <typename T> bool chmin(T &a, const T &b){if (a>b){a=b;return 1;}return 0;}
const ll INF=1LL<<60;
const ll MOD=1000000007;

#define MAX 200007
long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void fact() {
    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 comb(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;
}

signed main(void){
    cin.tie(0);cout.tie(0);ios::sync_with_stdio(false);
    fact();
    ll N;
    cin >> N;
    ll M;
    cin >> M;
    if(llabs(N-M)==1){
        prt(fac[N]*fac[M]%MOD)
    }
    else if(N==M){
        prt(2*fac[N]%MOD*fac[M]%MOD)
    }
    else prt(0)

    return 0;
}


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

int main() {
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	int N; cin >> N;
	long long tot = 0;
	vector<long long> cnd;
	for (int i = 0; i < N; i++) {
		if (i) cnd.push_back(tot);
		int a; cin >> a; tot += a;
	}
	long long ans = 1e18;
	for (long long v : cnd) {
		ans = min(ans, abs(2 * v - tot));
	}
	cout << ans << '\n';

	return 0;
}


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

using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int r;
  cin >> r;
  if (r < 1200) {
    cout << "ABC" << '\n';
  } else if (r < 2800) {
    cout << "ARC" << '\n';
  } else {
    cout << "AGC" << '\n';
  }
  return 0;
}

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


namespace D
{
    class Program
    {
        static long n, a, b;
        static long[] input;
        static long INF = 1000000000;
        static void Main(string[] args)
        {
            var ngo = Console.ReadLine().Split().Select(x => long.Parse(x)).ToArray();
            n = ngo[0];
            a = ngo[1];
            b = ngo[2];
            input = new long[n];
            for (long i = 0; i < n; ++i)
            {
                input[i] = long.Parse(Console.ReadLine());
            }

            Console.WriteLine(binarySearch());
        }

        static long binarySearch()
        {
            long left = 0;
            long right = INF;
            long trueMIN = INF;
            long falseMIN = 0;
            long lastMid = 114514;
            bool[] flag = new bool[INF];
            while (left < right)
            {
                long mid = (left + right) / 2;
                bool exp = explosion(mid);
               // Console.WriteLine("left=" + left + " right=" + right + " mid=" + mid+" exp="+exp);
                if (flag[mid])
                {
                    return mid;
                }
                else if (exp) //trueなら増やす
                {
                    right = mid;
                    flag[mid] = true;
                }
                else
                {
                    left = mid + 1;
                }
                lastMid = mid;
            }
            /*
            for (long i = 0; i < 100; ++i)
            {
                Console.Write(flag[i] + " ");
                if (i % 10 == 0) Console.WriteLine();
            }
             * */
            if (flag[lastMid])
            {
                return lastMid;
            }
            return Array.IndexOf(flag, true);
        }

        static bool explosion(long t)
        {
            long bt = b * t;
            long ab = a - b;
            long sum = 0;
            for (long i = 0; i < n; ++i)
            {
                if (input[i] > bt)
                {
                    sum += (long)Math.Ceiling((input[i] - bt) / (ab * 1.0));
                }
            }
            return sum <= t;
        }
    }
}


Measured memory_bytes: 34524
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
#define repr(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) for(int i=0;i<n;i++)
#define invrepr(i,a,b) for(int i=b-1;i>=a;i--)
#define invrep(i,n) invrepr(i,0,n)
const int MOD=1e9+7;


int main() {
    int n;
    cin >> n;
    vector<int> a(n);
    rep(i,n) cin >> a[i];
    vector<int> b;
    b.push_back(a[n-1]);
    invrep(i,n-1) {
        int j=upper_bound(b.begin(),b.end(),a[i])-b.begin();
        if (j==b.size()) b.push_back(a[i]);
        else b[j]=a[i];
    }
    cout << b.size() << endl;
}

Measured memory_bytes: 1276
s = gets.chomp.to_i
 
aa = s/100
bb = s%100
 
ay = true
am = 0 < aa && aa < 13
by = true
bm = 0 < bb && bb < 13
 
if am && bm
  puts "AMBIGUOUS"
elsif !am && bm
  puts "YYMM"
elsif am && !bm
  puts "MMYY"
elsif !am && !bm
  puts "NA"
end


Measured memory_bytes: 1788
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

func main() {
	sc := NewScanner()
	N, S := sc.NextInt(), sc.Next()

	count := 1
	for i := 1; i < N; i++ {
		if S[i] != S[i-1] {
			count++
		}
	}
	fmt.Println(count)

}

type Scanner struct {
	r   *bufio.Reader
	buf []byte
	p   int
}

func NewScanner() *Scanner {
	rdr := bufio.NewReaderSize(os.Stdin, 1000)
	return &Scanner{r: rdr}
}
func (s *Scanner) Next() string {
	s.pre()
	start := s.p
	for ; s.p < len(s.buf); s.p++ {
		if s.buf[s.p] == ' ' {
			break
		}
	}
	result := string(s.buf[start:s.p])
	s.p++
	return result
}
func (s *Scanner) NextLine() string {
	s.pre()
	start := s.p
	s.p = len(s.buf)
	return string(s.buf[start:])
}
func (s *Scanner) NextInt() int {
	v, _ := strconv.Atoi(s.Next())
	return v
}
func (s *Scanner) NextInt64() int64 {
	v, _ := strconv.ParseInt(s.Next(), 10, 64)
	return v
}

func (s *Scanner) NextFloat() float64 {
	v, _ := strconv.ParseFloat(s.Next(), 64)
	return v
}

func (s *Scanner) NextIntArray() []int {
	s.pre()
	start := s.p
	result := []int{}
	for ; s.p < len(s.buf)+1; s.p++ {
		if s.p == len(s.buf) || s.buf[s.p] == ' ' {
			v, _ := strconv.ParseInt(string(s.buf[start:s.p]), 10, 0)
			result = append(result, int(v))
			start = s.p + 1
		}
	}

	return result
}
func (s *Scanner) NextInt64Array() []int64 {
	s.pre()
	start := s.p
	result := []int64{}
	for ; s.p < len(s.buf)+1; s.p++ {
		if s.p == len(s.buf) || s.buf[s.p] == ' ' {
			v, _ := strconv.ParseInt(string(s.buf[start:s.p]), 10, 64)
			result = append(result, v)
			start = s.p + 1
		}
	}
	return result
}

func (s *Scanner) NextMap() map[int]bool {
	s.pre()
	start := s.p
	mp := map[int]bool{}
	for ; s.p < len(s.buf); s.p++ {
		if s.buf[s.p] == ' ' {
			v, _ := strconv.Atoi(string(s.buf[start:s.p]))
			mp[v] = true
			start = s.p + 1
		}
	}
	v, _ := strconv.Atoi(string(s.buf[start:s.p]))
	mp[v] = true

	return mp
}

func (s *Scanner) pre() {
	if s.p >= len(s.buf) {
		s.readLine()
		s.p = 0
	}
}
func (s *Scanner) readLine() {
	s.buf = make([]byte, 0)
	for {
		l, p, e := s.r.ReadLine()
		if e != nil {
			panic(e)
		}
		s.buf = append(s.buf, l...)
		if !p {
			break
		}
	}
}


Measured memory_bytes: 1280
#include<bits/stdc++.h>
using namespace std;
#define ll long long 
#define f first 
#define s second

vector<pair<ll, ll>> vec(3000);
ll dp[3000][3000];
ll n;
  
ll solve(ll l, ll r){
	if(l>r)return 0;
	if(dp[l][r]!=-1)return dp[l][r];
	
	ll idx=(n-(r-l+1)+1);
	ll ans1=abs(l-vec[idx].s)*vec[idx].f + solve(l+1,r);
	ll ans2=abs(r-vec[idx].s)*vec[idx].f + solve(l, r-1);
	
	return dp[l][r]=max(ans1, ans2);
}
  
int main()  {
	cin>>n;
	for(ll i=1;i<=n;i++){
		cin>>vec[i].f;
		vec[i].s=i;
	}
	sort(vec.begin()+1,vec.begin()+1+n);
	reverse(vec.begin()+1,vec.begin()+1+n);
	memset(dp , -1 , sizeof (dp));
	ll ans = solve(1,n);
	cout<<ans<<endl;
}

Measured memory_bytes: 74096
#include <stdio.h>
int main(){
  int x,y,p,q,tmp;
  scanf("%d%d",&x,&y);
  if(x>=y){
    p=x;
    q=y;
  }else{
    p=y;
    q=x;
  }
  while(1){
    tmp=q;
    q=p%q;
    p=tmp;
    if(q==0) break;
  }
  printf("%d\n",tmp);
  return 0;
}



Measured memory_bytes: 2120
#include<stdio.h>
int main()
{
	int i,len,j = 0;
	char s[11];
	scanf("%s",s);
	for(i = 0;s[i] != '\0';i++)
	{
		if(s[i] == 'B')
		{
			s[i] = '2';
			for(j = i - 1;j >= 0;j--)
			{
				if(s[j] != '2')
				{
					s[j] = '2';
					break;
				}
			}
		}
	}
	for(i = 0;s[i] != '\0';i++)
	{
		if(s[i] != '2')
			printf("%c",s[i]);
	}
	printf("\n");
	return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
int main(){
 int R;
 cin>>R;
 if(R<1200){
     cout<<"ABC"<<endl;
 }
 else if(R<2800){
     cout<<"ARC"<<endl;
 }
 else 
 cout<<"AGC"<<endl;
}


Measured memory_bytes: 3568
package main

import "fmt"

func main() {
	var n int
	fmt.Scan(&n)
	monsterNums := ScanNums(n + 1)
	beatableMonseterNums := ScanNums(n)
	beatedMonsterNum := 0

	for i := 0; i < n; i++ {
		beatableNum := beatableMonseterNums[i]
		if beatableNum <= monsterNums[i] {
			beatedMonsterNum += beatableNum
		} else {
			beatedMonsterNum += monsterNums[i]
			beatableNum -= monsterNums[i]
			if beatableNum > 0 && monsterNums[i+1] > 0 {
				if beatableNum <= monsterNums[i+1] {
					beatedMonsterNum += beatableNum
					monsterNums[i+1] = monsterNums[i+1] - beatableNum
				} else {
					beatedMonsterNum += monsterNums[i+1]
					monsterNums[i+1] = 0
				}
			}
		}
	}
	fmt.Println(beatedMonsterNum)
}

func ScanNums(len int) (nums []int) {
	var num int
	for i := 0; i < len; i++ {
		fmt.Scan(&num)
		nums = append(nums, num)
	}
	return
}


Measured memory_bytes: 7556
import java.io.*;
import java.math.*;
import java.util.*;
public class Main { 
 
	public static void main(String[] args) { 
		FastScanner I = new FastScanner(); //Input
		OutPut O = new OutPut(); //Output
		long Q = I.nextLong();
		long H = I.nextLong();
		long S = I.nextLong();
		long D = I.nextLong();
		long N = I.nextLong();
		Q*=8;
		H*=4;
		S*=2;
		long ans = 0;
		if (N%2==0) {
			long[] a = {Q,H,S,D};
			Arrays.sort(a);
			long cheap = a[0];
			N/=2; //Originally scaled per two liters to avoid precision errors
			ans=cheap*N;
		}else {
			if (D<S&&D<Q&&D<H) {
				//O.pln("HERE");
				long[] a = {H,S,Q};
				Arrays.sort(a);
				N/=2;
				ans += N*D;
				ans+=a[0]/2; //Have to also incorporate second cheapest (/2 because we need to 
				//re-scale to cost per single liter)
			}else { //If double isn't cheapest ---> Don't worry!!
				long[] a = {Q,H,S,D};
				Arrays.sort(a);
				long cheap = a[0];
				cheap/=2;
				ans=cheap*N;
			}
		}
		O.pln(ans);
	}
	public static long ceil(long num, long den) {long ans = num/den; if (num%den!=0) 
	ans++; return ans;}
	public static long GCD(long a, long b) {
		if (a==0||b==0) return Math.max(a,b);
		return GCD(Math.min(a, b),Math.max(a, b)%Math.min(a, b));
	}
	public static long FastExp(long base, long exp, long mod) {
		long ans=1;
		while (exp>0) {
			if (exp%2==1) ans*=base;
			exp/=2;
			base*=base;
			base%=mod;
			ans%=mod;
		}
		return ans;
	}
	public static long ModInv(long num,long mod) {return FastExp(num,mod-2,mod);}
	static class FastScanner {
		BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
		StringTokenizer st=new StringTokenizer("");
		String next() {
			while (!st.hasMoreTokens())
				try {
					st=new StringTokenizer(br.readLine());
				} catch (IOException e) {
					e.printStackTrace();
				}
			return st.nextToken();
		}
		int nextInt() {return Integer.parseInt(next());}
		long nextLong() {return Long.parseLong(next());};
	}
	static class OutPut{
		PrintWriter w = new PrintWriter(System.out);
		void pln(int x) {w.println(x);w.flush();}
		void pln(long x) {w.println(x);w.flush();}
		void pln(String x) {w.println(x);w.flush();}
		void pln(char x) {w.println(x);w.flush();}
		void pln(StringBuilder x) {w.println(x);w.flush();}
		void p(int x) {w.print(x);w.flush();}
		void p(long x) {w.print(x);w.flush();}
		void p(String x) {w.print(x);w.flush();}
		void p(char x) {w.print(x);w.flush();}
		void p(StringBuilder x) {w.print(x);w.flush();}
	}
}

Measured memory_bytes: 25636
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int a,b;
	cin>>a>>b;
	int p1,p2;
	p1=floor(float(100*a)/8);
	p2=floor(float(b)*10);
	//cout<<"p1="<<p1<<"and "<<"p2="<<p2<<endl;
	int flag=0;
	int i;
	for(i=min(p1,p2)-1;i<=max(p1,p2)+1;i++)
	{
		if(floor(0.08*i)==a and floor(0.1*i)==b)
		{
			flag=1;
			break;
		}
	}
	if(flag==1)
		cout<<i<<endl;
	else
		cout<<"-1"<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <bitset>
#include <algorithm>
#pragma GCC optimize("O3")
#pragma GCC target("avx")
#define ll long long
#define INF 1000000005
#define MOD 1000000007
#define EPS 1e-10
#define rep(i,n) for(int i=0;i<(int)(n);++i)
#define rrep(i,n) for(int i=(int)(n)-1;i>=0;--i)
#define srep(i,s,t) for(int i=(int)(s);i<(int)(t);++i)
#define each(a,b) for(auto& (a): (b))
#define all(v) (v).begin(),(v).end()
#define len(v) (int)(v).size()
#define zip(v) sort(all(v)),v.erase(unique(all(v)),v.end())
#define cmx(x,y) x=max(x,y)
#define cmn(x,y) x=min(x,y)
#define fi first
#define se second
#define pb push_back
#define show(x) cout<<#x<<" = "<<(x)<<endl
#define spair(p) cout<<#p<<": "<<p.fi<<" "<<p.se<<endl
#define sar(a,n) cout<<#a<<":";rep(pachico,n)cout<<" "<<a[pachico];cout<<endl
#define svec(v) cout<<#v<<":";rep(pachico,v.size())cout<<" "<<v[pachico];cout<<endl
#define svecp(v) cout<<#v<<":";each(pachico,v)cout<<" {"<<pachico.first<<":"<<pachico.second<<"}";cout<<endl
#define sset(s) cout<<#s<<":";each(pachico,s)cout<<" "<<pachico;cout<<endl
#define smap(m) cout<<#m<<":";each(pachico,m)cout<<" {"<<pachico.first<<":"<<pachico.second<<"}";cout<<endl

using namespace std;

const int MAX_N = 5005;

#define getchar getchar_unlocked

inline int in() {
    int n = 0; short c;
    while ((c = getchar()) >= '0') n = n * 10 + c - '0';
    return n;
}

int a[MAX_N], sm[MAX_N];

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n = in(), K = in(), id = 0;
    rep(i,n){
        a[id] = in();
        if(a[id] < K-1) id++;
    }
    n = id;
    sort(a, a+n, greater<int>());
    rrep(i,n){
        sm[i] = sm[i+1] + a[i];
    }
    int ans = 0;
    bitset<MAX_N> dp;
    dp[0] = true;
    rep(i,n){
        if(K+a[i]-sm[i] > 0){
            bool flag = true;
            srep(j,max(0, K-sm[i]),K+a[i]-sm[i]){
                if(dp[j]){
                    flag = false;
                    break;
                }
            }
            ans += flag;
        }
        dp |= (dp << a[i]);
    }
    cout << ans << "\n";
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
#include <stack>
#include <queue>
#include <functional>
#include <algorithm>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <vector>
#include <array>
#include <tuple>
#include <utility>
#include <numeric>
#include <iomanip>
#include <cctype>
#include <cmath>
#include <assert.h>
#include <cstdlib>
#include <list>
using namespace std;

using ll = long long;
using ull = unsigned long long;
using PII = pair<int, int>;
using PLL = pair<ll, ll>;

template<typename T1, typename T2> ostream& operator<<(ostream& s, const pair<T1, T2>& p) {
    return s << "(" << p.first << ", " << p.second << ")";
}
template<typename T> ostream& operator<<(ostream& s, const vector<T>& v) {
    s << "[";
    for (int i = 0; i < v.size(); i++) s << (i == 0 ? "" : ", ") << v[i];
    s << "]";
    return s;
}

#define ALL(a) (a).begin(), (a).end()

int main() {
    int r, g, b;
    cin >> r >> g >> b;

    if ((r * 100 + g * 10 + b) % 4 == 0) cout << "YES" << endl;
    else cout << "NO" << endl;

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp>     // Including tree_order_statistics_node_update
using namespace __gnu_pbds;
using namespace std;
/*
         ########     ########   ########   #########   ##       #######   ##       #######
         #      #     #      #   #      #       #       # #      #     #   # #      #     #
         #      #     #      #   #      #       #       #  #     #     #   #  #     #     #
         ########     #      #   #      #       #       #   #    #     #   #   #    #     #
         ###          #      #   #      #       #       #    #   #######   #    #   #######
         #  #         #      #   #      #       #       #   #    #     #   #   #    #     #
         #   #        #      #   #      #       #       #  #     #     #   #  #     #     #
         #    #       #      #   #      #       #       # #      #     #   # #      #     #
         #     #      ########   ########       #       ##       #     #   ##       #     #     
*/

#define rep(i, a, b) for (__typeof((b)) i = (a); i < (b); i++)
#define nrep(i, a, b) for (__typeof((b)) i = (a); i > (b); i--)
#define all(a) (a).begin(), (a).end()
#define ff first
#define ss second
#define ppi pair<int, int>
#define pppi pair<ppi, int>
#define vi vector<int>
#define vii vector<ppi>
#define viii vector<pppi>
#define vs vector<string>
#define pb push_back
#define bitcount __builtin_popcount //count no's of ones in a set bit
#define prq priority_queue
#define mp make_pair
#define mem(x, val) memset((x), (val), sizeof(x));
#define sz(x) (int)x.size()
#define M_PI 3.14159265358979323846
#define rootdada                      \
    ios_base::sync_with_stdio(false); \
    cin.tie(0);                       \
    cout.tie(0);
#define test  \
    int t;    \
    cin >> t; \
    while (t--)
#define debug(a)          \
    cerr << #a << ": ";   \
    for (auto i : a)      \
        cerr << i << " "; \
    cerr << '\n';
#define trace(a) cerr << #a << ": " << a << "\n"
#define print(ar, n)            \
    for (int u = 0; u < n; u++) \
    {                           \
        cout << ar[u] << " ";   \
    }                           \
    cout << endl;
#define int long long
#define M 1000000007
#define ordered_set tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update>
signed main()
{
    rootdada;

    int x, n;
    cin >> x >> n;
    int a[n];
    map<int, int> m;
    rep(i, 0, n)
    {
        cin >> a[i];
        m[a[i]]++;
    }
    int mini = INT_MAX, z;
    for (int i = 101; i >= 0; i--)
    {
        if (!m[i])
        {
            if (mini >= abs(x - i))
            {
                mini = abs(x - i);
                z = i;
            }
        }
    }
    cout << z << endl;
}

Measured memory_bytes: 3664
s = input()
ans,f,r,l = ["0"]*len(s),0,0,0
for i in range(len(s)):
    if 1-f and s[i]=="R": r+=1
    elif 1-f: f,l,num = 1,1,i
    elif f and s[i]=="L": l+=1
    else: ans[num-1],ans[num],r,l,f = str((r+1)//2+l//2),str(r//2+(l+1)//2),1,0,0
ans[num-1],ans[num] = str((r+1)//2+l//2),str(r//2+(l+1)//2)
print(" ".join(ans))

Measured memory_bytes: 10100
#!/usr/bin/ruby
M=10**9+7
def d(x,y) x.zip(y).reduce(0){|s,(a,b)|s+a*b} end
def mul(x,y)
	y=y.transpose
	[[d(x[0],y[0])%M,d(x[0],y[1])%M],[d(x[1],y[0])%M,d(x[1],y[1])%M]]
end
def pow(x,y)
	z=1
	while y>0
		z=z*x%M if y%2>0
		x=x*x%M
		y/=2
	end
	z
end
h,w,k=gets.split.map(&:to_i)
k-=1
m=$<.map{|e|e.chomp.chars};mt=m.transpose
c=m.count{|s|s[0]=='#'&&s[-1]=='#'}
d=mt.count{|s|s[0]=='#'&&s[-1]=='#'}
if d>0
	(p 1;exit) if c>0
	c,d=d,c
	m,mt=mt,m
	h,w=w,h
end
a=b=0
m.each{|s|w.times{|i|
	a+=1 if s[i]=='#'
	b+=1 if i<w-1&&s[i]=='#'&&s[i+1]=='#'
}}
if c==0&&d==0
	p pow(a,k)
	exit
end
 
e=[[1,0],[0,1]]
m=[[a,-b],[0,c]]
while k>0
	e=mul(e,m) if k%2>0
	m=mul(m,m)
	k/=2
end
p (e[0][0]+e[0][1])%M

Measured memory_bytes: 89212
X=$stdin.read.chomp.to_i
s = X ** (1/5.to_f).floor
(-120..).each do |a|
  a5 = a ** 5
  d = (X - a5)
  b = (d.abs ** (1 / 5.to_f)).round * (-1) * (if d == 0 then 1 else d/d end)
  b5 = b**5
  if a5 - b5 == X
    puts "#{a} #{b}"
    break
  end
end

Measured memory_bytes: 14724
from sys import setrecursionlimit
setrecursionlimit(10 ** 9)

n = int(input())
U = [[int(i) for i in input().split()] for j in range(n - 1)]

E = [[] for i in range(n + 1)]

for u, v, w in U:
    E[u].append((v, w))
    E[v].append((u, w))

visited = [False] * (n + 1)
color = [0] * (n + 1)

def dfs(v, w):
    if visited[v]:
        return None
    visited[v] = True
    color[v] = 1 if w % 2 == 1 else 0
    for u, weight in E[v]:
        dfs(u, w + weight)

    return None

dfs(1, 0)

for c in color[1:]:
    print(c)

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

int main(){


  int x,y;



  while(1){

   
 
    cin >> x >> y;


 if(x == 0 && y == 0) 
   break;
   

 if(x >= y){
   cout << y <<" "<< x << "\n" ;
 

 } if(x < y) {
   cout << x <<" "<< y << "\n" ;


 }


  } 
 

  return 0;

  
}

Measured memory_bytes: 1160