akhauriyash/Code-Regression huggingface dataset:
# -*- coding: utf-8 -*-

n,m=list(map(int, input().split()))
switches=[]
for i in range(m):
    l1=list(map(int, input().split()))[1:]
    s=0
    for i in l1:
        s+=1<<(i-1)
    switches.append(s)
remainders=list(map(int, input().split()))
answer=0
for i in range(1<<n):
    is_all_lighted=True
    for j,s in enumerate(switches):
        if bin(s&i).count("1")%2 != remainders[j]:
            is_all_lighted = False
    if is_all_lighted == True:
        answer+=1
print(answer)

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

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

const ll mod = 1e9+7;

int main(){
	string s;
	cin >> s;
	ll r_cnt, b_cnt;
	r_cnt = 0; b_cnt = 0;
	REP(i, s.length()){
		if (s[i] == '0'){r_cnt+=1;}
		else {b_cnt += 1;}
	}
	cout << 2*min(r_cnt, b_cnt)%mod << endl;
}

Measured memory_bytes: 512
import std.stdio, std.conv, std.functional, std.string;
import std.algorithm, std.array, std.container, std.range, std.typecons;
import std.bigint, std.numeric, std.math, std.random;
import core.bitop;

string FMT_F = "%.10f";

static File _f;
void file_io(string fn) { _f = File(fn, "r"); }
static string[] s_rd;
T _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }
T _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }
T[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }
T[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }
T RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }
T[] RDA(T = long)(T fix = 0) { if (_f.isOpen)  return _RDA!T(_f, fix); else return _RDA!T(fix); }

size_t[] MAKE_IDX(alias less = "a < b", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}
size_t MIN_POS(alias less = "a < b", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }

void chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(T)(ref T x, T y) { x = max(x, y); }
bool inside(T)(T x, T b, T e) { return x >= b && x < e; }
T lcm(T)(T x, T y) { return x * (y / gcd(x, y)); }

//long mod = 10^^9 + 7;
long mod = 998_244_353;
//long mod = 1_000_003;
void moda(T)(ref T x, T y) { x = (x + y) % mod; }
void mods(T)(ref T x, T y) { x = ((x + mod) - (y % mod)) % mod; }
void modm(T)(ref T x, T y) { x = (x * y) % mod; }
void modpow(T)(ref T x, T y) { if (!y) { x = 1; return; } auto t = x; x.modpow(y>>1); x.modm(x); if (y&1) x.modm(t); }
void modd(T)(ref T x, T y) { y.modpow(mod - 2); x.modm(y); }

void main()
{
	auto N = RD;
	auto A = RDA;

	int[long] cnt;
	foreach (i; 0..N)
	{
		++cnt[A[i]];
	}

	long ans;
	foreach (i; 0..N)
	{
		bool ok = true;
		for (long j = 1; j*j <= A[i]; ++j)
		{
			if (A[i] % j) continue;
			auto k = A[i] / j;
			if (j == A[i])
			{
				if (cnt.get(j, 0) >= 2)
				{
					ok = false;
					break;
				}
			}
			else
			{
				if (cnt.get(j, 0))
				{
					ok = false;
					break;
				}
			}
			if (k == A[i])
			{
				if (cnt.get(k, 0) >= 2)
				{
					ok = false;
					break;
				}
			}
			else
			{
				if (cnt.get(k, 0))
				{
					ok = false;
					break;
				}
			}
		}
		if (ok)
			++ans;
	}

	writeln(ans);
	stdout.flush;
	debug readln;
}


Measured memory_bytes: 23660
def main():
    n,x,m = map(int,input().split())
    R = [x]
    g = set([x])
    for i in range(1,min(m,n)):
        x = x**2 % m
        if not x in g:
            R.append(x)
            g.add(x)
        else:
            break
    
    R_ac = [0]*(len(R)+1)
    for i in range(len(R)):
        R_ac[i+1] = R_ac[i] + R[i]

    j = R.index(x)
    ct = n
    
    ans = R_ac[j]
    ct-=j

    q = ct//(len(R)-j)
    ans+= q*(R_ac[-1]-R_ac[j]) 
    ct-=q*(len(R)-j)

    ans+= R_ac[j+ct] - R_ac[j]

    print(ans)
main()

Measured memory_bytes: 77136
#include<bits/stdc++.h>
    #define ll long long int
    using namespace std;
    int main()
    {
    int a[100000][3]={0};
    int dp[100000][3]={0};
    ll n;
    cin>>n;
    for(int i=0;i<n;i++){
        cin>>a[i][0]>>a[i][1]>>a[i][2];
    }

    dp[0][0]=a[0][0];dp[0][1]=a[0][1];dp[0][2]=a[0][2];
    for(int i=1;i<n;i++){
        dp[i][0]=max(a[i][0]+dp[i-1][1],a[i][0]+dp[i-1][2]);
        dp[i][1]=max(a[i][1]+dp[i-1][0],a[i][1]+dp[i-1][2]);
        dp[i][2]=max(a[i][2]+dp[i-1][1],a[i][2]+dp[i-1][0]);
    }

    cout<<max(max(dp[n-1][0],dp[n-1][1]),dp[n-1][2]);
    }


Measured memory_bytes: 2560
#include<bits/stdc++.h>
using namespace std;
#define int long long

signed main(){

  int m,k; cin >> m >> k;

if(m <= 1){
  vector<int> v;
  for(int i = 0; i < pow(2,m); i++){
    for(int j = 0; j < 2; j++){
      v.push_back(i);
    }
  }

  do{
    bool judge = true;
    vector<bool> used(pow(2,m),false);
    for(int i = 0; i < v.size(); i++){
      if(used[v[i]]) continue;
      int res = v[i],j = i+1;
      while(v[i] != v[j]){
        res ^= v[j];
        j++;
      }
      res ^= v[j];
      used[v[i]] = true;
      if(res != k) judge = false;
    }

    if(judge){
      for(int k = 0; k < v.size(); k++){
        cout << v[k] << " ";
      }
      cout << endl;
      return 0;
    }
  }while(next_permutation(v.begin(),v.end()));
  cout << -1 << endl;
}
else {
  if(k >= pow(2,m)) cout << -1 << endl;
  else {
    for(int i = 0; i < pow(2,m); i++){
      if(i == k) continue;
      cout << i << " ";
    }
    cout << k << " ";
    for(int i = pow(2,m)-1; i >= 0; i--){
      if(i == k) continue;
      cout << i << " ";
    }
    cout << k << endl;
  }
}

  return 0;
}


