akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#define ll long long
using namespace std;
const ll maxx = 1e6 + 7;
const ll mod = 1e9 + 7;
const ll base = 311;
const ll base1 = 113;
ll t, T, n, m, k, tong, r, ans, mx, mn, x, y;
string s, s1, s2, ss;
ll a[maxx], b[maxx], pw[maxx], pw1[maxx], st[maxx], st1[maxx], f[2002][2002];
bool check(ll v)
{
    if(v < 2)return false;
    for(int i = 2; i <= v / i; i ++)
        if(v % i == 0)return false;
    return true;
}
ll hs(ll hh[maxx], ll pw[maxx], ll i, ll j)
{
    return (hh[j] - hh[i-1] * pw[j - i + 1] + maxx * maxx) % maxx;
}
struct mm
{
    ll val;
    ll pos;
};
mm c[maxx];
bool lf(const mm &x, const mm &y)
{
    return (x.val > y.val) || (x.val == y.val && x.pos < y.pos);
}

void sol()
{
    cin >> n;
    for(int i = 1; i <= n; i ++)
    {
        cin >> c[i].val;
        c[i].pos = i;
    }
    sort(c+1, c+1+n, lf);
    f[0][0] = 0;
    ans = 0;
    for(int i = 1; i <= n; i ++)
    {
        for(int j = 0; j <= i; j ++)
        {
            int l = i - j;
            if(j > 0)
            {
                f[l][j] = max(f[l][j], f[l][j-1] + c[i].val * abs(c[i].pos - j));
            }
            if(l > 0)
            {
                f[l][j] = max(f[l][j], f[l-1][j] + c[i].val * abs(c[i].pos - (n -l + 1)));
            }
            ans = max(ans, f[l][j]);
        }
    }
    cout << ans;
}

int main()
{
    cin.tie(0);
    cout.tie(0);
    ios_base::sync_with_stdio(0);
    sol();
}
/*
using namespace std;
const ll maxn=3e5+1;
const ll maxx=1e13;
const ll mod=1e9+7;
const ll mod1=998244353;

//vector <ll> adj[maxn];
set<ll> adj1[maxn];
//vector<ll> ans;
//bool kt[maxn];
ll n,m,e,k;
ll d=0;
set<ll> pt;
set<ll> adj[maxn];
ll cnt=0;
void dfs(ll u)
{
    cnt++;
    pt.erase(pt.find(u));
    ll pre=0;
    auto it=pt.begin();
    while (it!=pt.end())
    {
        it=pt.upper_bound(pre);
        while (adj[u].find(*it)!=adj[u].end()&&it!=pt.end())
        {
            it++;
        }
        if ( it!=pt.end() )
        {
            pre=*it;
            dfs(*it);
        }
    }
}
int main()
{
    // freopen("test.txt","r",stdin);
    // freopen("CHEMIST.OUT","w",stdout);
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    ll n,m;
    cin>>n>>m;
    for (int i=1;i<=m;i++)
    {
        ll x,y;
        cin>>x>>y;
        adj[x].insert(y);
        adj[y].insert(x);


    }
    for (int i=1;i<=n;i++)pt.insert(i);
    vector<ll> ans;
    for (int i=1;i<=n;i++)
    {
        if (pt.find(i)!=pt.end())
        {
            cnt=0;
            dfs(i);
            ans.pb(cnt);
        }
    }
    sort(all(ans));
    cout <<ans.size()<<endl;
    for (auto p:ans)
    {
        cout <<p<<" ";
    }

}
*/


Measured memory_bytes: 26192
#include <bits/stdc++.h>
#define REP(i,n,N) for(ll i=(n);i<(ll) N;i++)
#define RREP(i,n,N) for(int i=N-1;i>=(int) n;i--)
#define p(s) cout<<(s)<<endl
#define DEBUG(x,y) cout<<#x<<": "<<x<<" , "<<#y<<": "<<y<<endl;
#define CK(n,a,b) ((a)<=(n)&&(n)<=(b))
#define F first
#define S second
typedef long long ll;
using namespace std;
const int inf=1e9+7;

int N;
int A[15];
int g=1;
int main(){
	cin>>N;

	REP(i,0,N) cin>>A[i];
	REP(i,0,N){
		if(A[i]%2==0){
			g*=2;
		}
	}
	p(pow(3,N)-g);
	return 0;
}


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

int main()
{
  int n,k;
  cin>>n>>k;
  int arr[n];
  for(int i=0;i<n;i++)
  {
    cin>>arr[i];
  }
  sort(arr,arr+n);
  int sum = 0;
  for(int i=0;i<k;i++)
  {
    sum+=arr[i];
  }
  cout<<sum<<endl;
}

Measured memory_bytes: 3592
#include<iostream>
#include<vector>
#include<map>
#include<algorithm>
using namespace std;

int main() {
    int n; 
    scanf("%d", &n);

    string t;
    map<string, int> mp;

    long long ans = 0;
    for (int i = 0; i < n; i++) {
        cin >> t;
        sort(t.begin(), t.end());
        mp[t]++;
        ans += mp[t] - 1;
    }

    cout << ans << endl;
}

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

const int modx = 1e9+7, basx = 19260817, mody = 1e9+9, basy = 998244353;
const int MAXN = 37;

int n, powerx[MAXN], powery[MAXN];
string str;
struct hash_str {
	int hx, hy;
	hash_str() { hx = hy = 0; }
	hash_str(int x, int y)
	{ hx = x, hy = y; }
	friend bool operator < (const hash_str &a, const hash_str &b)
	{
		if (a.hx != b.hx) return a.hx < b.hx;
	        return a.hy < b.hy;
	}
	void append(int x)
	{ hx = ((long long)hx*basx+x)%modx, hy = ((long long)hy*basy+x)%mody; }
	friend hash_str operator - (const hash_str &a, const hash_str &b)
	{ return (hash_str) {((a.hx-b.hx)%modx+modx)%modx, ((a.hy-b.hy)%mody+mody)%mody}; }
	inline hash_str shift(int x) const
	{ return (hash_str) {(long long)hx*powerx[x]%modx, (long long)hy*powery[x]%mody}; }
};

map<hash_str, int> st;

