akhauriyash/Code-Regression huggingface dataset:
//g++ -std=c++14 test.cpp -o test.out

#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <cassert>
#include <algorithm>
#include <functional>
#include <iostream>
#include <iomanip>
#include <vector>
#include <queue>
#include <map> 
#include <utility>
#include <limits.h>
#include <bitset>
#include <set>
using namespace std;
 
#define LL long long int
const LL INF = (LL)(1e18)+1;
const int INF_INT = 2147483647-1e6-1;
const LL mod = 1000000007ll;
const int mod_int = 1000000007;

//引用元
//http://drken1215.hatenablog.com/entry/2019/03/03/224600
//union くっつける
//find  どのグループか調べる
struct UnionFind {
    vector<LL> parent;
    
    UnionFind(LL n) : parent(n, -1) { }
    void init(LL n) { parent.assign(n, -1); }
    
    //xの属している木の根っこを返す
    LL root(LL x) {
        if (parent[x] < 0) return x;
        else return parent[x] = root(parent[x]);//経路圧縮
    }
    
    LL size(LL x) {return -parent[root(x)];}//xの属する木の要素数を求める
    bool is_same_tree(LL x,LL y) {return root(x)==root(y);}
    
    bool merge(LL x,LL y) {
        x = root(x); y = root(y);
        if (x == y) return false;
        if (parent[x] > parent[y]) swap(x, y);//xの親の方がyの親より小さくなるようにする
        parent[x] += parent[y];//経路の長さを加算
        parent[y] = x;//yの親をxとする
        return true;
    }
};

LL N,M;
LL p[100001];
LL rev_p[100001];//iがp[j]に格納されている時rev_p[i] = jとする
vector<pair<LL,LL>> xy;
 
LL ans = 0;

void solve(){
	UnionFind uf(N+1);//i,jが同じグループに所属=iとjは交換可能　なことを表す
	for(int i=0;i<M;i++){
		LL x = xy[i].first;
		LL y = xy[i].second;
		uf.merge(x,y);
	}

	for(int i=1;i<=N;i++){
		if(i==p[i]){
			ans++;
			continue;
		}
		//rev_p[i]:iが格納されているインデックス
		if(uf.is_same_tree(i,rev_p[i])){
			//インデックスi,rev_p[i]の位置にある数を交換
			LL x = i;
			LL p_x = p[x];
			LL y = rev_p[i];
			LL p_y = p[y];
			ans++;
			p[x] = p_y;
			p[y] = p_x;
			rev_p[p_x] = y;
			rev_p[p_y] = x;
			continue;
		}
	}
}