Measured memory_bytes: 1792
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.ArrayList;

public class Main {
	public static void main(String[] args)throws Exception{
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String line = br.readLine();
        int n = Integer.parseInt(line);
        String line2 = br.readLine();
        String[] str = line2.split(" ");
        int[] n_array = new int[n];
        for(int i=0;i<n;i++)n_array[i]=Integer.parseInt(str[i]);
        int q = Integer.parseInt(br.readLine());
        String line3 = br.readLine();
        String[] str2 = line3.split(" ");
        ArrayList<Integer> q_array = new ArrayList<Integer>();
        for(int i=0;i<q;i++)q_array.add(Integer.parseInt(str2[i]));
        int cnt=0;
        for(int i=0;i<n;i++){
        	for(int j=0;j<q_array.size();j++){
        		if(n_array[i]==q_array.get(j)){
        			q_array.remove(j);
        			cnt++;
        		}
        	}
        }
        System.out.println(cnt);        
	}
}

Measured memory_bytes: 27276
#include<algorithm>
#include<bitset>
#include<cmath>
#include<complex>
#include<deque>
#include<functional>
#include<iomanip>
#include<iostream>
#include<iterator>
#include<map>
#include<numeric>
#include<queue>
#include<set>
#include<stack>
#include<string>
#include<unordered_map>
#include<unordered_set>
#include<utility>
#include<vector>
using namespace std;
typedef long long ll;
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=(ll)(b);i--)
#define ALL(x) (x).begin(),(x).end()
#define SIZE(x) ((ll)(x).size())
#define MAX(x) *max_element(ALL(x))
#define MIN(x) *min_element(ALL(x))
#define D()
#define INF 1000000000000
#define MOD 10000007
#define MAXR 100000
#define PB push_back
#define MP make_pair
#define F first
#define S second
#define INITA(a,i,j,v) for(ll k=i;k<=j;k++){a[k]=v;}
int main() {
    ll n; cin >> n;
    ll num_odd = 0;
    ll num_even_wo_four = 0; // 4の倍数以外の偶数
    ll num_four = 0; // 4の倍数
    REP(i, n) {
        ll tmp;
        cin >> tmp;
        if (tmp % 4 == 0) {
            num_four++;
        } else if (tmp % 2 == 0) {
            num_even_wo_four++;
        } else {
            num_odd++;
        }
    }

    if (num_even_wo_four == 0) {
        if (num_odd <= num_four + 1) {
            cout << "Yes" << endl;
        } else {
            cout << "No" << endl;
        }
    } else {
        if (num_odd <= num_four) {
            cout << "Yes" << endl;
        } else {
            cout << "No" << endl;
        }
    }

    return 0;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main() {
    int n, k; cin >> n >> k;
    int a[100] = {0};
    int cnt = 0;
    while (1) {
        for (int i = 0; i < k; i++) {
            a[i]++;
            cnt++;
            if (cnt == n) goto end;
        }
    }
end:
    int min = 1000000, max = 0;
    for (int i = 0; i < k; i++) {
        min = (min > a[i]) ? a[i] : min;
        max = (max < a[i]) ? a[i] : max;
    }
    cout << max - min << endl;
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
 
int IsPrime(int n){
    int i;
    if(n==1) return 0;
    if(n==2)return 1;
    else if(n%2==0)return 0;
    for(i=3;i*i<=n;i+=2)if(n%i==0)return 0;
    return 1;
}
 
int main(void){
    int n , i , count;
    int dp[1000000] = {0};

    for(i=1;i<1000000;i++) {
       if(IsPrime(i)) dp[i] = 1;
    }

    while(scanf("%d" , &n)!=EOF){
        count = 0;
        for(i=1;i<=n;i++)if(dp[i]==1)count++;
        printf("%d\n" , count);
    }
    return 0;
}

Measured memory_bytes: 4508
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

class Main {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		try {
			String str = br.readLine();
			String result = "";
			for(int i=str.length()-1;i >= 0;i--){
				result += str.charAt(i);
			}
			System.out.println(result);
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
	}

}

Measured memory_bytes: 9360
#include <iostream>

using namespace std;

int main()
{
    int N, h, n, w;

    cin >> N;

    for(h=3*N/4; h>=1 ; --h) {
        for(n=2*N*h/(4*h-N); n>=h; --n) {
            for(w=n; w<=3500; ++w) {
                if(4*h*n*w==N*(h*n+n*w+w*h)) {
                    cout << h << " " << n << " " << w << endl;
                    return 0;
                }
            }
        }
    }
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
using namespace std;
int main() {
 int a;
 char x[100010];
  cin >> a;
  for (int i = 0; i < a; ++i) {cin >> x[i];}
 int ans = 1;
 for (int j = 0; j < a-1; ++j) {{
 		if (x[j+1] - x[j] != 0) {ans += 1;} 
 	}
 }
  cout << ans;
  return 0;
}

Measured memory_bytes: 384
#include <iostream>

using namespace std;

int main()
{
	long long A, B, K;
	cin >> A >> B >> K;

	for (int i = 0; i < K; ++i) {
		if (i % 2 == 0) {
			B += A / 2;
			A /= 2;
		}
		else {
			A += B / 2;
			B /= 2;
		}
	}
	cout << A << " " << B << endl;
}


Measured memory_bytes: 256
n, m = map(int, input().split())
SC = [list(map(int, input().split())) for _ in range(m)]
for i in range(1000):
  t = str(i)
  l = len(t)
  if l != n:
    continue
  for s, c in SC:
    if s > l or t[s-1] != str(c):
      break
  else:
    print(i)
    break
else:
  print(-1)

Measured memory_bytes: 3064
// -*- coding:utf-8-unix -*-

use proconio::input;

fn main() {
    input! {
        s: String,
        t: String
    }
    // sもtも一文字以上入るらしいのでvalidationしない
    // println!("{} {}", s, &t[0..t.len()-1]);

    if s == &t[0..t.len()-1] {
        println!("Yes");
    } else {
        println!("No");
    }
    
}


Measured memory_bytes: 2112
#include <bits/stdc++.h>
using namespace std;
#include <math.h>
#include <iomanip>
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

const int mod=1e9+7;
const int INF=1001001001;

int main() {
  int N,K;
  cin>>N>>K;
  vector<int>A(N);
  for(int i=0;i<N;i++){
    cin>>A[i];
  }
  int roop=K;
  while(roop--){
    vector<int>IMOS(N+1);
    for(int j=0;j<N;j++){
        int l=max(0,j-A[j]);
        int r=min(N,j+A[j]+1);
        IMOS[l]++;IMOS[r]--;
    }
    for(int j=0;j<N;j++){
        IMOS[j+1]+=IMOS[j];
    }
    IMOS.pop_back();
    if(A==IMOS){break;}
    else{A=IMOS;}
  }
  for(int i=0;i<N;i++){
    cout<<A[i]<<endl;
  }
  return 0;  
}

Measured memory_bytes: 4844
#define _USE_MATH_DEFINES

#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <cmath>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>

using namespace std;

#define MAX_V 200000

typedef pair<long long int, long long int> P;
long long int INF = 1e18;

vector<P> v;

bool find(int cnt){
	if(cnt == 8){
		return true;
	}
	for(int x = 0; x < 8; x++){
		for(int y = 0; y < 8; y++){
			bool flag = true;
			for(int i = 0; i < v.size(); i++){
				if(x == v[i].first || y == v[i].second || x + y == v[i].first + v[i].second || x - y == v[i].first - v[i].second){
					flag = false;
					break;
				}
			}
			if(flag){
				P p;
				p.first = x;
				p.second = y;
				v.push_back(p);
				bool ret = find(cnt + 1);
				if(ret){
					return true;
				}
				v.pop_back();
			}
		}
	}
	return false;
}

int main(){
	
	int num;
	cin >> num;
	
	for(int i = 0; i < num; i++){
		P p;
		cin >> p.first >> p.second;
		v.push_back(p);
	}
	
	find(v.size());
	
	string str[8] = {
		"........",
		"........",
		"........",
		"........",
		"........",
		"........",
		"........",
		"........"
	};
	for(int i = 0; i < v.size(); i++){
		str[v[i].first][v[i].second] = 'Q';
	}
	
	for(int i = 0; i < 8; i++){
		cout << str[i] << endl;
	}
	
	return 0;
}


Measured memory_bytes: 3224
#include<bits/stdc++.h>
#define vi vector<int>
#define vvi vector<vi>
#define forr(i,k,n) for(int i=k; i<n; i++)
#define iforr(i,k,n) for(int i=n-1; i>=k; i--)
#define rep(i,n) forr(i,0,n)
#define irep(i,n) iforr(i,0,n)
#define aut(i,arr) for(auto& i:arr)
#define all(arr) arr.begin(), arr.end()
#define pb push_back
#define pii pair<int,int>
#define vpii vector<pii>
#define f first
#define db double
#define s second
#define ll long long 
#define ull unsigned long long
#define E '\n'
#define lmax 9223372036854775807;
#define MOD 1000000007
using namespace std;

void Fast_IO() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    #ifndef ONLINE_JUDGE
    freopen("code.in","r",stdin);
    freopen("code.out","w",stdout);
    #endif
}
vi v;
vvi ed;
void dfs(int i)
{
	v[i]=1;
	aut(j,ed[i])
		if(!v[j])
			dfs(j);
}
int fun(int i)
{
	int ans=0;
	aut(j,ed[i])
		if(v[j]!=-1)
			ans=max(ans,v[j]);
		else
			ans=max(ans,fun(j));
	v[i]=ans+1;
	return v[i];
}
int main()
{
	//Fast_IO();
	int t;
	//cin>>t;
	t=1;
	while(t--)
	{
		int n;
		cin>>n;
		int m;
		cin>>m;
		ed.resize(n);
		v.resize(n,-1);
		rep(i,m){
			int x;
			int y;
			cin>>x>>y;
			x--;y--;
			ed[x].pb(y);
		}
		int ans=-1;
		rep(i,n)
			if(v[i]==-1)
				ans=max(ans,fun(i));
		cout<<ans-1;
		cout<<E;
	}
	return 0;
}

Measured memory_bytes: 8832
/* BISMILLAHIR RAHMANIR RAHIM */
#include<bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define mod 1000000007
#define pb push_back
#define IOS ios_base::sync_with_stdio(0); cin.tie(0);
using namespace std;
int main() {
string s;
cin>>s;
if(s[0]-toupper(s[0])==0)
cout<<"A\n";
else
cout<<"a\n";
    return 0;
}

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

int main() {
	// your code goes here
	int N;
	scanf("%d",&N);
	unsigned long long power=1;
	long mod = pow(10,9)+7;
	for(int i=1;i<=N;i++) power=power*i%mod;
	printf("%llu",power);
	return 0;
}

Measured memory_bytes: 256
/**
 *    author:  tourist
 *    created: 03.11.2019 18:32:17       
**/
#include <bits/stdc++.h>

using namespace std;

template <typename A, typename B>
string to_string(pair<A, B> p);

template <typename A, typename B, typename C>
string to_string(tuple<A, B, C> p);

template <typename A, typename B, typename C, typename D>
string to_string(tuple<A, B, C, D> p);

string to_string(const string& s) {
  return '"' + s + '"';
}

string to_string(const char* s) {
  return to_string((string) s);
}

string to_string(bool b) {
  return (b ? "true" : "false");
}

string to_string(vector<bool> v) {
  bool first = true;
  string res = "{";
  for (int i = 0; i < static_cast<int>(v.size()); i++) {
    if (!first) {
      res += ", ";
    }
    first = false;
    res += to_string(v[i]);
  }
  res += "}";
  return res;
}

template <size_t N>
string to_string(bitset<N> v) {
  string res = "";
  for (size_t i = 0; i < N; i++) {
    res += static_cast<char>('0' + v[i]);
  }
  return res;
}

template <typename A>
string to_string(A v) {
  bool first = true;
  string res = "{";
  for (const auto &x : v) {
    if (!first) {
      res += ", ";
    }
    first = false;
    res += to_string(x);
  }
  res += "}";
  return res;
}

template <typename A, typename B>
string to_string(pair<A, B> p) {
  return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}

template <typename A, typename B, typename C>
string to_string(tuple<A, B, C> p) {
  return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " + to_string(get<2>(p)) + ")";
}

template <typename A, typename B, typename C, typename D>
string to_string(tuple<A, B, C, D> p) {
  return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " + to_string(get<2>(p)) + ", " + to_string(get<3>(p)) + ")";
}