int main()
{
	cin >> n >> str;
	powerx[0] = 1, powery[0] = 1;
	for (int i = 1; i <= n; i++) powerx[i] = (long long)powerx[i-1]*basx%modx;
	for (int i = 1; i <= n; i++) powery[i] = (long long)powery[i-1]*basy%mody;
	auto join = [](const hash_str &x, const hash_str &y, int len) {
		return x.shift(len)-y;
	};
	for (int i = 0; i < 1<<n; i++) {
		hash_str x, y;
		int c = 0;
		for (int j = 0; j < n; j++) 
			if (i>>j&1)
				x.append(str[j]), c++;
		for (int j = n-1; j >= 0; j--)
			if (!(i>>j&1))
				y.append(str[j]);
		c = n-c;
		hash_str h = join(x, y, c);
		st[h]++;
	}
	long long ans = 0;
        for (int i = 0; i < 1<<n; i++) {
		hash_str x, y;
		int c = 0;
		for (int j = 0; j < n; j++) 
			if (i>>j&1)
				x.append(str[j+n]);
		for (int j = n-1; j >= 0; j--)
			if (!(i>>j&1))
				y.append(str[j+n]), c++;
		c = n-c;
		hash_str h = join(y, x, c);
		ans += st[h];
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 33024
#include <stdio.h>

int main(){
  char moji;

  scanf("%c", &moji);

  if((moji>='a')&&(moji<='z')){
    printf("a\n");
  }else if((moji>= 'A') && (moji<='Z')){
    printf("A\n");
  }
  return 0;
}


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

#define max(a,b)(a>b?a:b)

int main()
{
	ios::sync_with_stdio(false);
	
	const int max_n=20;
	char operations[max_n];
	cin>>operations;
	
	char answer[max_n];
	int end=0;
	
	for(int i=0;operations[i]!='\0';i++)
	{
		if(operations[i]=='B')
			end=max(0,end-1);
		else
			answer[end++]=operations[i];
	}
	
	for(int i=0;i<end;i++)
		cout<<answer[i];
	
	return 0;
}

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

int main() {
  int A, B, C, D;
  cin >> A >> B >> C >> D;
  
  if (A * B < C * D) {
    cout << C * D << endl;
  } else if (A * B > C * D) {
    cout << A * B << endl;
  } else if (A * B == C * D) {
    cout << A * B << endl;
  }
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <vector>
#include <array>
#include <deque>
#include <queue>
#include <list>
#include <map>
#include <set>
#include <algorithm>
#include <numeric>
#include <cmath>

using namespace std;

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

    vector<array<int, 4>> city(M);
    for (int i = 0; i < M; ++i) {
        city[i][0] = i;
        cin >> city[i][1] >> city[i][2];
    }
    sort(city.begin(), city.end(), [](auto &lhs, auto &rhs){return lhs[2] < rhs[2];});

    vector<int> npref(N, 0);

    for (auto& e: city) {
        ++npref[e[1]];
        e[3] = npref[e[1]];
    }

    sort(city.begin(), city.end());

    for (auto&& e: city) {
        cout << setfill('0') << setw(6) << e[1] << setfill('0') << setw(6) << e[3] << endl;
    }

    return 0;
}


Measured memory_bytes: 3456
#include<bits/stdc++.h>
#include<unordered_set>
#include<unordered_map>
#include <algorithm> 
#include <iostream>
#include <string>
#include <cmath>
using namespace std;
#define ll long long
#define rep(i,n) for (ll i = 0; i < (n); i++)
#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
#define FORR(i,a,b)for(ll i=(a);i<=(b);i++)
#define repR(i,n) for(ll i=n;i>=0;i--)
#define all(v)(v).begin(),(v).end()
#define rall(v)(v).rbegin(),(v).rend()
#define F first
#define S second
#define pb push_back
#define pu push
#define COUT(x) cout<<(x)<<"\n"
#define PQ priority_queue<ll>
#define PQR priority_queue<ll,vector<ll>,greater<ll>>
#define YES(n) cout << ((n) ? "YES\n" : "NO\n"  )
#define Yes(n) cout << ((n) ? "Yes\n" : "No\n"  )
#define mp make_pair
#define sz(x) (ll)(x).size()
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
const ll MOD = 1000000007LL;
const ll INF = 1LL << 60;
using vll = vector<ll>;
using vb = vector<bool>;
using vvb = vector<vb>;
using vvll = vector<vll>;
using vstr = vector<string>;
using vc = vector<char>;
using vvc = vector<vc>;
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 dx[4]={0,1,0,-1};
ll dy[4]={1,0,-1,0};
int main(){
  ll n;
  cin>>n;
  vll l(n);
  rep(i,n) cin>>l[i];
  ll ans=0;
  sort(all(l));
  rep(i,n){
    for(int j=i+1;j<n;j++){
      for(int z=j+1;z<n;z++){
        if(l[i]+l[j]>l[z] && l[i]!=l[j]&&l[j]!=l[z]&&l[i]!=l[z]) ans++;
      }
    }
  }
  COUT(ans);
}

Measured memory_bytes: 3600
class FenwickTree:
    def __init__(self, size):
        self.elems = [0 for _ in range(size)]
        self.size = len(self.elems)

    def query(self, ind):
        resp = 0
        while ind > 0:
            resp = max(resp, self.elems[ind])
            ind -= ind & -ind
        return resp

    def update(self, ind, val):
        while ind < self.size:
            self.elems[ind] = max(self.elems[ind], val)
            ind += ind & -ind


n = input()
h = map(int, raw_input().split())
a = map(int, raw_input().split())
tree = FenwickTree(n + 1)

dp = [0] * n
for i in range(n):
    dp[i] = a[i] + tree.query(h[i])
    tree.update(h[i], dp[i])
print(max(dp))


Measured memory_bytes: 65216
#include<iostream>
#include<algorithm>

using namespace std;

typedef long long Int;
Int a[324000];
Int n, res;
int main(){
  cin >> n;
  for(int i = 0;i < 3 * n;i++){
    cin >> a[i];
  }
  sort(a, a + 3*n);
  Int p = 3 * n - 2;
  for(int i = 0;i < n;i++, p -= 2)res += a[p];
  cout << res << endl;
}

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

int main() {
  int64_t A,B,C,K;
  cin >> A >> B >> C >> K;
  int64_t ans=0;
  ans+=min(A,K);
  if(A+B>=K){
    cout << ans << endl;
    return 0;
  }
  K-=A+B;
  ans-=K;
  cout << ans << endl;
}

Measured memory_bytes: 3588
import java.util.Scanner;
 class Main{
	
public static int bubbleSort(int A[],int N){
    int i,j,r=0,temp;
    boolean flag=true;
    for(i=0;flag;i++){
    	flag=false;
        for(j=N-1;j>=i+1;j--){
        	if(A[j]<A[j-1]){
        		temp=A[j];
        		A[j]=A[j-1];
        		A[j-1]=temp;
        flag=true;
        r++;      	
        }
}
}
    return r;
}
   
public static void main(String[] args){
         
		 Scanner sc= new Scanner(System.in);
	         int N=sc.nextInt();
             int A[]=new int[100];
             
             int i,j;
             for(i=0;i<N;i++){
            	 A[i] = sc.nextInt();
             }
	       
        int loop = bubbleSort(A,N);
        for(i=0;i<N;i++){
      	  if(i>0)
      	   System.out.print(" ");
         System.out.print(A[i]);
        }
        System.out.println();
        System.out.println(loop);
        sc.close();
}
}

Measured memory_bytes: 26180
#include <bits/stdc++.h>
#define INF 100000000000
#define ll long long
#define pll pair<ll, ll>
using namespace std;

int main()
{
  string S;
  cin >> S;
  ll K;
  cin >> K;
  ll N = S.size();
  ll cnt = 0;
  vector<bool> in_s(26, false);
  for (ll i = 0; i < N; ++i) {
    in_s.at(S[i] - 'a') = true;
  }
  for (ll i = 0; i < 26; ++i) {
    if (!in_s.at(i)) {
      continue;
    }
    set<string> st;
    char check = (char)('a' + i);
    for (ll j = 0; j < N; ++j) {
      if (S[j] == check) {
        for (ll k = 1; k <= K; ++k) {
          if (j + k > N) {
            break;
          }
          st.insert(S.substr(j, k));
        }
      }
    }
    ll temp = st.size();
    if (cnt + temp >= K) {
      vector<string> sorted;
      for (auto j = st.begin(); j != st.end(); ++j) {
        sorted.push_back(*j);
        // cout << "j" << *j << endl;
      }
      sort(sorted.begin(), sorted.end());
      cout << sorted.at(K - cnt - 1) << endl;
      // for (ll i = 0; i < temp; ++i) {
      //   cout << sorted.at(i) << endl;
      // }
      return 0;
    }
    cnt += temp;
  }
}


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

bool dp[1000010];
int n,x;
int cook[33];
int solve();
bool prime(int now);

int main(){
	while(1){
		cin >> n >> x;
		if(n == 0 && x == 0) break;
		memset(dp,false,x+2);
		dp[0] = true;
		for(int i=0;i<n;i++){
			cin >> cook[i];
			for(int k=cook[i];k<=x;k++){
				if(dp[k-cook[i]]){
					dp[k] = true;
				}
			}
		}
		int ans = solve();
		if(ans) cout << ans << endl;
		else cout << "NA" << endl;
	}
}

int solve (){
	int now = x;
	while(1){
		if(dp[now] && !(prime(now))) return now;
		now--;
	}
}

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

Measured memory_bytes: 2144
#define taskname "test"

#include <bits/stdc++.h>

using namespace std;

#define sz(x) (int)x.size()
#define fi first
#define se second

typedef long long lli;
typedef pair<int, int> pii;

int n, D;

void read_input()
{
    cin >> n >> D;
}

lli sqr(int x)
{
    return x * 1LL * x;
}

void solve()
{
    int ans = 0;
    for(int i = 0; i < n; ++i)
    {
        int x, y;
        cin >> x >> y;
        if(sqr(x) + sqr(y) <= sqr(D))
            ++ans;
    }
    cout << ans << '\n';
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    read_input();
    solve();
}



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

int main(){
    string W, T;
    cin >> W;
    int a = 0;
    while(1){
        cin >> T;
        if(T == "END_OF_TEXT") break;
        for(int i = 0 ; i < T.size() ; i++){
            if(isalpha(T[i])) T[i] = tolower(T[i]);
        }
        if(T == W) a++;
    }
    cout << a << endl;
    return 0;
}


Measured memory_bytes: 3172
fn read_vec<T>() -> Vec<T>
where T: std::str::FromStr,
{
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().split_whitespace().map(
        |e| e.parse().ok().unwrap()
        ).collect()
}



fn main() {
    let inputs :Vec<u32> = read_vec();
    let r = inputs[0];
    let d = inputs[1];
    let mut x = inputs[2];
    for _ in 0..10 {
        x = r*x - d;
        println!("{}", x);
    }
}


Measured memory_bytes: 4352
#include <iostream>
#include <iomanip>
#include <string>
#include <map>
#include <math.h>
using namespace std;
 
#define ll long long
 
int main(){
    double N,K,ans = 0;
    cin >> N >> K;
    for(double i = 0; i < N; i++){
        for(double j = 0; j < 20; j++){
            if((i+1)*pow(2,j) >= K){
                ans += 1/N * pow(0.5,j);
                break;
            }
        }
    }
    cout << setprecision(20) << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const int64_t MOD = 1000000007;

int64_t pow_mod(int64_t M, int64_t N)
{
  int64_t POW[100];
  POW[0] = 1;
  POW[1] = M;
  for (int i = 2; i < 100; i++)
    POW[i] = (POW[i - 1] * POW[i - 1]) % MOD;
  int64_t bit = N, k = 1, m = 1;
  while (N > 0)
  {
    int a = N % 2;
    if (a)
      m = (m * POW[k]) % MOD;
    k++;
    N /= 2;
  }
  return m;
}

int main()
{
  int64_t M, N;
  cin >> M >> N;
  cout << pow_mod(M, N) << endl;
}


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

#define rep(i,n) for(int i = 0; i<n; ++i)
#define REP(i,n) for(int i = 1; i<=n; ++i)
#define all(x) begin(x),end(x)
#define show(obj) {for(auto x:obj)cout<<x<<' ';cout<<endl;}
#define line "----------"
typedef long long ll;
typedef pair<int,int> P;
const int inf = 1001001000;
const ll INF = 1LL<<60;
const ll MOD = 1e9 + 7;

int main(){
	ll A; double B;
	cin>>A>>B;
	ll ans = round(B*100);
	ans *= A;
	ans /= 100;
	cout<<ans<<endl;
}

// int main(){
// 	ll A; long double B; 
// 	cin>>A>>B;
// 	ll ans = A*B;
// 	cout<<ans<<endl;
// 	return 0;
// }

Measured memory_bytes: 3772
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>

#include <iostream>
#include <complex>
#include <string>
#include <algorithm>
#include <numeric>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>

#include <functional>
#include <cassert>

typedef long long ll;
using namespace std;

#ifndef LOCAL
#define debug(x) ;
#else
#define debug(x) cerr << __LINE__ << " : " << #x << " = " << (x) << endl;

template <typename T1, typename T2>
ostream &operator<<(ostream &out, const pair<T1, T2> &p) {
  out << "{" << p.first << ", " << p.second << "}";
  return out;
}

template <typename T>
ostream &operator<<(ostream &out, const vector<T> &v) {
  out << '{';
  for (const T &item : v) out << item << ", ";
  out << "\b\b}";
  return out;
}
#endif

#define mod 1000000007 //1e9+7(prime number)
#define INF 1000000000 //1e9
#define LLINF 2000000000000000000LL //2e18
#define SIZE 200010

ll s[SIZE], t[SIZE];

int main(){
  int N, M, Q;

  scanf("%d%d%d", &N, &M, &Q);

  for(int i=1;i<=N;i++) scanf("%lld", s+i);
  for(int i=1;i<=M;i++) scanf("%lld", t+i);
  s[0] = t[0] = -LLINF;
  s[N+1] = t[M+1] = LLINF;

  N += 2;
  M += 2;

  for(int i=0;i<Q;i++){
    ll x;
    ll ans = LLINF;

    scanf("%lld", &x);

    ll *p = lower_bound(s, s+N, x);
    ll *q = lower_bound(t, t+M, x);

    ll a = abs(x - *p);
    ll b = abs(x - *(p-1));
    ll c = abs(x - *q);
    ll d = abs(x - *(q-1));

    ans = min(ans, max(a, c));
    ans = min(ans, max(b, d));
    ans = min(ans, min(a, b) + min(c, d) + min({a, b, c, d}));

    printf("%lld\n", ans);
  }

  return 0;
}


Measured memory_bytes: 2816
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
	    Scanner in = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
	    String s = in.next();
	    s = s.toLowerCase();
	    String t = in.next();
	    t = t.toLowerCase();
	    
	    int sn = s.length();
	    int tn = t.length();
	    
	    if ((sn<1 || sn>3000) && (tn<1 || tn>3000)) {
	    	System.out.println("Entrada invalida!!!");
	    	System.exit(0);
	    }
	 
	    int[][] p = new int[sn + 1][tn + 1];
	    
	 
	    int[][] dp = new int[sn + 1][tn + 1];
	    for (int i = 1; i <= sn; i++) {
	      for (int j = 1; j <= tn; j++) {
	        if (s.charAt(i - 1) == t.charAt(j - 1)) {
	          dp[i][j] = dp[i - 1][j - 1] + 1;
	          p[i][j] = -3;
	        } else {
	          if (dp[i - 1][j] > dp[i][j - 1]) {
	            dp[i][j] = dp[i - 1][j];
	            p[i][j] = -1;
	          } else {
	            dp[i][j] = dp[i][j - 1];
	            p[i][j] = -2;
	          }
	        }
	      }
	    }
	 
	  StringBuilder sb = new StringBuilder();
	    int i = sn, j = tn;
	    while (p[i][j] != 0) {
	      if (p[i][j] == -3) {sb.append(s.charAt(i - 1)); i--; j--;}
	      else if (p[i][j] == -1) {i--;}
	      else {j--;}
	    }
	 	 
	    System.out.println(sb.reverse());
	  }
}


Measured memory_bytes: 130252
#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> pii;

#define mem(ar,a)       memset(ar,a,sizeof ar)
#define iOS           	ios_base::sync_with_stdio(false);cin.tie(NULL); 
#define pb(x)           push_back(x)
#define all(c)          c.begin(), c.end()
#define int             long long
#define ff              first
#define ss              second
#define nl              '\n'

int32_t main()
{
	iOS
	int x,y;cin>>x>>y;

	for(int i=0;i<=x;i++){
		int tur=x-i;
		if((tur*4+2*i)==y)
		{
			cout<<"Yes";return 0;
		}
	}
	cout<<"No";
}



Measured memory_bytes: 3664
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
#define strall(v) (v).cbegin(),(v).cend()
using namespace std;
using ll = long long;
using P = pair<int,int>;
using Graph = vector<vector<int>>;
template<class t,class u> void chmax(t&a,u b){if(a<b)a=b;}
template<class t,class u> void chmin(t&a,u b){if(b<a)a=b;}

vector<bool> a(105,false);

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


int main(){
  bool flag = true;
 int h,w;
 cin >> h >> w;
 vector<vector<char>> c(h,vector<char>(w));
 rep(i,h) rep(j,w) cin >> c[i][j];
 rep(i,h) rep(j,w) {
   int cnt = 0;
   if(c[i][j] == '#'){
     
       for(int p=0;p<4;p++){
         if(i+dy[p] >= h || i+dy[p] < 0 || j+dx[p] >= w || j+dx[p] < 0) continue;
         if(c[i+dy[p]][j+dx[p]] == '#') cnt++;
       }
       if(cnt < 1) flag = false;
   }
   
 }
 cout << ((flag)? "Yes":"No") << endl;
}


Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
typedef long long ll;
const int N=100010;
char s[N*2];
int k;
ll ans,ans1,ans2;
int main(){
	scanf("%s%d",s+1,&k);
	int n=strlen(s+1);
	if(s[1]==s[n]){
		bool ck=0;
		for(int i=2;i<=n;i++)
			if(s[i]!=s[i-1]){
				ck=1;
				break;
			}
		if(!ck){
			printf("%lld\n",1ll*n*k/2);
			return 0;
		}
		int i=1,l=1;
		while(s[i]==s[i+1]&&i<n){
			i++;
			l++;
		}
		ans1=l;
		int S=i+1;
		i=n,l=1;
		while(s[i]==s[i-1]&&i>1){
			i--;
			l++;
		}
		ans2=l;
		int T=i-1;
		for(i=S;i<=T;i++){
			l=1;
			while(s[i]==s[i+1]&&i<T){
				i++;
				l++;
			}
			ans+=l/2;
		}
		ans=ans*k+ans1/2+ans2/2+(ans1+ans2)/2*(k-1);
	}
	else{
		for(int i=1;i<=n;i++){
			int l=1;
			while(s[i]==s[i+1]&&i<n){
				i++;
				l++;
			}
			ans+=l/2;
		}
		ans*=k;
	}
	printf("%lld\n",ans);
	return 0;
}

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

#define FOR(i, a, b) for(int i=(a); i<(b); i++)
#define RFOR(i, a, b) for(int i=(a); i>=(b); i--)
#define rep(i, n) FOR(i, 0, n)
#define rrep(i, n) RFOR(i, n, 0)
#define dump(x)  cout << #x << " = " << (x) << endl;

typedef long long ll;
typedef pair<int, int> ii;
const ll INF = 1e18;
const int inf = 1e8;


void solve()
{
  vector<ll> a(3, 0);
  for (int i=0; i<3; i++) {
    scanf("%lld",&a[i]);
  }
  ll K;
  scanf("%lld",&K);
  sort(a.begin(),a.end());
  cout << a[0]+a[1]+a[2]*pow(2,K) << endl;
}

int main()
{
  solve();
  return 0;
}


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

template <class T>
inline bool read(T &ret)
{
    char c;
    int sgn;
    if (c = getchar(), c == EOF)
    {
        return 0;
    }
    while (c != '-' && (c < '0' || c > '9'))
    {
        c = getchar();
    }
    sgn = (c == '-') ? -1 : 1;
    ret = (c == '-') ? 0 : (c - '0');
    while (c = getchar(), c >= '0' && c <= '9')
    {
        ret = ret * 10 + (c - '0');
    }
    ret *= sgn;
    return 1;
}

template <class T>
inline void write(T x)
{
    if (x > 9)
    {
        write(x / 10);
    }
    putchar(x % 10 + '0');
}

int ans=0;
bool pd[99999];

int main()
{
    memset(pd,false,sizeof(pd));
    int n;
    cin>>n;
    for(int i=1;i<=n;i++)
    {
        for(int j=1;j<=n;j++)
        {
            for(int k=1;k<=n;k++)
            {
                if(!pd[100*i+10*j+k])
                {
                    pd[i+j+k]=true;
                    ans++;
                }
            }
        }
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 384
o=list(input())
e=list(input())
ans=""
if len(o)-len(e)==0:
    for i in range(len(o)):
        ans+=o[i]
        ans+=e[i]
    print(ans)
else:
    for i in range(len(e)):
        ans+=o[i]
        ans+=e[i]
    print(ans+o[-1])

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


int main(){
  while(1){
    int H,W;
    cin>>H>>W;
    if(H==0 && W==0) break;

    for(int i=0;i<H;i++){
      for(int j=0;j<W;j++){
	if(i==0||i==H-1||j==0||j==W-1) cout<<"#";
	else cout<<".";
      }
      cout<<endl;
    }
    cout<<endl;
  }

  return 0;
}


Measured memory_bytes: 3120
def main():
    n = int(input())
    a = list(map(int, input().split()))
    dp = [0] * (n*n)
    for i in range(n):
        dp[i+i*n] = a[i]
    for i in range(n - 2, -1, -1):
        for j in range(i + 1, n):
            dp[i+j*n] = max(a[i] - dp[i + 1+j*n], a[j] - dp[i+(j - 1)*n])
    print(dp[(n - 1)*n])
main()

Measured memory_bytes: 110192
#include<iostream>
using namespace std;
int main()
{
  int k,a,b;
  cin >> k >> a >> b;
  int f = 0;
  for(int i = a; i <= b; i++)
    if(i % k == 0)
      f = 1;
  if(f)
    cout << "OK\n";
  else
    cout << "NG\n";
}

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

int main() {

	string s, p;
	string::size_type index;

	cin >> s;
	cin >> p;

	s += s;


	index = s.find(p);

	if (index == string::npos) {
		cout << "No" << endl;
	}
	else {
		cout << "Yes" << endl;
	}


	return 0;
}

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

int main() {
  int N, M, X;
  cin >> N >> M >> X;
  vector<int> C(N);
  vector<vector<int>> A(N, vector<int>(M));
  rep(i, N) {
    cin >> C.at(i);
    rep(j, M) {
      cin >> A.at(i).at(j);
    }
  }

  // 全パターン試す
  int ans = INT_MAX;
  vector<int> v(M, 0);
  for (int bits = 1; bits < (1 << N); bits++) {
    int cost = 0;
    rep(i, M) v.at(i) = 0;
    for (int i = 0; i < N; i++) {
      if ((bits >> i) & 1) {
        // Ciが含まれる場合
        cost += C.at(i);
        rep(j, M) {
          v.at(j) += A.at(i).at(j);
        }
      }
    }

    bool res = true;
    rep(i, M) {
      if (v.at(i) < X) {
        res = false;
        break;
      }
    }
    if (res && cost < ans) {
      ans = cost;
    }
  }

  if (ans == INT_MAX) {
    ans = -1;
  }

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

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

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

int main()
{
    ll a,b,c,k,sum=0;
    cin >> a >> b >> c >> k;
    if( a>=k)
    {
        cout << k << endl;
        return 0;
    }
    else{
        k = k - a;
        sum = sum + a;
        if( b >= k)
        {
            cout << sum << endl;
            return 0;
        }
        else{
            k = k - b;
            sum = sum - 1*k;
            cout << sum << endl;
            return 0;
        }
    }
    return 0;
}



Measured memory_bytes: 3620
import java.util.Scanner;
import java.math.BigDecimal;
class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int n = 2, m = 3;
    double a[][] = new double[n][m];
    while(sc.hasNext()) {
      for (int i = 0; i < n; i++) {
        for (int j = 0; j < m; j++) {
          a[i][j] = sc.nextDouble();
        }
      }
      for (int ipv = 0; ipv < n; ipv++) {
        double max = 0.0;
        int row = 0;
        for(int i = ipv; i < n; i++) {
          if(Math.abs(a[i][ipv]) > max) {
            max = a[i][ipv];
            row = i;
          }
        }
        if(max == 0.0) {
          break;
        }
        if(ipv != row) {
          for(int j = 0; j < m; j++) {
            double temp = a[ipv][j];
            a[ipv][j] = a[row][j];
            a[row][j] = temp;
          }
        }
        
        double inv_pv = 1.0/a[ipv][ipv];
        for (int j = 0; j < m; j++) {
          a[ipv][j] *= inv_pv;
        }
        
        for (int i = 0; i < n; i++) {
          if (i != ipv) {
            double temp = a[i][ipv];
            for (int j = 0; j < m; j++) {
              a[i][j] -= temp*a[ipv][j];
            }
          }
        }
      }
      BigDecimal x[] = new BigDecimal[n];
      for (int i = 0; i < n; i++) {
        BigDecimal bda = new BigDecimal(a[i][m-1]);
        x[i] = bda.setScale(3, BigDecimal.ROUND_HALF_UP);
      }
      System.out.println(x[0]+" "+x[1]);
    }
  }
}

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

int main() {
	static char aa[11], bb[11], cc[11];
	int a, b;

	scanf("%s%s%s", aa, bb, cc);
	a = strlen(aa);
	b = strlen(bb);
	printf(aa[a - 1] == bb[0] && bb[b - 1] == cc[0] ? "YES\n" : "NO\n");
	return 0;
}


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

int main(){
    string a , m ,n;
    int b , c;
    cin >> b >> a;
    c= 0;
    if(b % 2 == 0){
        while(c  != b/2){
            n = a.at(c);
            m += n;
            c = c + 1;
        }
        if(a == m + m){
            cout << "Yes" <<endl;
        }else{
            cout << "No" << endl;
        }
    }else{
        cout << "No" << endl;
    }
    
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return true; } return false; }
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define si(x) int(x.size())
const int mod=1000000007,MAX=200005,INF=1<<29;

int main(){
    
    std::ifstream in("text.txt");
    std::cin.rdbuf(in.rdbuf());
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    int N,M;cin>>N>>M;
    if(N%2){
        for(int i=1;i<=M;i++){
            cout<<i<<" "<<N+1-i<<"\n";
        }
    }else{
        vector<pair<int,int>> ans;
        for(int i=1;i<=N/4;i++){
            ans.push_back({i,N+1-i});
        }
        for(int i=N/4+1;i<=N/2;i++){
            ans.push_back({i,N-i});
        }
        
        for(int i=0;i<M;i++){
            cout<<ans[i].fi<<" "<<ans[i].se<<"\n";
        }
    }
}


Measured memory_bytes: 4240
X,K,D=map(int,input().split())
a=round(abs(X/D))
if K<a:
  print(abs(abs(X)-K*abs(D)))
elif (K-a)%2==0:
  l=[]
  l.append(abs(abs(X)-a*abs(D)))
  l.append(abs(abs(X)-(a+2)*abs(D)))
  l.append(abs(abs(X)-(a-2)*abs(D)))
  print(min(l))
elif (K-a)%2!=0:
  l=[]
  l.append(abs(abs(X)-(a+1)*abs(D)))
  l.append(abs(abs(X)-(a-1)*abs(D)))  
  print(min(l))

Measured memory_bytes: 9164
/*
  author: ruruvuvu
  GitHub account: colon-ku

  created at: 2020-03-05 00:45:46
*/

#include <bits/stdc++.h>
using namespace std;

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

typedef long long LL;
typedef long double LD;

bool compare_by_b(pair<int, int> a, pair<int, int> b)
{
    if (a.second != b.second) {
        return a.second < b.second;
    } else {
        return a.first < b.first;
    }
}

ostringstream oss_global;
string s_global = oss_global.str();

int main()
{
    int a[4][4] = {0};
    for (int i = 1; i <= 3; i++)
        for (int j = 1; j <= 3; j++)
            cin >> a[i][j];
    
    int n;
    cin >> n;
    int b[n] = {0}; 
    for (int i = 0; i < n; i++)
        cin >> b[i];

    for (int k = 0; k < n; k++)
        for (int i = 1; i <= 3; i++)
            for (int j = 1; j <= 3; j++)
                if (a[i][j] == b[k]) a[i][j] = 0;
    
    int bingo;
    if (a[1][1] + a[2][1] + a[3][1] == 0 ||
        a[1][2] + a[2][2] + a[3][2] == 0 ||
        a[1][3] + a[2][3] + a[3][3] == 0 ||
        a[1][1] + a[1][2] + a[1][3] == 0 ||
        a[2][1] + a[2][2] + a[2][3] == 0 ||
        a[3][1] + a[3][2] + a[3][3] == 0 ||
        a[1][1] + a[2][2] + a[3][3] == 0 ||
        a[1][3] + a[2][2] + a[3][1] == 0)
    {
        bingo = 1;
    } else {
        bingo = 0;
    }

    if (bingo) cout << "Yes" << endl;
    else cout << "No" << endl;

    return 0;
}


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

const long long MOD = 1e9 + 7;
long long fac[210000], finv[210000], inv[210000];
 
long long mod_pow(long long x, long long n) {
    long long ans = 1;
    while (n != 0) {
      if (n & 1) ans = ans * x % MOD;
      x = x * x % MOD;
      n = n >> 1;
    }
    return ans;
}
 
void com_init() {
  fac[0] = fac[1] = 1;
  finv[0] = finv[1] = 1;
  inv[1] = 1;
  for (int i = 2; i < 210000; i++) {
    fac[i] = fac[i - 1] * i % MOD;
    finv[i] = finv[i - 1] * mod_pow(i, MOD - 2) % MOD;
  }
}
 
long long comb(long long n, long long k) {
  if (n < k) return 0;
  if (n < 0 || k < 0) return 0;
  return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
 
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  long long n, k;
  cin >> n >> k;
  long long ans = 0;
  com_init();
  for (int i = 0; i < min(k + 1, n); i++) {
    ans += (comb(n, i) * comb(n - 1, n - i - 1)) % MOD;
    ans %= MOD;
  }
  cout << ans << "\n";
  return 0;
}

Measured memory_bytes: 3584
#include <bits/stdc++.h>
#define rep(i,n) for(ll i=0;i<(n);++i)
#define sayyes cout<<"Yes"<<endl;
#define sayno cout<<"No"<<endl;
#define vv(a,b) vector< vector<int> > v(a,vector<int>(b,0));
using namespace std;
typedef long long ll;
typedef pair<int,int>P;
const int mod =1e9+7;

int main()
{
    ll a,b,n;
    cin>>a>>b>>n;
    ll ans=min(b-1,n);
    cout<<floor(a*ans/b)-a*floor(ans/b);
    
}


Measured memory_bytes: 3796
#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <utility>
#include <stack>
#include <numeric>
#include <algorithm>
#include <tuple>
#include <stdio.h>
#include <bitset>
#include <limits.h>
#include <complex>
#include <deque>
#include <iomanip>
#include <list>
using namespace std;
#define pi pair<int32,int32>
#define pl pair<int64,int64>
#define chmax(a,b) (a<b ? a=b:0)
#define chmin(a,b) (a>b ? a=b:0)
#define en cout << endl //セミコロンつけろ
//#define MM 1000000000
//#define MOD MM+7
const int MM = 1e9;
const int MOD = MM+7;
const long double PI = acos(-1);
const long long INF = 1e15;
int dx[8] = {-1,0,1,0,-1,-1,1,1};
int dy[8] = {0,-1,0,1,-1,1,1,-1};
// 'A' = 65, 'Z' = 90, 'a' = 97, 'z' = 122
template<typename T>
T GCD(T u,T v){
    return v ? GCD(v,u%v) : u;
}
template<typename T>
T LCM(T x,T y){
    T gc = GCD(x,y);
    return x*y/gc;
}

int main(){
    int n,m; cin >> n;
    map<int,int> mp;
    for(int i = 0; i < n; i++){
        int a; cin >> a;
        mp[a]++;
    }
    cin >> m;
    vector<int> v;
    for(int i = 0; i < m; i++){
        int b; cin >> b;
        if (mp[b] > 0){
            v.push_back(b);
        }
    }
    for(int i = 0; i < v.size(); i++){
        cout << v[i] << endl;
    }
}


Measured memory_bytes: 21804
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <set>
#include <algorithm>
#include <array>
#include <complex>
#include <string>
#include <utility>
#include <map>
#include <queue>
#include <list>
#include <functional>
#include <numeric>
#include <stack>
#include <tuple>

using namespace std;
int dx[4] = { -1,0,1,0 };
int dy[4] = { 0,1,0,-1 };
const int INF = 100000000;
const long long LINF = 1000000000000000000;
const int MOD = (int)1e9 + 7;
const double EPS = 1e-6;
using pii = std::pair<int, int>;
using pLL = std::pair<long long, long long>;
using ll = long long;
#define SORT(v) std::sort(v.begin(), v.end())

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	string s;
	cin >> s;
	if (s[5]=='1'||s[6] > '4') {
		cout << "TBD" << endl;
	}
	else if (s[6] <= '4') {
		cout << "Heisei" << endl;
	}
	return 0;
}