int main(){
    cin >> N >> M;
    for(int i=1;i<=N;i++){
    	cin >> p[i];
    	rev_p[p[i]] = i;
    }
    for(int i=0;i<M;i++){
    	LL x,y;
    	cin >> x >> y;
    	xy.push_back(pair<LL,LL>(x,y));
    }
 
    solve();
 
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 4208
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>

using namespace std;

typedef long long int ll;
typedef pair<ll, ll> P;
#define INF 10000000000000
#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define rep1(i, n) for(ll i = 1; i < (ll)(n); i++)
#define repN_1(i, n) for(ll i = 0; i < (ll)(n - 1); i++)
#define repM(i, n) for(ll i = (ll)(n - 1); i >= 0; i--)
template<class T>bool chmax(T& a, const T& b) { if (a < b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T& a, const T& b) { if (b < a) { a = b; return 1; } return 0; }

int main()
{
	cout << fixed << setprecision(18);
	ll a, b, n;
	ll t;
	cin >> a >> b >> n;

	if (n < b)
		t = (ll)floor((a * n) / b) - a * (ll)floor(n / b);
	else
		t = (ll)floor((a * (b - 1)) / b) - a * (ll)floor((b - 1) / b);

	cout << t << endl;
	
	return 0;
}

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

typedef long long ll;
typedef int64_t i6;

#define rep(i, n) for (ll i = 0; i < n; ++i)
#define Sort(x) sort(x.begin(), x.end())
#define Sort_rev(x) sort(x.begin(), x.end(), greater<int>())
#define ALL(v) (v).begin(), (v).end()

//π M_PI
//deg = rad*180/M_PI

char shift_char(int shift_count, char char_in)
{
    string str = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";

	int i, j;
	int num;
	for (i = 0; i < 27; i++){
		if (char_in == str[i]) {
            //num = i;
            break;
        }
	}
	//if (i >= 26) return char_in; /* この行を追加する */

	j = (i + shift_count) % 26;
/*
	if (j < 0) {
		j += 26;
	}
*/
	return str[j];
}

int main() {
    int n;
    string s;
    cin >> n >> s;
    //std::vector<string> v;
    rep(i, s.length()) {
        //v.push_back(shift_char(n, s[i]));
        //cout << v[i];
        char ss = shift_char(n, s[i]);
        cout << ss;
    }
    cout << endl;
    //cout << v << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int a[2005],n,t;
int main(){
    int n;
    scanf("%d",&n);
    for(int i=0;i<n;i++)scanf("%d",&a[i]);
    sort(a,a+n);
    for(int i=0;i<n-2;i++)for(int j=i+1;j<n-1;j++){
        t+=lower_bound(a,a+n,a[i]+a[j])-a-j-1;
    }
    printf("%d",t);
}

Measured memory_bytes: 256
S = input()
upper_S = int(S[0:2])
lower_S = int(S[2:4])

if upper_S >=1 and upper_S <=12:
    if lower_S >= 1 and lower_S <= 12:
        print('AMBIGUOUS')
    else:
        print('MMYY')
else:
    if lower_S >= 1 and lower_S <= 12:
        print('YYMM')
    else:
        print('NA')



Measured memory_bytes: 3060
io = STDIN
n=io.gets.to_i
b=io.gets.split.map(&:to_i)
a=Array.new(n,0)
if n==2
  puts b[0]*2
else
  b.unshift(0)
  a[0]=b[1]
  (1..(n-1)).each do |i|
    a[i-1]=b[i] if b[i-1]>=b[i]
    a[i]=a[i-1]
    a[i]=b[i] if b[i-1]<=b[i] && i < n-1  && b[i]<=b[i+1]
    a[i]=b[i]   if i==n-1 && a[i]<b[i]
  end
  puts a.inject(:+)
end


Measured memory_bytes: 1788
/*
    Author: Nguyen Tan Bao
    Status:
    Idea:
*/
 
#include <bits/stdc++.h>
#define FI first
#define SE second
#define EPS 1e-9
#define ALL(a) a.begin(),a.end()
#define SZ(a) int((a).size())
#define MS(s, n) memset(s, n, sizeof(s))
#define FOR(i,a,b) for (int i = (a); i <= (b); i++)
#define FORE(i,a,b) for (int i = (a); i >= (b); i--)
#define FORALL(it, a) for (__typeof((a).begin()) it = (a).begin(); it != (a).end(); it++)
//__builtin_ffs(x) return 1 + index of least significant 1-bit of x
//__builtin_clz(x) return number of leading zeros of x
//__builtin_ctz(x) return number of trailing zeros of x
 
using namespace std;
using ll = long long;
using ld = double;
typedef pair<int, int> II;
typedef pair<II, int> III;
typedef complex<ld> cd;
typedef vector<cd> vcd;
 
const ll MODBASE = 1000000007LL;
const int MAXN = 110;
const int MAXM = 1000;
const int MAXK = 16;
const int MAXQ = 200010;

int main() {
    ios::sync_with_stdio(0);
    cin.tie(nullptr);
    int m, n;
    cin >> m >> n;
    FOR(i,1,n) {
        int x;
        cin >> x;
        m -= x;
    }
    if (m < 0) cout << -1;
    else cout << m;
    return 0;
}


Measured memory_bytes: 3652
#include <iostream>
#include <cmath>
#include <map>
#include <queue>
#include <string>
#include <string>
#include <algorithm>
using namespace std;

int main(){
    long long a, b, x; cin >> a >> b >> x;
    cout << ((a) ? b/x-(a-1)/x : b/x+1)<< endl; return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <stdio.h>
#include <algorithm>
#include <functional>
#include <iostream>

using namespace std;
 
int main() {
int W, H, N, X[110]={0}, Y[110]={0}, A[110]={0};
cin >> W >> H >> N;
for(int i=1; i<=N; ++i){
  cin >> X[i] >> Y[i] >> A[i];
}
int L=0, R=W, D=0, U=H;
for(int i=1; i<=N; ++i){
  if(A[i]==1) L=max({X[i],L});
  if(A[i]==2) R=min({X[i],R});
  if(A[i]==3) D=max({Y[i],D});
  if(A[i]==4) U=min({Y[i],U}); 
}
if(R>L && U>D){
  cout << (R-L)*(U-D) << endl;
}
else {
  cout << 0 << endl;
}
}


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


int main() 
{
    int N;
    cin >> N;
    vector<pair<long long, long long>> X(N);
    for (int i = 0; i < N; i++) {
        long long x, l;
        cin >> x >> l;
        X[i] = {x-l, x+l};
    }
    sort(X.begin(), X.end(), [](pair<long long, long long>a, pair<long long, long long> b){return a.second < b.second;});
    
    int ans = 0;
    long long cur = LLONG_MIN;
    for (int i = 0; i < N; i++) {
        if (cur > X[i].first){
            continue;
        }
        ans++;
        cur = X[i].second;
    }
    cout << ans << endl;
}

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

inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<long long> VL;
typedef vector<vector<long long>> VVL;
typedef vector<string> VS;
typedef pair<int, int> P;
typedef tuple<int,int,int> tpl;

#define ALL(a)  (a).begin(),(a).end()
#define SORT(c) sort((c).begin(),(c).end())
#define REVERSE(c) reverse((c).begin(),(c).end())
#define LB(a,x) lower_bound((a).begin(), (a).end(), x) - (a).begin()
#define UB(a,x) upper_bound((a).begin(), (a).end(), x) - (a).begin()

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define RFOR(i,a,b) for(int i=(a)-1;i>=(b);--i)
#define RREP(i,n) RFOR(i,n,0)

#define en "\n"

constexpr double EPS = 1e-9;
constexpr double PI  = 3.141592653589793238462643383279;
constexpr int INF = 2147483647;
constexpr long long LINF = 1LL<<60;
constexpr long long MOD = 1000000007; // 998244353

#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << 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; }

int N, dp[1<<18][50], ans = MOD;
VI A,B;

int rec(int bit, int s, int n){
    if(dp[bit][s-1] != -1) return dp[bit][s-1];
    if(n == 0) return dp[bit][s-1] = 0;

    int ret = MOD, swp = n;
    REP(i,N){
        if(!(bit & 1<<i)) continue;
        swp--;
        int t = abs(n-i-1)%2 == 0 ? A[i] : B[i];
        if(t != s) continue;
        int prev_bit = bit ^ (1<<i);
        REP(j,t) chmin(ret, rec(prev_bit, j+1, n-1) + swp);
    }
    return dp[bit][s-1] = ret;
}

int main(void){
    cin >> N; A.resize(N); B.resize(N);
    REP(i,N) cin >> A[i]; REP(i,N) cin >> B[i];
    REP(i,1<<N)REP(j,50) dp[i][j] = -1;
    REP(i,50) chmin(ans, rec((1<<N)-1, i+1, N));
    cout << (ans<MOD ? ans : -1) << endl;
    return 0;
}

Measured memory_bytes: 51584
#include <string>
#include <iostream>
#include <math.h>
using namespace std;

typedef long long ll;

#define CPP_STR(x) CPP_STR_I(x)
#define CPP_CAT(x,y) CPP_CAT_I(x,y)
#define CPP_STR_I(args...) #args
#define CPP_CAT_I(x,y) x ## y

#define FOR(i, start, end) for(ll i = (start), CPP_CAT(i,xxxx_end)=(end); i < CPP_CAT(i,xxxx_end); ++i)
#define REP(i, n) FOR(i, 0, n)

ll digits(ll num) {
    ll count = 0;
    while (num > 0) {
        num /= 10;
        count++;
    }
    return count;
}

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

    ll ans = LLONG_MAX;
    FOR(i, 1, N+1) {
        ll a = i;
        ll b = N / a;
        if (a > b) {
            break;
        }
        if (a * b == N) {
            ll d = max(digits(a), digits(b));
            ans = min(ans, d);
        }
    }
    cout << ans << endl;
    
    return 0;
}

Measured memory_bytes: 888
#include<bits/stdc++.h>
using namespace std;
int main()
{
int a;long long int sum=0;
cin>>a;
for(int i=1;i<=a;i++)
{
if(i%3==0||i%5==0)
{}
else
{
sum=sum+i;
}


}
cout<<sum<<"\n";

}


Measured memory_bytes: 3636
N,x = map(int,input().split())
A = sorted(map(int,input().split()))

S =[0]+[0 for i in range(N)]
for i in range(N):
  S[i+1]=S[i]+A[i]
  #print(S)
  if S[i+1]>x:
    print(i)
    exit()
if S[-1]==x:
  print(N)
else:
  print(N-1)

Measured memory_bytes: 38384
<?php
list($n) = ints();
for ($a = 1; $a <= 3500; ++$a) {
    for ($b = $a; $b <= 3500; ++$b) {
        $x = $n * $a * $b;
        $y = 4 * $a * $b - $n * ($a + $b);
        if ($y > 0 && $x % $y === 0) {
            $c = intdiv($x, $y);
            break 2;
        }
    }
}
echo implode(' ', [$a, $b, $c]);
function ints()
{
    return array_map('intval', explode(' ', trim(fgets(STDIN))));
}


Measured memory_bytes: 16296
import sys

read = sys.stdin.buffer.read
input = sys.stdin.buffer.readline
inputs = sys.stdin.buffer.readlines

# mod=10**9+7
# rstrip().decode('utf-8')
# map(int,input().split())
# import numpy as np

def main():
	n=int(input())
	A=list(map(int,input().split()))
	
	ans="YES"
	
	if sum(A)%2:
		ans="NO"
	
	print(ans)
	
if __name__ == "__main__":
	main()


Measured memory_bytes: 56944
#include <bits/stdc++.h>
const double PI = acos(-1);
#define rep(i,n) for (int i = 1; i < (n + 1); ++i)
using namespace std;
using ll = long long;
using p = pair<int, int>;
double r;

int main() {
	cin >> r;
	cout << r * 2 * PI;
	return 0;
}


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

using namespace std;

#define debug(n) cerr << #n << ':' << n << endl;
#define dline    cerr << __LINE__ << endl;

using ll = long long;
template<class T, class U> using P = pair<T,U>;
template<class T> using Heap = priority_queue<T>;
template<class T> using heaP = priority_queue<T,vector<T>,greater<T>>;
template<class T,class U> using umap = unordered_map<T,U>;
template<class T> using uset = unordered_set<T>;

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

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

template<class T, size_t N, class U>
void Fill(T (&a)[N], const U&v){
    fill((U*)a,(U*)(a+N),v);
}

template<class T>
istream& operator >> (istream&is, vector<T>&v){
  for(auto&e:v)is >> e;
  return is;
}

int main(){
  int n,k; cin >> n >> k;
  vector<int> v(n); cin >> v;
  sort(v.begin(), v.end());
  int sum = 0;
  for(int i = 0; i < k; ++i)sum += v[i];
  cout << sum << endl;
  return 0;
}


Measured memory_bytes: 3628
#include<iostream>
#include<map>
#include<set>
#include<string>
#include<algorithm>
#include<cmath>
#include<vector>
#include<queue>
#include<stack>
#include<limits>
#include<sstream> 
#include<unordered_map>      

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef int itn;
typedef vector<int> vi;
typedef vector<ll> vl;

const int inf = numeric_limits<int>::max() >> 2;
const ll linf = numeric_limits<ll>::max() >> 2;
const ull ulinf = numeric_limits<ull>::max() >> 2;
const double pi = acos(-1);
const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};
const int dx8[8]={-1,0,1,-1,1,-1,0,1};
const int dy8[8]={-1,-1,-1,0,0,1,1,1};

#define p_queue(i) priority_queue<i> 
#define rp_queue(i) priority_queue<i, vector<i>, greater<i>> 
#define umap(i,j) unordered_map<i,j>
#define P(p) cout<<(p)<<endl
#define PS(p) cout<<(p)<< " "
#define IN cin >> 
#define rep(i,m,n) for(int i = (m); i < (int)(n); i++)
#define rrep(i,m,n) for(int i = (m-1); i >= (int)(n); i--)
#define inrep(n,a) for(int i = 0; i < (int)(n); i++)cin >> a[i];
#define mod(i) ((i)%(ll)(1e9 + 7))
#define divm(a,b) (mod(a * modpow((ll)b,(ll)(1e9+5))))
#define rsort(a,b,c) sort(a, b, greater<c>())
#define vsort(v) sort(v.begin(), v.end());
#define rvsort(v) sort(v.end(), v.begin());
#define ft first
#define sd second
#define pb push_back
#define it insert
#define sz(x) ((int)(x).size())
#define lb(a,n,k) (lower_bound(a,a+n,k) - a) 
#define vlb(a,k)  (lower_bound(a.begin(),a.end(),k) - a.begin())
#define ub(a,n,k) (upper_bound(a,a+n,k) - a) 
#define vub(a,k)  (upper_bound(a.begin(),a.end(),k) - a.begin())
#define YES cout<<"YES"<< endl
#define NO cout<<"NO"<<endl
#define Yes cout<<"Yes"<<endl
#define No cout<<"No"<<endl  
#define yes cout<<"yes"<<endl
#define no cout<<"no"<<endl
#define ret return

ll modpow(ll i,ll j){ ll tmp=1; while(j){ if(j%2)tmp=mod(tmp*i);i=mod(i*i);j/=2;}return tmp;}
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }

vector<string> split(const string &str, char sep){
    vector<string> v;
    stringstream ss(str);
    string buffer;
    while( getline(ss, buffer, sep) ) {
        v.push_back(buffer);
    }
    return v;
}

//ll ncr[100][100];
//ll nCr(int n, int r){if(n==r) ret ncr[n][r] = 1; if(r==0) ret ncr[n][r] = 1; if(r==1) ret ncr[n][r] = n;if(ncr[n][r]) ret ncr[n][r]; ret ncr[n][r] = nCr(n-1,r) + nCr(n-1,r-1);}

//ll npr[100][100]={};
//ll nPr(int n,int r){if(npr[n][r])ret npr[n][r];if(r==0)ret npr[n][r] = 1;if(r==1)ret npr[n][r] = n;ret npr[n][r] = n * nPr(n-1,r-1);}

//ll nHr(int n,int r){ret nCr(n+r-1,r);}

///////////////////////////////////////////////////////////////////////////


int main(){
    
    ll a,b;
    cin >> a >> b;
    ll ans = 0;
    
    if(a == b){
	P(a);
	ret 0;
    }
    b++;
    ll c = 2;
    rep(i,0,60){
	ll l = a/c*(c/2) + max(a%c - c/2, 0LL);
	ll r = b/c*(c/2) + max(b%c - c/2, 0LL);
	
	if((r-l)&1)ans += 1LL << i;
	
	c *= 2;
	//	if(c > b)break;
    }
    P(ans);
    return  0;
}


Measured memory_bytes: 256
# B - KEYENCE String
def is_keyence_string():
	for i in range(1, len(key)):
		left = key[:i]
		right = key[i-len(key):]
		
		if S.startswith(left) and S.endswith(right):
			return True
	
	return False


S = input().strip()
key = 'keyence'

if S.startswith(key):
	print('YES')
elif S.endswith(key):
	print('YES')
elif is_keyence_string():
	print('YES')
else:
	print('NO')

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

using namespace std;

const int inf = 1e9 + 7;

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    int n;
    cin >> n;
    vector <vector <int> > a(n, vector <int> (3, 0));
    for (int i = 0; i < n; i++) {
        cin >> a[i][0] >> a[i][1] >> a[i][2];
    }
    vector <int> dp(3, 0);
    for (int i = 0; i < n; i++) {
        vector <int> go(3, 0);
        for (int j = 0; j < 3; j++) {
            for (int k = 0; k < 3; k++) {
                if (j != k) {
                    go[j] = max(go[j], dp[k] + a[i][j]);
                }
            }
        }
        dp = go;
    }
    cout << *max_element(dp.begin(), dp.end()) << '\n';
    return 0;
}