void debug_out() { cerr << endl; }

template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cerr << " " << to_string(H);
  debug_out(T...);
}

#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  vector<int> a(n), b(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i] >> b[i];
  }
  int min_b = *min_element(b.begin(), b.end());
  int max_a = *max_element(a.begin(), a.end());
  int ans = 0;
  vector<pair<int, int>> p(n);
  for (int i = 0; i < n; i++) {
    p[i] = make_pair(min_b - a[i] + 1, b[i] - max_a + 1);
  }
  sort(p.begin(), p.end());
  debug(p);
  int m2 = (int) 1.01e9;
  for (int i = 0; i < n - 1; i++) {
    m2 = min(m2, p[i].second);
    ans = max(ans, p[i + 1].first + m2);
  }
  for (int i = 0; i < n; i++) {
    int cur = b[i] - a[i] + 1;
    cur += max(0, min_b - max_a + 1);
    ans = max(ans, cur);
  }
  cout << ans << '\n';
  return 0;
}


Measured memory_bytes: 1792
#include <iostream>
#include <set>
#include <map>
#include <cmath>
#include <vector>
#include <string>
#include <algorithm>
#include <iomanip>
#include <queue>
#include <deque>
#include <stack>
#include <climits>
#include <math.h>
#include <cassert>
#include <unordered_map>
using namespace std;
#pragma warning(disable : 4996)
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;