Measured memory_bytes: 256
#pragma GCC optimize(2)
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iomanip>
#include <cmath>
#include <iostream>
#include <algorithm>
#include <array>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <bitset>
#include <fstream>
#include <sstream>
#include <ctime>
#define fi first
#define se second
#define pb push_back
#define all(x) (x).begin(),(x).end()
#define mes(a, b) memset((a), (b), sizeof (a))
#define IosF ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0)
using namespace std;

struct Point{
    double x, y;
    Point(double a = 0, double b = 0) : x(a), y(b) {};
};

typedef Point Vector;
inline Vector operator + (Vector A, Vector B) {return Vector(A.x + B.x, A.y + B.y);}
inline Vector operator - (Vector A, Vector B) {return Vector(A.x - B.x, A.y - B.y);}
inline Vector operator * (Vector A, double x) {return Vector(A.x * x, A.y * x);}
inline Vector operator / (Vector A, double x) {return Vector(A.x / x, A.y / x);}
inline double Dot(Vector A, Vector B) {return A.x * B.x + A.y * B.y;} //向量点乘
inline double Len(Vector A) {return sqrt(Dot(A, A));}
inline double Ang(Vector A, Vector B) {return acos(Dot(A, B) / Len(A) / Len(B));} //向量夹角
inline double Cro(Vector A, Vector B) {return A.x * B.y - A.y * B.x;} //向量叉乘
inline double Area(Vector A, Vector B) {return Cro(A, B) * 0.5;} //组成三角形面积
inline Vector Rotate(Vector A, double rad) {return Vector(A.x * cos(rad) - A.y * sin(rad), A.x * sin(rad) + A.y * cos(rad));} //向量逆时针旋转角度rad
inline Vector Normal(Vector A) {double len = Len(A); return Vector(-A.y / len, A.x / len);}//求向量A的单位法线