Measured memory_bytes: 5760
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (int)(n); i++)
#define REP(i,n) for (int i = 1; i < (int)(n); i++)
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define vout(x) rep(i,x.size()) cout << x[i] << " "
template<class T> bool chmin(T &a, T b) {if(a>b) {a=b;return 1;}return 0;}
template<class T> bool chmax(T &a, T b) {if(a<b) {a=b;return 1;}return 0;}
using namespace std;
using vint = vector<int>;
using vvint = vector<vector<int>>;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using P = pair<int,int>;
const int inf = 1e9;
const ll inf_l = 1e18;
const int MAX = 1e5;

const int mod = 1e9+7;
struct mint {
    ll x;
    mint (ll x = 0) : x((x%mod+mod)%mod) {}
    mint operator -() const {return mint(-x);}
    mint& operator +=(const mint a) {
        if ((x += a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator -=(const mint a) {
        if ((x += mod-a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator *=(const mint a) {(x *= a.x) %= mod; return *this;}
    mint operator +(const mint a) const {return mint(*this) += a;}
    mint operator -(const mint a) const {return mint(*this) -= a;}
    mint operator *(const mint a) const {return mint(*this) *= a;}
    mint pow(ll t) const {
        if (!t) return 1;
        mint a = pow(t>>1);
        a *= a;
        if (t&1) a *= *this;
        return a;
    }
    mint inv() const {return pow(mod-2);}
    mint operator /=(const mint a) {return *this *= a.inv();}
    mint operator /(const mint a) {return mint(*this) /= a;}
};
istream& operator >>(istream &is, const mint &a) {return is >> a.x;}
ostream& operator <<(ostream &os, const mint &a) {return os << a.x;}

mint dp[25][1<<21];

int main() {
    int n; cin >> n;
    vvint a(n,vint(n));
    rep(i,n)rep(j,n) cin >> a[i][j];
    dp[0][0] = 1;
    REP(i,n+1) {
        rep(j,1<<n) {
            if (__builtin_popcount(j) != i-1) continue;
            rep(k,n) {
                if (a[i-1][k] == 1) dp[i][j|(1<<k)] += dp[i-1][j];
            }
        }
    }
    cout << dp[n][(1<<n)-1] << endl;
}

Measured memory_bytes: 409856
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (int)(n); i++)
#define REP(i,n) for (int i = 1; i < (int)(n); i++)
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define debug(var) do{cout << #var << " : "; view(var);}while(0)
template<class T> bool chmin(T &a, T b) {if(a>b) {a=b;return 1;}return 0;}
template<class T> bool chmax(T &a, T b) {if(a<b) {a=b;return 1;}return 0;}
using namespace std;
template<class T> void view(T e) {cout << e << endl;}
template<class T> void view(const vector<T> &v) {for(const auto &e : v){cout << e << " ";} cout << endl;}
template<class T> void view(const vector<vector<T>> &vv) {for(const auto &v : vv){view(v);}}
using vint = vector<int>;
using vvint = vector<vector<int>>;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using P = pair<int,int>;
const int inf = 1e9;
const ll inf_l = 1e18;
const int MAX = 1e5;

vint a, f;
int n;
ll k;

bool check(ll x) {
    ll ct = 0;
    rep(i,n) ct += max((ll)0,a[i]-x/f[i]);
    return ct <= k;
}

int main() {
    cin >> n >> k;
    a.resize(n); 
    f.resize(n);
    rep(i,n) cin >> a[i];
    rep(i,n) cin >> f[i];
    sort(rall(a));
    sort(all(f));
    ll l = -1;
    ll r = 1e12;
    while (r-l > 1) {
        ll mid = (l+r)/2;
        if (check(mid)) r = mid;
        else l = mid;
    }
    cout << r << endl;
}

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

int main()
{
	constexpr auto to_bin = [](int64_t n) -> string {
		string s;
		for (; n; n >>= 1)
		{
			s += "01"[n & 1];
		}
		reverse(s.begin(), s.end());
		return s;
	};
	int64_t n;
	cin >> n;
	if (n == 0)
	{
		cout << 0 << endl;
		return 0;
	}
	vector<int64_t> a((1 << 20)), b((1 << 20));
	for (int i = 0; i < (1 << 20); i++)
	{
		int64_t p = 0, q = 0;
		for (int j = 0; j < 20; j++)
		{
			if ((i >> j) & 1)
			{
				p += (1ll << (2 * j));
				q += (1ll << (2 * j + 1));
			}
		}
		a[i] = p;
		b[i] = q;
	}
	for (int i = 0; i < (1 << 20); i++)
	{
		int64_t m = n - a[i];
		m *= -1;
		auto itr = lower_bound(b.begin(), b.end(), m);
		int j = distance(b.begin(), itr);
		if (*itr == m)
		{
			string ans;
			for (; i || j; i >>= 1, j >>= 1)
			{
				ans += "01"[i & 1];
				ans += "01"[j & 1];
			}
			reverse(ans.begin(), ans.end());
			int k = 0;
			for (;; k++)
			{
				if (ans[k] == '1')
				{
					break;
				}
			}
			cout << ans.substr(k, ans.size()) << endl;
			break;
		}
	}
	return 0;
}

Measured memory_bytes: 16640
#atcoder template
def main():
    import sys
    imput = sys.stdin.readline
    #文字列入力の時は上記はerrorとなる。
    #ここにコード
    #input
    n, m, k = map(int, input().split())
    a = list(map(int, input().split()))
    b = list(map(int, input().split()))

    #output
    import itertools
    A = [0] + list(itertools.accumulate(a))
    B = [0] + list(itertools.accumulate(b))

    #A[i] + B[j] <= Kとなるi, jでi+jが最大になるもの

    answer = 0
    j = m
    for i in range(n+1):
        if A[i] > k:
            break
        while B[j] > k - A[i]:
            j -= 1
        answer = max(answer, i+j)
        
    print(answer)

    #N = 1のときなどcorner caseを確認！
if __name__ == "__main__":
    main()

Measured memory_bytes: 135556
package main
import (
  "fmt"
  "bufio"
  "os"
  "strings"
)

var sc = bufio.NewScanner(os.Stdin)
func main() {
  sc.Scan()
  strScan := sc.Text()
  ans := "Yes"
  
  strlen := len(strScan)
  for i:=0; i<strlen; i++ {
    even := 0
    odd := strings.Index("RUD",fmt.Sprintf("%c",strScan[i]))
    if i+1 < strlen {
	  even = strings.Index("LUD",fmt.Sprintf("%c",strScan[i+1]))
    }
    if odd == -1 || even == -1 { 
      ans = "No"
      break 
    }
    i++
  }
  
  fmt.Println(ans)
}


Measured memory_bytes: 640
import math

n,k = map(int,input().split())
ans = 0 

if n<= k-1:
  for i in range(1,n+1):
    ans += 0.5**(math.ceil(math.log2(k/i)))
    
  print(ans*(1/n))
  
else:
  for j in range(1,k):
    ans += 0.5**(math.ceil(math.log2(k/j)))
    
  print(ans*(1/n) + ((n-k+1)/n))

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define FOR(i, m, n) for (int i = m; i < (n); i++)
#define RFOR(i, m, n) for (int i = (m - 1); i >= 0; i--)
#define REP(i, n) FOR(i, 0, n)
#define RREP(i, n) RFOR(i, n, 0)
#define ALL(v) v.begin(), v.end()
#define RALL(v) v.rbegin(), v.rend()
using namespace std;
typedef long long ll;
const int mod = 1e9 + 7;

ll gcd(ll x, ll y) { return y ? gcd(y, x % y) : x; }

int main() {
  string s;
  cin >> s;

  if (regex_match(s, regex("(dream(er)?|(erase(r)?))*")))
    cout << "YES" << endl;
  else
    cout << "NO" << endl;
  return 0;
}

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

int main(){
    char b;
    cin >> b;

    if(b == 'A')
        cout << 'T' << endl;
    else if(b == 'C')
        cout << 'G' << endl;
    else if(b == 'T')
        cout << 'A' << endl;
    else if(b == 'G')
        cout << 'C' << endl;

}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define faster_io ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define sz 200004
#define ll long long

int main()
{
    faster_io
    int n,x = 1,m;
    int a[] = {0,9,90,900,9000,90000};
    string s;
    cin>>s;

    int nn = s.size();
    n = 0,m=0;
    for(int i=nn-1;i>=0;i--){
        n+=(x*(s[i]-'0'));
        x*=10;
    }

    int sum = 0;
    for(int i=1;i<nn;i+=2){
        sum+=a[i];
    }

    if(nn%2==1) sum+=(n-(x/10)+1);

    cout<<sum<<endl;

    return 0;
}



Measured memory_bytes: 256
#include<stdio.h>
void print(int[][3][10]);
void print(int x[][3][10]){
    int o,p,q;
    char y[21]="####################";
    for(o=0;o<4;o++){
        for(p=0;p<3;p++){
            for(q=0;q<10;q++){
                printf(" %d",x[o][p][q]);
            }
            printf("\n");
        }
        if(o<3){
            printf("%s\n",y);
        }
    }
    return;
}
int main(void){
    int b,f,r,v,i,n;
    int a[4][3][10]={0};
    scanf("%d",&n);
    for(i=0;i<n;i++){
        scanf("%d %d %d %d",&b,&f,&r,&v);
        a[b-1][f-1][r-1]+=v;
    }
    print(a);
    return 0;
}


Measured memory_bytes: 2040
import bisect
n = int(input())
al = list(map(int, input().split()))
bl = list(map(int, input().split()))
cl = list(map(int, input().split()))
al.sort()
bl.sort()
cl.sort()
ans = 0
tmp1 = [n]*n
tmp2 = [n]*n
for i in range(n):
    j = bisect.bisect_left(al, bl[i])
    tmp1[i] = j
for i in range(n):
    j = bisect.bisect_right(cl, bl[i])
    tmp2[i] = n-j
for i in range(n):
    ans += tmp1[i]*tmp2[i]
print(ans)


Measured memory_bytes: 106340
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=(a);i<=(b);i++)
#define per(i,a,b) for(int i=(a);i>=(b);i--)
#define pii pair<int,int>
#define pll pair<ll,ll>
#define mp make_pair
#define pb push_back
#define fi first
#define se second
using namespace std;
typedef long long ll;
const int maxn = 2e5 + 5;
const int maxc = 26;
const int inf = 0x3f3f3f3f;
const ll mod = 1e9 + 7;
const ll INF = 0x3f3f3f3f3f3f3f3f;
const double pi = acos(-1.0);
const double eps = 1e-8;
inline int read(){
    int f = 1,x = 0; char ch = getchar();
    while(ch < '0' || ch > '9'){if(ch == '-')f = -1;ch = getchar();}
    while(ch >= '0' && ch <= '9'){x = x * 10 + ch - 48;ch = getchar();}
    return f * x;
}
ll gcd(ll a,ll b){return !b?a:gcd(b,a%b);}
ll lcm(ll a,ll b){return a / gcd(a,b) * b;}
ll qw(ll x,ll y){ll ans = 1;while(y){if(y&1) ans *= x;x *= x;y >>= 1;}return ans;}
ll poww(ll x,ll y,ll p){ll ans = 1;while(y){if(y & 1) ans = ans * x % p;x = x * x % p;y >>= 1;}return ans % p;}
bool is_prime(ll x){if(x <= 1) return 0;for(ll i = 2;i * i <= x;i++){if(x % i == 0) return 0;}return 1;	}
string s;
int main()
{
//	ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
	cin >> s;
	if(s == "ABC") cout << "ARC" << endl;
	else cout << "ABC" << endl; 
	return 0;	
}

Measured memory_bytes: 3620
#include <stdio.h>

int O[1000000],kaisuu;

int BS(int key)
{
  int right = kaisuu;
  int left  = 0;
  int mid;
  while ( left < right )
    {
      mid = (right + left) / 2;
      if ( key == O[mid] ) return 1;
      else if ( key > O[mid]  ) left = mid + 1;
      else if ( key < O[mid]) right = mid;
    }
  return 0;
}

int main()
{
  int i,t,a,goukei = 0;

  scanf("%d", &kaisuu);
  for (i = 0; i < kaisuu; i++)
    {
      scanf("%d", &O[i]);
    }

  scanf("%d",&t);
  for (i = 0; i < t;i++)
  {
    scanf("%d",&a);
    if(BS(a)) goukei++;
  }
  printf("%d\n",goukei);

  return 0;
}



Measured memory_bytes: 2960
#include <bits/stdc++.h>
#define int long long
#define pii pair <int,int>
#define piii pair < pair<int,int> ,int>
#define f first
#define s second
#define pb push_back
#define MOD 1000000007
#define INF 100000000000000000

using namespace std;

main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    string s,t;
    cin>>n>>s>>t;
    int i,ans=2*n;
    for(i=1;i<=n;i++)
    {
        if(s.substr(n-i)==t.substr(0,i))
        {
            ans=2*n-i;
        }
    }
    cout<<ans;
}


Measured memory_bytes: 256
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.NoSuchElementException;

public class Main implements Runnable{
	String s;
	public void solve() {
		s = next();
		ArrayList<Integer> list = new ArrayList<Integer>();

		for(int i = 0;i < 10;i++){
			char[] ch = s.toCharArray();
			for(int j = 0;j < 12;j++)
				if(ch[j] == '?')
					ch[j] = (char)(i + '0');
			int digit = 0;
			for(int j = 11;j >= 1;j--){
				int Q = j >= 7 ? j - 5 : j + 1;
				digit += (ch[(11-j)]-'0') * Q;
			}
			digit %= 11;
			if(digit <= 1)digit = 0;
			else digit = 11 - digit;

			if(digit+'0' == ch[11])list.add(i);
		}

		if(list.size() > 1)out.println("MULTIPLE");
		else out.println(list.get(0));
	}

	public static void main(String[] args) {
		new Thread(null,new Main(),"",32 * 1024 * 1024).start();
	}

	/* Input */
	private static final InputStream in = System.in;
	private static final PrintWriter out = new PrintWriter(System.out);
	private final byte[] buffer = new byte[2048];
	private int p = 0;
	private int buflen = 0;

	private boolean hasNextByte() {
		if (p < buflen)
			return true;
		p = 0;
		try {
			buflen = in.read(buffer);
		} catch (IOException e) {
			e.printStackTrace();
		}
		if (buflen <= 0)
			return false;
		return true;
	}

	public boolean hasNext() {
		while (hasNextByte() && !isPrint(buffer[p])) {
			p++;
		}
		return hasNextByte();
	}

	private boolean isPrint(int ch) {
		if (ch >= '!' && ch <= '~')
			return true;
		return false;
	}

	private int nextByte() {
		if (!hasNextByte())
			return -1;
		return buffer[p++];
	}

	public String next() {
		if (!hasNext())
			throw new NoSuchElementException();
		StringBuilder sb = new StringBuilder();
		int b = -1;
		while (isPrint((b = nextByte()))) {
			sb.appendCodePoint(b);
		}
		return sb.toString();
	}

	public int nextInt() {
		return Integer.parseInt(next());
	}

	public long nextLong() {
		return Long.parseLong(next());
	}

	public double nextDouble() {
		return Double.parseDouble(next());
	}

	@Override
	public void run() {
		out.flush();
		new Main().solve();
		out.close();

	}
}

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

int n;
string s[10005];
int ans;
int f,m,r;

int main(){

    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);

    cin>>n;
    for(int i=1;i<=n;i++){
        cin>>s[i];
        for(int j=0;j<s[i].size()-1;j++){
            if(s[i][j]=='A'&&s[i][j+1]=='B')ans++;
        }
        if(s[i][0]=='B'&&s[i][s[i].size()-1]=='A'){
            m++;
            continue;
        }
        if(s[i][s[i].size()-1]=='A'){
            f++;
            continue;
        }
        if(s[i][0]=='B'){
            r++;
            continue;
        }
    }
    if(f>0&&r>0){
        f--;
        r--;
        ans+=m+1;
        m=0;
    }
    int k=min(f,r);
    ans+=k;
    f-=k;
    r-=k;
    if(m>0){
        ans+=m-1;
        m=0;
        if(f||r)ans++;
    }
    cout<<ans<<endl;

    return 0;
}

Measured memory_bytes: 768
#include <stdio.h>

int main(void) {
	int w,h,x,y,r;
	scanf("%d %d %d %d %d",&w,&h,&x,&y,&r);

if((x-r>=0)&&(x+r<=w)&&(y-r>=0)&&(y+r<=h)){
	printf("Yes\n");
}
else{
	printf("No\n");
}
	return 0;
}



Measured memory_bytes: 2100
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <fstream>
#include <sstream>
#include <set>
#include <map>
#include <vector>
#include <list>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <string>
#include <stack>
#include <queue>
#include <bitset>     //UWAGA - w czasie kompilacji musi byc znany rozmiar wektora - nie mozna go zmienic
#include <cassert>
#include <iomanip>        //do setprecision
#include <ctime>
#include <complex>
using namespace std;

#define FOR(i,b,e) for(int i=(b);i<(e);++i)
#define FORQ(i,b,e) for(int i=(b);i<=(e);++i)
#define FORD(i,b,e) for(int i=(b)-1;i>=(e);--i)
#define REP(x, n) for(int x = 0; x < (n); ++x)

#define ST first
#define ND second
#define PB push_back
#define PF push_front
#define MP make_pair
#define LL long long
#define ULL unsigned LL
#define LD long double
#define pii pair<int,int>
#define pll pair<LL,LL>
#define vi vector<int>
#define vii vector<vi>

const double pi = 3.14159265358979323846264;
const int mod=1000000007;

int main(){
	string s;
	cin>>s;
	map<string,int> mp;
	mp["SUN"]=7;
	mp["MON"]=6;
	mp["TUE"]=5;
	mp["WED"]=4;
	mp["THU"]=3;
	mp["FRI"]=2;
	mp["SAT"]=1;
	cout<<mp[s]<<endl;

}


Measured memory_bytes: 256
#include<cstdio>
#include<iostream>
#include<string>
#include<algorithm>
#include <math.h> 

using namespace std;
// a <b
int gcd(int a, int b)
{
	if (a > b) swap(a, b);
	while (a != 0)
	{
		int temp = a;
		a = b % a;
		b = temp;
	}

	return b;
}
int main(void)
{
	int N;
	const int SIZE = 100000;
	int a[SIZE];
	int smallest;
	cin >> N;

	for (int i = 0; i < N; i++)
	{
		cin >> a[i];
	}
	smallest = a[0];
	for (int i = 1; i < N; i++)
	{
		smallest = gcd(smallest, a[i]);
		
	}
	cout << smallest;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
#define ll long long
#define pq priority_queue
using namespace std;
const ll INF=(ll)1e9;
const ll MOD=(ll)1e9+7;
const ll MAX=510000;
vector<int> dx={1,0,-1,0},dy={0,1,0,-1};
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; }
ll gcd(ll a, ll b) {
  if (b==0) return a;
  else return gcd(b,a%b);
}
ll lcm(ll a, ll b) {
  ll g=gcd(a,b);
  return a/g*b;
}
int main(){
   ll K,a=0,ans=0;
   cin>>K;
   vector<ll> v(K*K);
   for(ll i=1;i<=K;i++){
       for(ll j=1;j<=K;j++){
           v[a]=gcd(i,j);
           a++;
       }
   }
   for(ll i=0;i<v.size();i++){
       for(ll j=1;j<=K;j++){
           ans+=gcd(v[i],j);
       }
   }
   cout<<ans<<endl;
}

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

typedef long long ll;
const ll INF = 1010000000000000017LL;
const ll MOD = 1000000007LL;

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

//#define DEBUG(fmt, ...)
#define DEBUG(fmt, ...) fprintf(stderr, fmt "\n", ##__VA_ARGS__)

int main(){
    std::cout<<std::fixed<<std::setprecision(10);

    ll N;

    cin >> N;
    unordered_set<string> m;
    REP(i, N){ 
        string S;
        cin >> S;
        m.insert(S);
    }

    cout << m.size() << endl;
}


Measured memory_bytes: 17792
import java.io.BufferedReader
import java.io.InputStreamReader
import java.io.PrintWriter
import java.util.*
import kotlin.math.abs
import kotlin.math.max
import kotlin.math.sqrt

val br = BufferedReader(InputStreamReader(System.`in`))
val out = PrintWriter(System.out)

fun main() {
    br.use { out.use {
        solve()
        out.flush()
    } }
}

fun solve() {
    val (h, w) = readIntegerList()
    val n = readInteger()
    val aList = readIntegerList()
    val ans = Array(h) { IntArray(w) }
    var currentA = 0
    var count = 0
    for (i in 0 until h) {
        for (j in 0 until w) {
            val x = if (i % 2 == 0) j else w - j - 1
            ans[i][x] = currentA + 1
            count++

            if (count == aList[currentA]) {
                count = 0
                currentA++
            }
        }
    }

    for (row in ans) {
        out.println(row.joinToString(" "))
    }
}

fun readInteger() = Integer.parseInt(br.readLine())
fun readLong() = java.lang.Long.parseLong(br.readLine())
fun readStringList() = br.readLine()!!.split(' ')
fun readIntegerList() = readStringList().map(Integer::parseInt)
fun readLongList() = readStringList().map(java.lang.Long::parseLong)
fun readDoubleList() = readStringList().map(java.lang.Double::parseDouble)


Measured memory_bytes: 42204
def solve(arr, m):
	dict = {}
	return solve_rec(0, arr, m, dict)

def solve_rec(i, arr, m, dict):
	key = str(i) + '-' + str(m)
	res = False
	if key in dict:
		res = dict[key]
	elif m == 0:
		res = True
	elif i >= len(arr):
		res = False
	else:
		res1 = solve_rec(i + 1, arr, m, dict)
		res2 = solve_rec(i + 1, arr, m - arr[i], dict)
		res = res1 or res2	
	dict[key] = res
	return res

n = int(input())
arr = list(map(int, input().split()))
q = int(input())
targets = list(map(int, input().split()))

for i in range(q):
	res = solve(arr, targets[i])
	if res == True:
		print('yes')
	else:
		print('no')



Measured memory_bytes: 6416
#include <bits/stdc++.h>
#define IOS ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define add push_back
#define endl "\n"
const int INF = 0x3f3f3f3f;
const double pi = acos(-1);
using ll = long long;
using namespace std;

int n, arr[100001], cnt[100001], mx;
int main() {
    IOS
    cin >> n;
    for (int i = 1; i <= n; ++i) {
        cin >> arr[i];
        if (arr[i] <= arr[i-1]) {
            cnt[i] = 1 + cnt[i-1];
        }
        mx = max(mx, cnt[i]);
    }
    cout << mx << endl;

    return 0;
}






Measured memory_bytes: 1024
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()
//#pragma GCC optimize ("-O3")
using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
typedef long long ll; const int inf = INT_MAX / 2; const ll infl = 1LL << 60;
template<class T>bool chmax(T& a, const T& b) { if (a < b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T& a, const T& b) { if (b < a) { a = b; return 1; } return 0; }
//---------------------------------------------------------------------------------------------------
/*---------------------------------------------------------------------------------------------------
　　　　　　　　　　　 ∧＿∧
　　　　　 ∧＿∧ 　（´<_｀ ）　 Welcome to My Coding Space!
　　　　 （ ´_ゝ`）　/　 ⌒i     @hamayanhamayan0
　　　　／　　　＼　 　  |　|
　　　 /　　 /￣￣￣￣/　　|
　 ＿_(__ﾆつ/　    ＿/ .| .|＿＿＿＿
　 　　　＼/＿＿＿＿/　（u　⊃
---------------------------------------------------------------------------------------------------*/














int N, M, S[5], C[5];
//---------------------------------------------------------------------------------------------------
void _main() {
	cin >> N >> M;
	rep(i, 0, M) cin >> S[i] >> C[i], S[i]--;

	rep(ans, 0, 1000) {
		string s = to_string(ans);
		if (s.length() != N) continue;

		bool ok = true;
		rep(i, 0, M) rep(j, 0, N) if (j == S[i] && (s[j] - '0') != C[i]) ok = false;
		if (ok) {
			cout << ans << endl;
			return;
		}
	}

	cout << -1 << endl;
}







Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
#define clr(i, j)     memset(i, j, sizeof(i))
#define pb            push_back
 #define PI acos(-1)
 #define MOD ((int)1e9+7)
typedef long long     ll;
 
//-*-*-*-*-*-*-*-*-
 
 

 
const int N=2e5+100;
ll visited[100005];
//ll a[200000];
 

#define lop(i,n) for(int i=0;i<n;++i)
//ll n,m,mod;

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

const int MAX = 2e5 + 10 ;
void finis(){cout<<-1;}
vector<ll>v[1000000];


ll h,w,n,m,k;
ll wa,tle,re,ac;
char z[100][100];
char a[100][100];
char b[100][100];
ll ans;




void goo(int i,int mask,int mask2){
    if(i==w){
        ll kk=0;
        for(int j=0;j<h;j++){
            if(mask&(1<<j)){continue;}
            for(int jj=0;jj<w;jj++){
                if(mask2&(1<<jj)){continue;}
                kk+=(a[j][jj]== '#');
            }
        }if(kk==k){ans++;}
        return;
        
    }
     
    goo(i+1,mask,mask2);
   
    
    goo(i+1,mask,mask2|(1<<i));
}
void go(int i,int mask){
    if(i==h){goo(0,mask,0);return;}
   
     go(i+1,mask);
     
    go(i+1,mask|(1<<i));
   
}
int main()
{  ios::sync_with_stdio(0);
cin.tie(0);
cin>>h>>w>>k;

    for(int i=0;i<h;i++){
        for(int j=0;j<w;j++){
            cin>>a[i][j];
            b[i][j]=a[i][j];
        }
        
    }go(0,0);
    cout<<ans;
}


Measured memory_bytes: 27032
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MOD=1e9+7;
const int INF=2e9;

int main(){
    int a[]={1,3,1,2,1,2,1,1,2,1,2,1};
    int x,y;
    cin>>x>>y;
    if(a[x-1]==a[y-1])cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define ALL(v) (v).begin(), (v).end()
using ll = long long;
using P = pair<int, int>;
constexpr int INF = 1e9;
constexpr long long LINF = 1e18;
constexpr long long MOD = 1e9 + 7;

signed main() {
    int n;
    cin >> n;
    ll dp[n + 1] = {};
    for (int i = 1; i <= n; i++) {
        for (int j = 0; j <= n; j += i){
            dp[j]++;
        }
    }
    ll ans = 0;
    for (int i = 1; i <= n; i++){
        ans += dp[i] * i;
    }
    cout << ans << endl;
    return 0;
}

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

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

int main()
{   
    int n;
    cin >> n;
    
    set<string> S;

    for (int i = 0; i < n; i++) {
        string str, word;
        cin >> str;

        if (str == "insert") {
            cin >> word;
            S.insert(word);

        }

        else if (str == "find") {
            cin >> word;
            if (S.count(word)) {
                cout << "yes" << endl;
            }

            else {
                cout << "no" << endl;
            }
        }
    }
}


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

int main(){
	cin.tie(0),ios::sync_with_stdio(false);
	string s,t; cin>>s>>t;
	string ans; ans+='z'+1;
	for(int i=0;i+t.size()<=s.size();++i){
		bool yes=true; string temp=s;
		for(int j=0,k=i;j<t.size();++j,++k){
			if(t.at(j)!=s.at(k)&&s.at(k)!='?'){
				yes=false;
			}
			temp.at(k)=t.at(j);
		}
		if(yes){
			replace(temp.begin(),temp.end(),'?','a');
			ans=min(ans,temp);
		}
	}
	cout<<(ans.front()!='z'+1?ans:"UNRESTORABLE"s)<<"\n"s;
}

Measured memory_bytes: 256
/*
AizuOnline A1154
Title
*/
#include <stdio.h>
// Select Below
//#include <stdlib.h>
//#include <string.h>
//#include <float.h>
//#include <math.h>
//#include <limits.h>
//Global data section
#define NOOFPRIME 7200
int NUM;
int prime_f[NOOFPRIME][2];  //getudo_prime_f[N][0] = is_getudo_prime(N*7+1)
//                                           [N][1] =                (N*7+6)
void make_furui()
{
  int n,i,j,k,l;

  for(i=0;i<5;i++)
    {
      prime_f[i][0]=prime_f[i][1]=1;
    }
  for(i=5;i<NOOFPRIME;i++)
    for(j=0;j<=1;j++)
      prime_f[i][j]=1;
  
  for(i=5;i<NOOFPRIME;i++)
    for(j=0;j<=1;j++)
      {
	n=i*7+1+j*5;
	for(k=0;k<n/32;k++)
	  for(l=0;l<2;l++)
	    if((n % (k*7+1+l*5))==0 && (k||l))
	      {
		prime_f[i][j]=0;
	      }
      }   
      
}
void ck_furui()
{
  int i,j;
  for(i=0;i<10;i++)
    for(j=0;j<=1;j++)
      if(prime_f[i][j])
	    printf(" %d",i*7+1+j*5);
  printf("\n");
}

main()
{
  int i,j,c;

  make_furui();
#ifdef DEBUG
  ck_furui();
#endif
  while(EOF!=scanf("%d",&NUM) && NUM!=1)
    {
      printf("%d:",NUM);
      c=0;
      for(i=0;i<NOOFPRIME;i++)
	for(j=0;j<=1;j++)
	  if(prime_f[i][j] && ((NUM % (i*7+1+j*5))==0)&&(i||j))
	    {
	      c++;
	      printf(" %d",i*7+1+j*5);
	    }
      if(c==0)
	printf(" %d",NUM);
      printf("\n");
    }
return(0);
}

Measured memory_bytes: 656
#include<iostream>
#include<vector>
#include<string>
#include<cmath>
#include<algorithm>
#include<numeric>
#include<map>
#include<unordered_map>
#include<queue>
#include<deque>
 
using namespace std;
using ll=long long;
#define rep(i,n)  for(ll i=0;i<n;++i)
#define all_map(itr,mp) for(auto itr=mp.begin();itr!=mp.end();itr++)
#define ALL(a) (a).begin(),(a).end()
 
int main(){
    ll a, b, k;
    cin >> a >> b >> k;

    if(a >= k)cout << a-k << " " << b;
    else cout << 0 << " " << max((ll)0, a+b-k) << endl;

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp> 
#include <ext/pb_ds/assoc_container.hpp> 
using namespace std;
using namespace __gnu_pbds;
 
typedef vector<int> vi;
typedef pair<int,int> ii;
vi v;
int n;
 
tree<ii,null_type,less<ii>,rb_tree_tag,tree_order_statistics_node_update> t;
 
int main()
{
    ios_base::sync_with_stdio(false); cin.tie(0);
    map<int,int> mp;
    while(cin >> n)
    {
        v = vi(n); t.clear(); mp.clear();
        for(int i = 0; i < n; i++)
        {
            cin >> v[i];
            t.insert({v[i], mp[v[i]]++});
        }
	mp.clear();
	for(int i = 0; i < n; i++)
	{
		t.erase({v[i], mp[v[i]]});
		cout << (*t.find_by_order((n-1)/2)).first << '\n'; 
		t.insert({v[i], mp[v[i]]++});
	}
    }
    return 0;
}

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

int main() {
    char b;
    cin >> b;

    if (b == 'A') cout << 'T' << '\n';
    if (b == 'T') cout << 'A' << '\n';
    if (b == 'C') cout << 'G' << '\n';
    if (b == 'G') cout << 'C' << '\n';
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <assert.h>
#include <fstream>
#include <iostream>
#include <algorithm>
#include <array>
#include <vector>
#include <queue>
#include <set>
#include <cmath>
#include <iomanip>
#include <unordered_map>
//#include <unordered_set>
//#include <boost/container/static_vector.hpp>
//#include <boost/unordered_set.hpp>
//#include <boost/unordered_map.hpp>
//#include <unistd.h>

const int MAX_N = 500050;
int N, Q, q[MAX_N];
long long D, d[MAX_N];

long long area[MAX_N], loc[MAX_N];

int main(int argc, char **argv) {
    std::cin >> N >> D;

    for (int i = 1; i <= N; i++) {
        std::cin >> d[i];
    }

    std::cin >> Q;

    for (int i = 1; i <= Q; i++) {
        std::cin >> q[i];
    }

    area[N+1] = 0;
    for (int i = N; 1 <= i; i--) {
        if (d[i] <= area[i+1] * 2 + 1) {
            area[i] = area[i+1] + d[i];
        } else {
            area[i] = area[i+1];
        }
        //std::cout << i << " " << area[i] << std::endl;
    }

    loc[0] = D;
    for (int i = 1; i <= N; i++) {
        loc[i] = std::min(llabs(loc[i-1] - d[i]), loc[i-1]);
        //std::cout << i << " " << loc[i] << std::endl;
    }

    for (int i = 1; i <= Q; i++) {
        if (loc[q[i]-1] > area[q[i]+1]) {
            std::cout << "YES" << std::endl;
        } else {
            std::cout << "NO" << std::endl;
        }
    }
    
    return 0;
}

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

int main() {
  int a, b;
  cin >> a >> b;
  if((a + b) % 2 == 0){
    cout << (a + b) / 2 << endl;
  }else{
    cout << (a + b) / 2 + 1 << endl;
  }
}


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

using ll = long long int;

const int MOD = 1e9 + 7;

#define MAX(a, b) ((a > b) ? a : b)
#define MIN(a, b) ((a > b) ? b : a)

template <class T>
class my_array{
  private:
    int n;
    vector<T> A;
  public:
    my_array(int k){n = k; A.resize(n);}
    ~my_array(void){};
    // input a_0, a_1, ..., a_(n-1)
    void get(void){
      for(int i = 0; i < n; i++) cin >> A.at(i);
    }
    // sort A
    void sorted(bool flag = true){
      if(flag) sort(A.begin(), A.end());
      else sort(A.begin(), A.end(), greater<T>());
    }
    // print : a_0, a_1, ... a_(n-1)
    void show(void){
      for(int i = 0; i < n - 1; i++) cout << A.at(i) << " ";
      cout << A.at(n - 1) << "\n";
    }
    int solve(int a, int b){
      if(a >= b) return 0;
      int mn_idx = 0, min = 1e9;
      for(int i = a; i < b; i++) if(min > A.at(i)){
        min = A.at(i);
        mn_idx = i;
      }
      for(int i = a; i < b; i++) A.at(i) -= min;
      return solve(a, mn_idx) + min + solve(mn_idx + 1, b);
    }
};


/* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */


int main(void){
  int n, k;
  cin >> n >> k;
  if(n >= 2 * k - 1) cout << "YES\n";
  else cout << "NO\n";
  return 0;
}

Measured memory_bytes: 256