int main() {
#ifdef _DEBUG
	freopen("input1.txt", "r", stdin);
	freopen("output2.txt", "w", stdout);
#endif
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	ll n;
	string s;
	cin >> n >> s;
	ll r = 0, g = 0, b = 0;
	for (int i = 0; i < n; i++) {
		if (s[i] == 'R')r++;
		if (s[i] == 'G')g++;
		if (s[i] == 'B')b++;
	}
	ll ans = r * g * b;
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < i; j++) {
			int add = i - j;
			if (i + add < n && s[i] != s[j] && s[j] != s[i + add] && s[i + add] != s[i])ans--;
		}
	}
	cout << ans;
}

Measured memory_bytes: 3656
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <unordered_map>
#include <queue>
#include <algorithm>

#include <bits/stdc++.h>
#include <cmath>
#include <limits>

using namespace std;
typedef long long LL;

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

	LL N, A, B;
	cin >> N >> A >> B;

	LL mi = A*(N-1) + B;
	LL ma = B*(N-1) + A;
	LL ans = ma - mi + 1;
	printf("%lld\n", max(ans, 0LL));
	return 0;
}

Measured memory_bytes: 3784
#include<stdio.h>
#include<vector>
using namespace std;

struct Node{
  int parent;
  int root;
  int internal;
  vector<int> child;
};

Node T[100000];

int depth(int m){
  int d = 0;
  while(T[m].parent != -1){
    m = T[m].parent;
    d++;
  }

  return d;
}
  

int main() {
  int i,j,n,id,k[100000],s,num;

  scanf("%d",&n);

  for(i=0;i<n;i++) {
    T[i].parent = -1;
    T[i].root = 1;
    T[i].internal =1;
  }
    
  for(i=0;i<n;i++){
    scanf("%d",&id);
    scanf("%d",&k[id]);
    T[id].child.resize(k[id]);    
    for(j=0;j<k[id];j++){
      if(i==0){
	T[id].parent = -1;
	T[id].root = 1;
      }
      else {
	T[id].internal =1;
      }
      
      scanf("%d",&s);
      T[s].parent = id;
      T[s].root = 0;
      T[s].internal = 1;
      T[id].child[j] = s;      
    }
  }
  for(i=0;i<n;i++){
    printf("node %d: ",i);
    printf("parent = %d, ",T[i].parent);
    printf("depth = %d, ",depth(i));
    if(T[i].root) {
      printf("root, [");
      for(j=0;j<k[i];j++){
	if(j==0) printf("%d",T[i].child[j]);
	else printf(", %d",T[i].child[j]);
      }
      printf("]\n");
    }
    else if(T[i].internal&&k[i]){
      printf("internal node, [");
      for(j=0;j<k[i];j++){
	if(j==0) printf("%d",T[i].child[j]);
	else printf(", %d",T[i].child[j]);
      }
      printf("]\n");
    }
    else printf("leaf, []\n");
  
  }

  return 0;
}
      
      
	



Measured memory_bytes: 7356
n = int(input())
s = input()

def parse_ox(c):
    if c == "o":
        return 0
    elif c == "x":
        return 1

def select_good_c(past, ox):
    if past == "SS":
        return "S" if ox == "o" else "W"
    elif past == "SW":
        return "W" if ox == "o" else "S"
    elif past == "WS":
        return "W" if ox == "o" else "S"
    elif past == "WW":
        return "S" if ox == "o" else "W"

val = ""
start = [["SSS", "WSW", "WWS", "SWW"], ["SSW", "WSS", "SWS", "WWW"]] 
for val in start[parse_ox(s[1])]:
    for i in range(2,n):
        val += select_good_c(val[-2:], s[i])
    if val[0] == val[-1] and select_good_c(val[-2:], s[0]) == val[1]:
        print(val[:-1])
        exit()
print(-1)

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

unsigned long long Kaijo(int n) {
	long long int m;
	if (n == 0)
		return 1;
	m = Kaijo(n - 1);
	return m*n;
}

int main() {
	int n;
	cin >> n;
	cout << Kaijo(n) << endl;
	return 0;
}

Measured memory_bytes: 3068
#include<iostream>
#include<string.h>
#include<vector>
#include<list>
#include<stdio.h>
#include<math.h>
#include<iomanip>
#include<map>
#include<stack>
#include<queue>
#define range(i,a,b) for(int i = (a); i < (b); i++)
#define rep(i,b) range(i,0,b)
#define debug(x) cout << "debug " << x << endl;
using namespace std;

int main(){
    int n;
    while(cin >> n){
        rep(i, 3){
            int inp;
            cin >> inp;
            n+= inp;
        }
        cout << n / 60 << endl << n % 60 << endl;
    }
}

Measured memory_bytes: 1160
/* B Maximum Heap */
#include<stdio.h>

int heap_size;

void maxHeapify(int A[],int i);
void buildMaxHeap(int A[]);
int left(int i);
int right(int i);

int main(){
  int i;
  
  scanf("%d",&heap_size);
  int A[heap_size+1];

  /* scan A[1...heap_size] */
  for(i=1;i<=heap_size;i++){
    scanf("%d",&A[i]);
  }
  
  buildMaxHeap(A);

  /* print*/
  for(i=1;i<=heap_size;i++){
    printf(" %d",A[i]);
  }
  printf("\n");
  return 0;
}