typedef long long ll;
typedef unsigned long long ull;
const int N = 1e6 + 10;
const int M = 0x3f3f3f3f;
const int inf = 0x7fffffff;
const int mod = 9901;
const double PI = acos(-1);

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

inline void Solve() {
    int k;
    cin >> k;
    int n = k;
    int num = 1;
    while ( k % 360 != 0 ) {
        k += n;
        num ++;
    }

    cout << num << endl;
}

int main() {
    IosF;
    srand(time(NULL));
    Solve();
    return 0;
}


Measured memory_bytes: 3596
#include <bits/stdc++.h>
#define PI 3.141592653
#define rep(i,a,n) for(int i=a;i<(int)n;++i)
#define SZ(x) ((int)(x).size())	//size() unsigned -> int
#define descSort(a) sort(a.begin(),a.end(),std::greater<int>())
using namespace std;
typedef long long ll;
const ll INF = 1e9 + 7;
ll gcd(ll x,ll y){
    if(x%y==0)return y;
    return gcd(y,x%y);
}
int main(void){
    int n;
    string s;
    cin>>n>>s;
    int res=INF;
    vector<int> l(n+1),r(n+1);
    rep(i,1,n+1){
        if(s[i-1]=='#')l[i]=l[i-1]+1;
        else l[i]=l[i-1];
    }
    for(int i=n-2;i>=0;i--){
        if(s[i+1]=='.')r[i]=r[i+1]+1;
        else r[i]=r[i+1];
    }
    rep(i,0,n){
        res=min(res,l[i]+r[i]);
    }
    cout<<res<<endl;
    return 0;
}

Measured memory_bytes: 2180
N, M = list(map(int, input().split()))
As = list(map(int, input().split()))

totalvotes = sum(As)
As.sort()
found = 0
for i in range(len(As)):
    if As[i] >= 1/(4*M)*(totalvotes):
        found += 1

if found >= M:
    print('Yes')
else:
    print('No')


Measured memory_bytes: 3064
//by yjz
#include<bits/stdc++.h>
using namespace std;
#define FF first
#define SS second
#define PB push_back
#define MP make_pair
#define bged(v) (v).begin(),(v).end()
#define foreach(it,s) for(__typeof((s).begin()) it=(s).begin();it!=(s).end();it++)
typedef long long ll;
const int Imx=2147483647;
const ll Lbig=2e18;
const int mod=1e9+7;
//My i/o stream
struct fastio
{
	char s[100000];
	int it,len;
	fastio(){it=len=0;}
	inline char get()
	{
		if(it<len)return s[it++];it=0;
		len=fread(s,1,100000,stdin);
		if(len==0)return EOF;else return s[it++];
	}
	bool notend()
	{
		char c=get();
		while(c==' '||c=='\n')c=get();
		if(it>0)it--;
		return c!=EOF;
	}
}_buff;
#define geti(x) x=getnum()
#define getii(x,y) geti(x),geti(y)
#define getiii(x,y,z) getii(x,y),geti(z)
#define puti(x) putnum(x),putchar(' ')
#define putii(x,y) puti(x),puti(y)
#define putiii(x,y,z) putii(x,y),puti(z)
#define putsi(x) putnum(x),putchar('\n')
#define putsii(x,y) puti(x),putsi(y)
#define putsiii(x,y,z) putii(x,y),putsi(z)
inline ll getnum()
{
	ll r=0;bool ng=0;char c;c=_buff.get();
	while(c!='-'&&(c<'0'||c>'9'))c=_buff.get();
	if(c=='-')ng=1,c=_buff.get();
	while(c>='0'&&c<='9')r=r*10+c-'0',c=_buff.get();
	return ng?-r:r;
}
template<class T> inline void putnum(T x)
{
	if(x<0)putchar('-'),x=-x;
	register short a[20]={},sz=0;
	while(x)a[sz++]=x%10,x/=10;
	if(sz==0)putchar('0');
	for(int i=sz-1;i>=0;i--)putchar('0'+a[i]);
}
inline char getreal(){char c=_buff.get();while(c<=32)c=_buff.get();return c;}
ll qpow(ll x,ll k){return k==0?1:1ll*qpow(1ll*x*x%mod,k>>1)*(k&1?x:1)%mod;}
int n,lg2[1<<21];
int a[21][1<<21];
int go[1<<21][21][2];
int ans[1<<21];
int main()
{
	for(int i=1;i<(1<<21);i++)
	{
		if(i>1)lg2[i]=lg2[i>>1]+1;
		int l0=-1,l1=-1,len=-1;
		for(int j=20;j>=0;j--)
		{
			if((i>>j)&1)
			{
				l1=j;
				if(len==-1)len=j;
			}else l0=j;
			go[i][j][0]=l0>=len?-1:l0,go[i][j][1]=l1>=len?-1:l1;
		}
	}
	int K;
	getii(n,K);
	for(int i=0;i<=n;i++)
	{
		for(int j=0;j<(1<<i);j++)
		{
			char c=getreal();
			if(c=='1')
			{
				a[0][j|(1<<i)]=1;
			}
		}
	}
	for(int i=0;i<=n;i++)
	{
		for(int j=0;j<(1<<(n+1));j++)
		{
			if(!a[i][j])continue;
			ans[(j&((1<<i)-1))|(1<<i)]+=a[i][j];
			if(i==n)continue;
			for(int c=0;c<2;c++)
			{
				int nxt=go[j][i][c];
				if(nxt!=-1)
				{
					a[i+1][(j&((1<<i)-1))|((j>>nxt)<<i)]+=a[i][j];
				}
			}
		}
	}
//	for(int i=1;i<(1<<(n+1));i++)cerr<<ans[i]<<" ";cerr<<endl;
	pair<int,int> ANS=MP(0,0);
	int len=0;
	for(int i=1;i<(1<<(n+1));i++)
	{
		if(i>(1<<len))len++;
		if(ans[i]>=K)
		{
			ANS=min(ANS,MP(-lg2[i],i));
		}
	}
	for(int i=lg2[ANS.SS]-1;i>=0;i--)cout<<((ANS.SS>>i)&1);
	return 0;
}


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