void maxHeapify(int A[],int i){
  int temp;
  int l,r,largest;
  l=left(i);
  r=right(i);

  if(l<=heap_size&&A[l]>A[i]){
    largest=l;
  }else{
    largest=i;
  }
  if(r<=heap_size&&A[r]>A[largest]){
    largest=r;
  }
  if(largest!=i){
    temp=A[i];
    A[i]=A[largest];
    A[largest]=temp;
    maxHeapify(A, largest);
  }
}

void buildMaxHeap(int A[]){
  int i;
  for(i=heap_size/2;i>=1;i--){
    maxHeapify(A,i);
  }
}

int left(int i){
  return 2*i;
}

int right(int i){
  return 2*i+1;
}

Measured memory_bytes: 2356
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;

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


void solve(std::vector<long long> A){
    ll sum = 0;
    rep(i,3){
        sum += A[i];
    }
    if(sum >= 22){
        cout << "bust" << endl;
    } else{
        cout << "win" << endl;
    }
}

int main(){
    std::vector<long long> A(3);
    for(int i = 0 ; i < 3 ; i++){
        scanf("%lld",&A[i]);
    }
    solve(std::move(A));
    return 0;
}


Measured memory_bytes: 3632
#include<bits/stdc++.h>
using namespace std;
int main() 
{
	int a,b,c,k;
	cin>>a>>b>>c>>k;
	if(k<=a)
      cout<<k<<endl;
  	else if(k<=a+b)
      cout<<a<<endl;
  	else 
      cout<<a- (k-a-b) <<endl;
  	return 0;
}

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

using namespace std;

typedef long long ll;

int main(){
  int N;
  cin >> N;
  while(N--){
    ll x[9];
    for(int i = 0 ; i < 9 ; i++){
      scanf("%llx",&x[i]);
    }
    ll K = 0LL;
    for(int i = 0 ; i < 32 ; i++){
      ll sum = 0LL;
      for(int j = 0 ; j < 8 ; j++){
        sum += (x[j]^K);
      }
      if((sum & (1LL<<i)) != ((x[8]^K) & (1LL<<i))){
        K |= (1LL<<i);
      }
    }
    printf("%llx\n",K);
  }
  return 0;
}

Measured memory_bytes: 1232
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,x,ma=0,sum=0;
    scanf("%d",&n);
    for(int i=1;i<=n;i++) scanf("%d",&x),sum+=x,ma=max(ma,x);
    if(sum-ma>ma) printf("Yes");
    else cout<<"No";
}


Measured memory_bytes: 256
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define rep(i,c) for (int i = 0; i < (int)c; i++)
#define all(v) v.begin(), v.end()
const int inf = 1000000000; //10^9
using ll = long long;
using P = pair<int,int>;
//加算代入演算子は+=！！！！！
//int 2^31 10^9まで
int main() {
    int sx, sy, tx, ty;
    cin >> sx >> sy >> tx >> ty;
    int dx = tx - sx;
    int dy = ty - sy;
    cout << string(dy, 'U') << string(dx, 'R');
    cout << string(dy, 'D') << string(dx, 'L');
    cout << 'L' << string(dy + 1, 'U') << string(dx + 1, 'R') << 'D';
    cout << 'R' << string(dy + 1, 'D') << string(dx + 1, 'L') << 'U';
    cout << endl;
    return 0;
}

Measured memory_bytes: 256
macro_rules! input {
    // ?
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };

    // stdinの生成 値の読み込み開始
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    // ?
    ($next:expr) => {};
    // ?
    ($next:expr, ) => {};

    // 変数名:型の読み込みの繰り返し
    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

macro_rules! read_value {
    // 値を読み込むベース 型,の繰り返し
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    // 配列の読み込み
    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    // 文字列Vec<char>の読み込み
    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    // usize1?の読み込み
    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    // 指定した型で読み込み
    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}
fn main() {
    input! {
        num: usize,
    };

    println!("{}", solve(num));
}

fn solve(num: usize) -> &'static str {
    if num < 1000 {
        return "ABC";
    } else {
        return "ABD";
    }
}
macro_rules! tests {
    ($($test_name:ident:$name:ident($( $args:expr ),*) => $expected:expr,)*) => {
        mod tests {
            $(
                #[test]
                fn $test_name() {
                    assert_eq!($expected,super::$name($($args),*));
                }
            )*
        }
    }
}


tests! {
    //テスト名:[引数]=>expected
    test1:solve(1000) => "ABD",
    test2:solve(999) => "ABC",
    test3:solve(1481) => "ABD",
}


Measured memory_bytes: 4352
#include<stdio.h>

#define N 2000001

int B[N], C[N];

void countingSort(int A[], int B[], int k, int num){
  int i, j;

  for(i = 0; i <= k; i++){
    C[i] = 0;
  }
  for(j = 1; j <= num; j++){
    C[A[j]]++;
  }   
  for(i = 1; i <= k; i++){
    C[i] = C[i] + C[i - 1];
  } 
  for(j = num; j >= 1; j--){
    B[C[A[j]]] = A[j];
    C[A[j]]--;
  }

  for(i = 1; i <= num; i++){
    printf("%d", B[i]);
    if(i != num) printf(" ");
  }
  printf("\n");

}

int main(){
  int A[N];
  int i, j, num, k = 0;


  scanf("%d", &num); 
  for(i = 1; i <= num; i++){
    scanf("%d", &A[i]);
    if(k < A[i]) k = A[i];
  }


  countingSort(A, B, k, num);

  return 0;
}



Measured memory_bytes: 17348
#include<bits/stdc++.h>
#define maxn 100005
#define ll long long 
using namespace std;
ll read(){
	ll x=0,c;while(!isdigit(c=getchar()));
	while(x=x*10+c-'0',isdigit(c=getchar()));
	return x;
}
int main(){
	ll a=read(),b=read(),c=read(),k=read();
	if(k%2==1)printf("%lld\n",b-a);else printf("%lld\n",a-b);
	return 0;
}

Measured memory_bytes: 256
k = gets.to_i
que = [1,2,3,4,5,6,7,8,9]
k.times do |i|
  s = que.shift
  if s % 10 != 0
    que << s*10 + s % 10 - 1
  end
  que << s * 10  + s % 10
  if s % 10 != 9
    que << s * 10 + s % 10  + 1
  end
  puts s if i == (k - 1)
end

Measured memory_bytes: 3964
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <unordered_map>
#include <vector>
#include <string.h>
#include <set>

using namespace std;

#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl

template<class T> void printvec(const vector<T>& v) {
  for (auto x : v) { cout << x << " "; }
  cout << endl;
}
template<class T> void printtree(const vector< vector<T> >& tree) {
  for (long long i = 0; i < tree.size(); ++i) {
    cout << i + 1 << ": "; printvec(tree[i]);
  }
}
template<class T, class U> void printmap(const map<T, U>& mp) {
  for (auto x : mp) { cout << x.first << "=>" << x.second << endl; }
}

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

#define rep(i, n) for(ll i = 0; i < n; ++i)
#define all(s) s.begin(), s.end()
#define sz(x) (ll)(x).size()
#define fr first
#define sc second
#define mp make_pair
#define pb push_back
#define eb emplace_back

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
typedef tuple<ll, ll, ll> triple;
typedef double D;
typedef vector<ll> vl;
typedef vector<P> vp;

const ll INF = 1e9;
const ll MOD = 1000000007;  // 1e9 + 7

const ll N = 1e5; // max value

int main(int argc, char** argv) {
  cin.tie(NULL);
  cout.tie(NULL);
  ios_base::sync_with_stdio(false);
  //cout << setprecision(10) << fixed;

  // Calculate primes by Shieve of Eratosthenes
  vector<bool> is_prime(N+1, true);
  is_prime[0] = false;
  is_prime[1] = false;
  for (int i = 2; i*i <= N; ++i) {
    if (is_prime[i]) {
      // Set false to all multiples
      for (int j = 2; j*i <= N; ++j) {
        is_prime[j*i] = false;
      }
    }
  }

  vector<ll> v; // similar nums
  rep(i,N+1) {
    if (is_prime[i] && is_prime[(i+1)/2]) {
      v.push_back(i);
    }
  }

  // printvec(v);

  ll q;
  cin >> q;
  rep(iter,q) {
    ll l,r;
    cin >> l >> r;
    ll cnt = upper_bound(all(v),r) - lower_bound(all(v),l);
    cout << cnt << endl;
  }
}


Measured memory_bytes: 640
from math import gcd
from functools import reduce
 
def gcd_list(numbers):
    return reduce(gcd, numbers)

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


X = [0]*N
Y = [0]*N
X[0] = A[0]
Y[-1] = A[-1]
ans = [0]*N
for i in range(1,N):
  X[i] = gcd(X[i-1],A[i])
  Y[N-i-1] = gcd(Y[N-i],A[N-i-1])
for i in range(1,N-1):
  ans[i] = gcd(X[i-1],Y[i+1])
ans[0],ans[-1] = gcd_list(A[1:]),gcd_list(A[:-1])
print(max(ans))

Measured memory_bytes: 25780
#include <cstdio>
#include <algorithm>

using namespace std;

#define MAX_N 100001


/* -----------------------------------------------------------------------------
	型とクラス定義
----------------------------------------------------------------------------- */

/* -----------------------------------------------------------------------------
	大域データ
----------------------------------------------------------------------------- */
int N;	

int main () {

	int ans = 0;

	// 個数と長さの読込み
	scanf("%d", &N);

	for(int i = 1; i < 10; i++) {
		if(N % i == 0 && N / i < 10) {
			ans = 1; break;
		}
	}
						
	printf("%s\n", ans == 1 ? "Yes" : "No");

	return 0;
}

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

int dy[] = {0,-1,0,1};
int dx[] = {-1,0,1,0};
signed
main(){
		int N;
		while(cin >> N && N!=0){
				vector<int> n(N), d(N);
				for(int i=1;i<N;i++){
						cin >> n[i] >> d[i];
				}
				//全探索
				//もし正方形範囲を超えるならflag = false
				bool flag;
				for(int sy=0;sy<N;sy++){
						for(int sx=0;sx<N;sx++){
								flag = true;
								vector<bool> Hdone(N), Wdone(N);
								vector<pair<int,int> > z(N);
								z[0] = {sy,sx};
								Hdone[sy] = true;
								Wdone[sx] = true;

								for(int i=1;i<N;i++){
										int ny = z[n[i]].first + dy[d[i]];
										int nx = z[n[i]].second + dx[d[i]] ;
										if(0  <= ny and nx < N and 0 <= nx and nx < N){
												Hdone[ny] = true;
												Wdone[nx] = true;
												z[i] = {ny,nx};
										}else{
												flag = false;
												break;
										}
								}
								if(flag){
										int w = 0, h = 0;
										for(int i=0;i<N;i++){
												if(Hdone[i]) h++;
												if(Wdone[i]) w++;
										}
										cout << w << " " << h << endl;
										break;
								}
						}
						if(flag) break;
				}
		}
}


Measured memory_bytes: 3012
import sys

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007


def main():
    s = readline().strip()

    ans = []
    for c in s:
        if c in ('0', '1'):
            ans.append(c)
        elif ans:
            ans.pop()

    print(''.join(ans))
    return


if __name__ == '__main__':
    main()


Measured memory_bytes: 8928
#include <bits/stdc++.h>
#define _ ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define int long long
const int inf = 0x3f3f3f3f3f3f3f3LL;
const int mod = 2019;
using namespace std;
#if LOCAL
#include "../../tr.h"
#else
#define tr(...)
#define endl '\n'
#endif
template<class T> void smin(T& a, T val) {if (a > val) a = val;}template<class T> void smax(T& a, T val) {if (a < val) a = val;}
const int N = 5*(int)1e5 + 10;

void solve(){
   string s;

   cin >> s;
   int n = (int)(s.size());

   vector<int> freq(mod, 0);
   int ans = 0;
   for (int i = 0; i < n; ++i)
   {
      int curr = s[i] - '0';
      vector<int> X(mod, 0);
      for (int j = 0; j < mod; ++j)
      {
         if (freq[j] == 0){
            continue;
         }
         int num = j;
         num *= 10;
         num %= 2019;
         num += curr;
         num %= 2019;
         X[num] = freq[j];
      }
      X[curr]++;
      ans += X[0];
      swap(freq, X);
   }

   cout<<ans;
}

int32_t main(){_
   
   int t = 1;
   //cin >> t;

   while(t--){
     solve();
     cout << endl;
   }
   

   return 0;
}

Measured memory_bytes: 3744
#include "bits/stdc++.h"

using namespace std;

int main()
{
    int a,a5,a10,a50,a100,a500;
    cin >> a >> a5 >>a10 >> a50 >> a100 >> a500;
    int sum=0;
    sum=a+a5*5+a10*10+a50*50+a100*100+a500*500;
    int ans=0;
    if(sum>=1000){
        ans=1;
    }
    cout << ans << endl;
    return 0;
}