//n桁でmから始まるるんるん数の数
//ただしm=0のときは最終結果には使えない
int startwith(int n, int m) {
  if(n==1) return 1;
  if(m==0) return startwith(n-1, 0) + startwith(n-1, 1);
  if(m==9) return startwith(n-1, 8) + startwith(n-1, 9);
  else return startwith(n-1, m-1) + startwith(n-1, m) + startwith(n-1, m+1);
}

int keta(int k) {
  int ans = 0;
  while(k>0) {
    int sum=0;
    for(int i=1; i<10; i++) sum+=startwith(ans+1, i);
    k -= sum;
    ans++;
  }

  return ans;
}

int main() {
  int k;
  cin>>k;
  int kt = keta(k);

  for(int i=1; i<kt; i++) {
    for(int j=1; j<10; j++) {
      k -= startwith(i, j);
    }
  }

  int ans[kt];
  int n = kt;
  int num = 1;
  while(kt>0) {
    if(k<=startwith(kt, num)) {
      ans[kt-1] = num;
      kt--;
      num=max(0, num-1);
    }
    else {
      k -= startwith(kt, num);
      num++;
    }
  }

  for(int i=n-1; i>=0; i--) cout<<ans[i];
  cout<<endl;

  return 0;
}

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

#define REP(i, start, count) for(int i=(start); i<(int)(count); ++i)
#define rep(i, count) REP(i, 0, count)
#define ALLOF(c) (c).begin(), (c).end()