Measured memory_bytes: 3120
#include <iostream>
using namespace std;
int main(void){
    int n;
    cin >> n;
    int ans=0;
    for (int i=3 ; i<=n ; i+=2){
        int counter=0;
        for (int j=1 ; j*j<i ; j++){
            if (i%j == 0){
                counter++;
            }
        }
        if (counter == 4){
            ans++;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std ;
typedef long long ll ;
int main () {
    
    int N , D;
    cin >> N >> D ;
    int mx = N ;
    for(int mask = 1 ; mask < (1 << N) ; mask++){
        
        bool v[N + 1] ;
        for(int j = 0 ; j <= N ;j++)
            v[j] = false ;
        vector<int> pos ;
        for(int j = 0 ; (1 << j) <= mask ;j++)
            if(mask&(1<<j)) pos.push_back(j + 1) ;
        for(int i = 0 ; i < pos.size();i++){
            for(int j = max(1 , pos[i] - D) ; j <= min(N , pos[i] + D) ;j++)
                v[j] = true ;
        }
        bool flag = true ;
        for(int i = 1 ; i <= N ;i++)
            if(v[i] == false){
                flag = false ;
                break ;
            }
        if(flag) mx = min(mx , int(pos.size())) ;
    }
    
    cout<<mx<<endl;
    return 0 ;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <utility>
#include <string>
#include <vector>
#include <set>
#include <stack>
#include <queue>
#include <map>
#include <math.h>
#include <string.h>
#include <iomanip>
#include <numeric>
#include <cstdlib>
#include <cstdint>
#include <cmath>
#include <functional>
#include <limits>
#include <cassert>

using namespace std;

/* template */

using ll = long long;

void debug_out() { std::cout << std::endl; }
 
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cout << H << " ";
  debug_out(T...);
}

#ifdef LOCAL
#define debug(...) cout << "debug: "; debug_out(__VA_ARGS__)
#else
#define debug(...) 
#endif

#define rep(i, a, n) for (int i = (int)(a); i < (int)(n); i++)
#define rrep(i, a, n) for (int i = ((int)(n-1)); i >= (int)(a); i--)
#define Rep(i, a, n) for (long long i = (long long)(a); i< (long long)(n); i++)
#define RRep(i, a, n) for (long long i = ((long long)(n-1ll)); i>=(long long)(a); i--)
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()

template <typename T>
std::ostream& operator<<(std::ostream& os, std::vector<T> vec) {
  for (std::size_t i = 0; i < vec.size(); i++)os << vec[i] << (i + 1 == vec.size() ? "" : " ");
  return os;
}

struct Edge{
    int to;
    ll weight;
    Edge(int t, ll w) : to(t), weight(w){ }
};

struct edge{
    int from;
    int to;
    ll weight;
    edge(int f,int t,ll w) : from(f), to(t), weight(w){ }
};


using Graph = vector<vector<Edge>>;
using graph = vector<vector<int>>;
using edges = vector<edge>;

template <class T>
inline bool chmin(T &a, T b){
    if (a > b){
        a = b;
        return true;
    }
    return false;
}

template <class T>
inline bool chmax(T &a, T b){
    if (a < b){
        a = b;
        return true;
    }
    return false;
}

template <class T>
T lcm(T a, T b){
    return (a*b)/gcd(a,b);
}

bool isPalindrome(string s){
    string t = s;
    reverse(all(t));
    return s==t;
}

constexpr ll LNF = __LONG_LONG_MAX__;

constexpr int INF = 1e9+7;

const double PI=3.14159265358979323846;


vector<int> dx = {-1,0,1,0,-1,1,-1,1};
vector<int> dy = {0,-1,0,1,1,-1,-1,1};

/* template */

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int n,q; cin >> n >> q;
    vector<tuple<ll,ll,ll>> r;
    rep(i,0,n){
        ll s,t,x; cin >> s >> t >> x;
        r.emplace_back(s-x,1,x);
        r.emplace_back(t-x,-1,x);
    }
    sort(all(r));
    ll now = 0;
    multiset<ll> s;
    rep(i,0,q){
        ll d; cin >> d;
        while(now<2*n && get<0>(r[now])<=d){
            if(get<1>(r[now])==1){
                s.insert(get<2>(r[now]));
            }
            else{
                auto p = s.lower_bound(get<2>(r[now]));
                s.erase(p);
            }
            now++;
        }
        if(s.empty()) cout << -1 << endl;
        else cout << *s.begin() << endl;
    }
}

Measured memory_bytes: 20328
#include <bits/stdc++.h>
using namespace std;
int main() {
    long long x;
    cin >> x;
    long long s = 100;
    int ans = 0;
    while (s < x) {
        s = (long long) (s * 1.01);
        ans++;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3624
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define cinf(n,x) for(int i=0;i<(n);i++)cin>>x[i];
#define ft first
#define sc second
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define all(v) (v).begin(),(v).end()
#define LB(a,x) lb(all(a),x)-a.begin()
#define UB(a,x) ub(all(a),x)-a.begin()
#define mod 1000000007
//#define mod 998244353
#define FS fixed<<setprecision(15)
using namespace std;
typedef long long ll;
const double pi=3.141592653589793;
template<class T> using V=vector<T>;
using Graph = vector<vector<int>>;
using P=pair<ll,ll>;
typedef unsigned long long ull;
typedef long double ldouble;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline void out(T a){ cout << a << '\n'; }
void YN(bool ok){if(ok) cout << "Yes" << endl; else cout << "No" << endl;}
//void YN(bool ok){if(ok) cout << "YES" << endl; else cout << "NO" << endl;}


const ll INF=1e18;
const int mx=200005;

int main(){
    cin.tie(0);ios::sync_with_stdio(false);
    ll n,K;
    cin>>n>>K;
    V<ll> x(n),y(n);
    V<P> p(n);
    rep(i,n){
        cin>>x[i]>>y[i];
        p[i]=make_pair(x[i],i);
    }
    sort(all(p));
    ll ans=5*INF;
    rep(i,n){
        for(int j=i;j<n;j++){
            if(j-i+1<K) continue;
            ll w=p[j].ft-p[i].ft;
            V<ll> tmp;
            for(int k=i;k<=j;k++){
                tmp.push_back(y[p[k].sc]);
            }
            sort(all(tmp));
            for(int k=0;k<(int)tmp.size()-K+1;k++){
                ll h=tmp[k+K-1]-tmp[k];
                chmin(ans,h*w);
            }
        }
    }
    out(ans);
}


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

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

#define FOR(i, n, m) for (ll(i) = (m); (i) < (n); ++(i))
#define REP(i, n) FOR(i, n, 0)
#define OF64 std::setprecision(10)

const ll MOD = 1000000007;
const ll INF = (ll)1e15;

class SegmentTree
{
  public:
    SegmentTree(int n)
    {
        int c = 1;
        while (c < n)
            c <<= 1;
        N = c;
        node.resize(2 * N - 1);
        REP(i, node.size())
        {
            node[i] = INF;
        }
    }

    void set(int l, int r, ll v, int k = 0, int tl = 0, int tr = -1)
    {
        if (tr == -1)
            tr = N - 1;
        if (tr < l || r < tl)
            return;

        if (l <= tl && tr <= r)
        {
            node[k] = std::min(v, node[k]);
            return;
        }
        set(l, r, v, 2 * k + 1, tl, (tl + tr) / 2);
        set(l, r, v, 2 * k + 2, (tl + tr) / 2 + 1, tr);
    }

    ll get(int n)
    {
        int k = N - 1 + n;
        ll min = node[0];
        while (k > 0)
        {
            min = std::min(min, node[k]);
            k = (k - 1) / 2;
        }
        return min;
    }

  private:
    int N;
    vector<ll> node;
};

struct T
{
    ll d;
    int i;
};
T D[200005];

struct S
{
    ll s;
    ll t;
    ll x;
};

S C[200005];

int main()
{
    ll N, Q;
    cin >> N >> Q;
    REP(i, N)
    {
        cin >> C[i].s >> C[i].t >> C[i].x;
    }
    REP(i, Q)
    {
        cin >> D[i].d;
        D[i].i = i;
    }
    sort(D, D + Q, [](T a, T b) { return a.d < b.d; });

    SegmentTree seg(Q);

    REP(i, N)
    {
        if (C[i].t - C[i].x < 0)
            continue;

        ll min = std::max(C[i].s - C[i].x, 0LL);
        ll max = C[i].t - C[i].x;

        //! 出発時間がmin以上max以下の奴はダメ
        ll l = N;
        {
            ll ok = Q - 1;
            ll ng = -1;
            while (abs(ok - ng) > 1)
            {
                ll mid = (ok + ng) / 2;
                if (D[mid].d >= min)
                    ok = mid;
                else
                    ng = mid;
            }
            if (D[ok].d >= min)
                l = ok;
            else
                l = ok + 1;
        }
        ll r = -1;
        {
            ll ok = 0, ng = Q;
            while (abs(ok - ng) > 1)
            {
                ll mid = (ok + ng) / 2;
                if (D[mid].d < max)
                    ok = mid;
                else
                    ng = mid;
            }
            if (D[ok].d < max)
                r = ok;
            else
                r = ok - 1;
        }
        if (r < l)
            continue;
        seg.set(l, r, C[i].x);

        //cout << l << " " << r << endl;
    }
    REP(i, Q)
    {
        D[i].d = seg.get(i);
    }
    sort(D, D + Q, [](T a, T b) { return a.i < b.i; });
    REP(i, Q)
    {
        if (D[i].d == INF)
            cout << -1 << endl;
        else
            cout << D[i].d << endl;
    }
    return 0;
}

Measured memory_bytes: 13824
def num_of_bits(bits)
  bits = (bits & 0x55555555) + (bits >> 1 & 0x55555555)
  bits = (bits & 0x33333333) + (bits >> 2 & 0x33333333)
  bits = (bits & 0x0f0f0f0f) + (bits >> 4 & 0x0f0f0f0f)
  bits = (bits & 0x00ff00ff) + (bits >> 8 & 0x00ff00ff)
  (bits & 0x0000ffff) + (bits >> 16 & 0x0000ffff)
end

N = gets.to_i
Fs = Array.new(N) { gets.split.join.to_i(2) }
Pss = Array.new(N) { gets.split.map(&:to_i) }
S = 1 << 10

ans = -1.0 / 0
(1...S).each do |s|
  sum = 0
  N.times do |i|
    sum += Pss[i][num_of_bits(Fs[i] & s)]
  end
  ans = [ans, sum].max
end

puts ans


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

int main(){
  string S, T;
  cin>>S>>T;
  int SN=S.size();
  int K=0;
  for(int i=0;i<SN;i++){
    if(S.at(i)!=T.at(i)){
      K=1;
    }
  }
  if(K==1){
    cout<<"No";
  }
  else{
    cout<<"Yes";
  }
}

Measured memory_bytes: 3588
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <cstring>
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <cmath>
#include <numeric>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
typedef unsigned long long ll;


int main(){
int N; cin >> N;
vector<pair<int, int>> A(N);//配列の宣言
for(int i = 0; i < N ; i++){
	int a;
  cin >> a;
  int b = i + 1;
  A[i] = make_pair(a,b);//配列型のpairに代入
}
  sort(A.begin(),A.end());//pair.firstを小さい順にsort
rep(i,N-1){
	cout <<	A[i].second << " "; 
}
	cout << A[N-1].second << endl;
}

Measured memory_bytes: 1536
import java.util.Scanner;
import java.util.Arrays;
import java.util.Collections;

public class Main {
	public static void main (String[] args) {
		// for C
		Scanner sc = new Scanner (System.in);
		int N = sc.nextInt ();
		long[] a = new long [N];
		int i;
		for (i=0; i<N; i++)
			a[i] = sc.nextLong ();
		Arrays.sort (a);
		long h=0, w=0;
		for (i=N-1; i>0; i--) {
			if (a[i]==a[i-1]) {
				h = a[i];
				i-=2;
				break;
			}
		}
		for (; i>0; i--) {
			if (a[i]==a[i-1]) {
				w = a[i];
				break;
			}
		}
		System.out.println (h*w);
	}
}

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

#define rep(i,n) for(int i=0; i<n; i++)
#define all(x) (x).begin(),(x).end()
#define INF (1000000000)
#define MOD (1000000007)

int main(){
  int n;
  cin >> n;
  string s;
  cin >> s;
  int cntr = 0;
  rep(i,n){
    if(s[i]=='R'){
      cntr++;
    }
  }
  int cntb = n-cntr;
  if(cntr>cntb){
    cout << "Yes" << endl;
  }else{
    cout << "No" << endl;
  }
}

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

int main(){
	int a = 0;
	int i;
	char moji[3];
	int b = 1;
	char m = '0' + b;
	if(scanf("%s",moji)==1){
		for(i=0;i < sizeof(moji);i++){
			if(moji[i] == '1')a++;
		}
	}
	printf("%d",a);
	
	return 0;
}

Measured memory_bytes: 128