typedef long long ll;
typedef unsigned long long ull;

int main(void) {
    int N;
    cin >> N;
    vector<int> a(N + 1);

    REP(i, 1, N + 1) cin >> a[i];

    vector<int> ans(N + 1);
    int M = 0;
    for (int i = N; i >= 1; --i) {
        int k = i + i;
        int odd = 0;
        while (k <= N) {
            odd = (odd + ans[k]) % 2;
            k += i;
        }

        if (a[i] != odd) {
            ans[i] = 1;
            M++;
        }
    }

    cout << M << endl;
    rep(i, N + 1) {
        if (ans[i] == 1) {
            cout << i;
            if (i != N) cout << " ";
        }
    }
    cout << endl;

    return 0;
}

Measured memory_bytes: 2432
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
double farm(int p,int a,int b,int c,int d,int e,int f,int s,int m){
  double ret;
  int sou=a+b+c;
  sou+=(d+e)*m;
  ret=(double)(f*s*m-p);
  ret/=(double)sou;
  return ret;
}
struct fruit{
  string name;
  double a;

};
bool asd(fruit a,fruit b){
  if(a.a!=b.a)
    return a.a> b.a;
  else 
    return a.name<b.name;
}
int main(){
  string l;
  int p,a,b,c,d,e,f,s,m;
  int k;

  cin >>k;
  while(k){
    vector<fruit> list(k);
    for(int i=0;i<k;i++){
      cin >>list[i].name;
      //   cout <<list[i].name<<endl;
      cin>>p>>a>>b>>c>>d>>e>>f>>s>>m;
      list[i].a=farm(p,a,b,c,d,e,f,s,m);
    }
    sort(list.begin(),list.end(),asd);
    for(int i=0;i<k;i++)
      cout <<list[i].name<<endl;
    cin >>k;
    cout<<"#\n";
  }
  return 0;
}

Measured memory_bytes: 1224
#define _USE_MATH_DEFINES
#include <math.h>
#include <iostream>
#include <iomanip>
#include <cstdlib>
#include <algorithm>
#include <numeric>
#include <stdio.h>
#include <vector>
#include <map>
#include <queue>

using namespace std;
typedef long long ll;

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

int main() {

    ll X,Y,A,B,C;
    cin >> X >> Y >> A >> B >> C;
    ll p[A];
    rep(i,A) cin >> p[i];
    ll q[B];
    rep(i,B) cin >> q[i];
    vector<ll> r;
    rep(i,C){
        ll R;
        cin >> R;
        r.push_back(R);
    }
    sort(p,p+A);
    sort(q,q+B);
    for(ll i=A-X;i<A;i++) r.push_back(p[i]);
    for(ll i=B-Y;i<B;i++) r.push_back(q[i]);
    sort(r.begin(),r.end());
    ll out = 0;
    rep(i,X+Y) out += r[X+Y+C-1-i];
    cout << out << endl;
    return 0;
}


Measured memory_bytes: 9004
#include<iostream>
#include<algorithm>
#include<cmath>
#include<vector>
#include<map>
#include<set>
#include<string>
#include<queue>
#include<stack>
#include<iomanip>

#define fast_io ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);

using namespace std;

#define debug(x) cout<<(#x)<<"="<<(x)<<", ";
#define debug1(x) debug(x) cout<<'\n';
#define debug2(x1, x2) debug(x1) debug(x2) cout<<'\n';
#define debug3(x1, x2, x3) debug(x1) debug(x2) debug(x3) cout<<'\n';
#define debug4(x1, x2, x3, x4) debug(x1) debug(x2) debug(x3) debug(x4) cout<<'\n';
#define debug5(x1, x2, x3, x4, x5) debug(x1) debug(x2) debug(x3) debug(x4) debug(x5) cout<<'\n';

#define fcout cout<<fixed<<setprecision(15)
#define repp(i,j,k) for(int i=j; i<k; ++i)
#define rep(i,j) repp(i,0,j)
#define rrep(i,j,k) for(int i=j; i>=k; --i)
#define all(x) (x).begin(), (x).end()
#define sort(x) sort(x.begin(), x.end())
#define lb(x,val) lower_bound(x.begin(), x.end(), val)
#define ub(x,val) upper_bound(x.begin(), x.end(), val)
#define pb(x) emplace_back(x);

typedef long long int lli;
typedef pair<int,int> pii;
typedef pair<lli,lli> pll;
typedef vector<int> vi;
typedef vector<lli> vl;
typedef tuple<int, int, lli> tiil;

//const lli M=998244353ll;
const lli M=1000000007ll;
const double D=1.0;

int main(){
	fast_io
	int a,b;
	cin>>a>>b;
	cout<<max(a*b, max(a-b,a+b));
	
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>


int main (void)
{
  int n, a, b, i;
  scanf("%d", &n);
  for(i =1; i<= n; i++){
    a = i;
    if(a %3 ==0){
      printf(" %d", i);
    } else{
      for(;;){
        b = a % 10;
        if(b == 3){
          printf(" %d", i);
          break;
        } else if(a < 10)
        {
          break;
        }

        a = a/10;
      }
    }

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

Measured memory_bytes: 1788
#include<iostream>
#include<vector>
#include<map>
#include<algorithm>
using namespace std;


typedef pair<int,int> P;
vector<P> g[30];
bool use[30];
int sum;

int dfs(int x){
  int maxi = 0;
  use[x] = true;
  for(int i=0;i<(int)g[x].size();i++){
    P e = g[x][i];
    if(use[e.first])continue;
    int tmp = dfs(e.first);
    if(g[e.first].size()!=1){
      tmp += e.second;
      sum += e.second;
    }
    maxi = max(maxi,tmp);
  }
  return maxi;
}

int main(){
  int n,a,b,t;

  while(cin>> n && n){
    for(int i=0;i<n;i++){
      g[i].clear();
      use[i] = false;
    }

   for(int i=0;i<n-1;i++){
      cin >> a >> b >> t;
      a--;b--; sum += t;
      g[a].push_back(P(b,t));
      g[b].push_back(P(a,t));
    }
   sum = 0;
   int tmp = dfs(0);
   cout << 2*sum -tmp << endl;
  }
}

Measured memory_bytes: 0
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
#define int long long int
#define M 1000000007
#define pb push_back
#define pf push_front
#define ulli unsigned long long int
#define what_is(x) cerr << #x << " is " << x << endl;
#define pi 2*acos(0.0)
#define F  first
#define S  second
#define endl '\n'
using namespace std;
using namespace __gnu_pbds;
const int INF = 1e18L+5;
const int LG = 20;
const int N = 1e5+9;
typedef tree<int,null_type,less_equal<int>,rb_tree_tag,tree_order_statistics_node_update>ordered_set;
int power(int x,int y){int res=1;while(y>0){if(y%2==1)res=(res*x)%M;x=(x*x)%M;y=y/2;}return res;}
bool isvowel(char c){if(c=='a' || c=='e' || c=='i' || c=='o' || c=='u' || c=='A' || c=='E' || c=='I' || c=='O' || c=='U')return true;return false;}
int32_t main()
{
	//cout.precision(15);
	//cout.setf(ios::fixed,ios::floatfield);
	ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	//freopen("input.txt","r",stdin);
	//freopen("output.txt","w",stdout);
	int T=1;
	//cin>>T;
	while(T--)
	{
		int i,a,b,k;
		cin>>k>>a>>b;
		for(i=a;i<=b;i++)
		{
			if(i%k==0)
			{
				cout<<"OK"<<endl;
				return 0;
			}
		}
		cout<<"NG"<<endl;
	}
}



Measured memory_bytes: 3652